Autosave enable/disable UI button
This commit is contained in:
parent
43582b6319
commit
caef289b9b
@ -91,6 +91,10 @@ class AutoSaveUsermod : public Usermod {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void enable(bool enable) {
|
||||||
|
enabled = enable;
|
||||||
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
// gets called once at boot. Do all initialization that doesn't depend on
|
// gets called once at boot. Do all initialization that doesn't depend on
|
||||||
@ -155,12 +159,24 @@ class AutoSaveUsermod : public Usermod {
|
|||||||
* Creating an "u" object allows you to add custom key/value pairs to the Info section of the WLED web UI.
|
* Creating an "u" object allows you to add custom key/value pairs to the Info section of the WLED web UI.
|
||||||
* Below it is shown how this could be used for e.g. a light sensor
|
* Below it is shown how this could be used for e.g. a light sensor
|
||||||
*/
|
*/
|
||||||
//void addToJsonInfo(JsonObject& root) {
|
void addToJsonInfo(JsonObject& root) {
|
||||||
//JsonObject user = root["u"];
|
JsonObject user = root["u"];
|
||||||
//if (user.isNull()) user = root.createNestedObject("u");
|
if (user.isNull()) {
|
||||||
//JsonArray data = user.createNestedArray(F("Autosave"));
|
user = root.createNestedObject("u");
|
||||||
//data.add(F("Loaded."));
|
}
|
||||||
//}
|
|
||||||
|
JsonArray infoArr = user.createNestedArray(FPSTR(_name)); // name
|
||||||
|
|
||||||
|
String uiDomString = F("<button class=\"btn btn-xs\" onclick=\"requestJson({");
|
||||||
|
uiDomString += FPSTR(_name);
|
||||||
|
uiDomString += F(":{");
|
||||||
|
uiDomString += FPSTR(_autoSaveEnabled);
|
||||||
|
uiDomString += enabled ? F(":false}});\">") : F(":true}});\">");
|
||||||
|
uiDomString += F("<i class=\"icons ");
|
||||||
|
uiDomString += enabled ? "on" : "off";
|
||||||
|
uiDomString += F("\"></i></button>");
|
||||||
|
infoArr.add(uiDomString);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* addToJsonState() can be used to add custom entries to the /json/state part of the JSON API (state object).
|
* addToJsonState() can be used to add custom entries to the /json/state part of the JSON API (state object).
|
||||||
@ -173,9 +189,20 @@ class AutoSaveUsermod : public Usermod {
|
|||||||
* readFromJsonState() can be used to receive data clients send to the /json/state part of the JSON API (state object).
|
* readFromJsonState() can be used to receive data clients send to the /json/state part of the JSON API (state object).
|
||||||
* Values in the state object may be modified by connected clients
|
* Values in the state object may be modified by connected clients
|
||||||
*/
|
*/
|
||||||
//void readFromJsonState(JsonObject& root) {
|
void readFromJsonState(JsonObject& root) {
|
||||||
// if (!initDone) return; // prevent crash on boot applyPreset()
|
if (!initDone) return; // prevent crash on boot applyPreset()
|
||||||
//}
|
bool en = enabled;
|
||||||
|
JsonObject um = root[FPSTR(_name)];
|
||||||
|
if (!um.isNull()) {
|
||||||
|
if (um[FPSTR(_autoSaveEnabled)].is<bool>()) {
|
||||||
|
en = um[FPSTR(_autoSaveEnabled)].as<bool>();
|
||||||
|
} else {
|
||||||
|
String str = um[FPSTR(_autoSaveEnabled)]; // checkbox -> off or on
|
||||||
|
en = (bool)(str!="off"); // off is guaranteed to be present
|
||||||
|
}
|
||||||
|
if (en != enabled) enable(en);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* addToConfig() can be used to add custom persistent settings to the cfg.json file in the "um" (usermod) object.
|
* addToConfig() can be used to add custom persistent settings to the cfg.json file in the "um" (usermod) object.
|
||||||
|
Loading…
Reference in New Issue
Block a user