Skip to content

Commit

Permalink
add json overrides to save/restore fade options
Browse files Browse the repository at this point in the history
  • Loading branch information
alefnull committed Aug 25, 2022
1 parent 10d0565 commit 19fc42a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/switch18.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,22 @@ struct Switch18 : Module, SwitchBase {
lights[STEP_1_LIGHT + i].setBrightness(i == current_step ? 1.f : 0.f);
}
}

json_t* dataToJson() override {
json_t* rootJ = json_object();
json_object_set_new(rootJ, "fade_while_switching", json_boolean(fade_while_switching));
json_object_set_new(rootJ, "fade_speed", json_real(fade_speed));
return rootJ;
}

void dataFromJson(json_t* rootJ) override {
json_t* fadeJ = json_object_get(rootJ, "fade_while_switching");
if (fadeJ)
fade_while_switching = json_boolean_value(fadeJ);
json_t* fade_speedJ = json_object_get(rootJ, "fade_speed");
if (fade_speedJ)
fade_speed = json_real_value(fade_speedJ);
}
};


Expand Down
16 changes: 16 additions & 0 deletions src/switch81.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,22 @@ struct Switch81 : Module, SwitchBase {
lights[STEP_1_LIGHT + i].setBrightness(i == current_step ? 1.f : 0.f);
}
}

json_t* dataToJson() override {
json_t* rootJ = json_object();
json_object_set_new(rootJ, "fade_while_switching", json_boolean(fade_while_switching));
json_object_set_new(rootJ, "fade_speed", json_real(fade_speed));
return rootJ;
}

void dataFromJson(json_t* rootJ) override {
json_t* fadeJ = json_object_get(rootJ, "fade_while_switching");
if (fadeJ)
fade_while_switching = json_boolean_value(fadeJ);
json_t* fade_speedJ = json_object_get(rootJ, "fade_speed");
if (fade_speedJ)
fade_speed = json_real_value(fade_speedJ);
}
};


Expand Down

0 comments on commit 19fc42a

Please sign in to comment.