Skip to content

Commit 19fc42a

Browse files
committed
add json overrides to save/restore fade options
1 parent 10d0565 commit 19fc42a

2 files changed

Lines changed: 32 additions & 0 deletions

File tree

src/switch18.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,22 @@ struct Switch18 : Module, SwitchBase {
160160
lights[STEP_1_LIGHT + i].setBrightness(i == current_step ? 1.f : 0.f);
161161
}
162162
}
163+
164+
json_t* dataToJson() override {
165+
json_t* rootJ = json_object();
166+
json_object_set_new(rootJ, "fade_while_switching", json_boolean(fade_while_switching));
167+
json_object_set_new(rootJ, "fade_speed", json_real(fade_speed));
168+
return rootJ;
169+
}
170+
171+
void dataFromJson(json_t* rootJ) override {
172+
json_t* fadeJ = json_object_get(rootJ, "fade_while_switching");
173+
if (fadeJ)
174+
fade_while_switching = json_boolean_value(fadeJ);
175+
json_t* fade_speedJ = json_object_get(rootJ, "fade_speed");
176+
if (fade_speedJ)
177+
fade_speed = json_real_value(fade_speedJ);
178+
}
163179
};
164180

165181

src/switch81.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,22 @@ struct Switch81 : Module, SwitchBase {
165165
lights[STEP_1_LIGHT + i].setBrightness(i == current_step ? 1.f : 0.f);
166166
}
167167
}
168+
169+
json_t* dataToJson() override {
170+
json_t* rootJ = json_object();
171+
json_object_set_new(rootJ, "fade_while_switching", json_boolean(fade_while_switching));
172+
json_object_set_new(rootJ, "fade_speed", json_real(fade_speed));
173+
return rootJ;
174+
}
175+
176+
void dataFromJson(json_t* rootJ) override {
177+
json_t* fadeJ = json_object_get(rootJ, "fade_while_switching");
178+
if (fadeJ)
179+
fade_while_switching = json_boolean_value(fadeJ);
180+
json_t* fade_speedJ = json_object_get(rootJ, "fade_speed");
181+
if (fade_speedJ)
182+
fade_speed = json_real_value(fade_speedJ);
183+
}
168184
};
169185

170186

0 commit comments

Comments
 (0)