You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: usermods/EXAMPLE_v2/usermod_v2_example.h
+27-17Lines changed: 27 additions & 17 deletions
Original file line number
Diff line number
Diff line change
@@ -20,15 +20,32 @@
20
20
* 2. Register the usermod by adding #include "usermod_filename.h" in the top and registerUsermod(new MyUsermodClass()) in the bottom of usermods_list.cpp
21
21
*/
22
22
23
+
/* WLEDMM: move usermod variables to class.
24
+
25
+
As of March 2023 this is work in progress, more variables will be moved in the future.
26
+
See Example v2, Temperature, MPU6050 and weather and fastled (rest to be done) as examples which has been converted using the steps below:
// in such case add the following to another usermod:
68
82
// in private vars:
@@ -222,8 +236,8 @@ class MyExampleUsermod : public Usermod {
222
236
*/
223
237
voidaddToConfig(JsonObject& root)
224
238
{
225
-
JsonObject top = root.createNestedObject(FPSTR(_name));
226
-
top[FPSTR(_enabled)] = enabled;
239
+
Usermod::addToConfig(root); JsonObject top = root[FPSTR(_name)]; //WLEDMM
240
+
227
241
//save these vars persistently whenever settings are saved
228
242
top["great"] = userVar0;
229
243
top["testBool"] = testBool;
@@ -258,9 +272,7 @@ class MyExampleUsermod : public Usermod {
258
272
// default settings values could be set here (or below using the 3-argument getJsonValue()) instead of in the class definition or constructor
259
273
// setting them inside readFromConfig() is slightly more robust, handling the rare but plausible use case of single value being missing after boot (e.g. if the cfg.json was manually edited and a value was removed)
260
274
261
-
JsonObject top = root[FPSTR(_name)];
262
-
263
-
bool configComplete = !top.isNull();
275
+
bool configComplete = Usermod::readFromConfig(root);JsonObject top = root[FPSTR(_name)]; //WLEDMM
0 commit comments