Change on/off button for Sataicase usermod.

This commit is contained in:
Blaz Kristan 2022-06-28 12:33:00 +02:00
parent 4c60a70c6f
commit a3b0b8b3d0

View File

@ -406,6 +406,14 @@ class Animated_Staircase : public Usermod {
} }
} }
void appendConfigData() {
//oappend(SET_F("dd=addDropdown('staircase','selectfield');"));
//oappend(SET_F("addOption(dd,'1st value',0);"));
//oappend(SET_F("addOption(dd,'2nd value',1);"));
//oappend(SET_F("addInfo('staircase:selectfield',1,'additional info');")); // 0 is field type, 1 is actual field
}
/* /*
* Writes the configuration to internal flash memory. * Writes the configuration to internal flash memory.
*/ */
@ -458,15 +466,11 @@ class Animated_Staircase : public Usermod {
useUSSensorTop = top[FPSTR(_useTopUltrasoundSensor)] | useUSSensorTop; useUSSensorTop = top[FPSTR(_useTopUltrasoundSensor)] | useUSSensorTop;
topPIRorTriggerPin = top[FPSTR(_topPIRorTrigger_pin)] | topPIRorTriggerPin; topPIRorTriggerPin = top[FPSTR(_topPIRorTrigger_pin)] | topPIRorTriggerPin;
// topPIRorTriggerPin = min(33,max(-1,(int)topPIRorTriggerPin)); // bounds check
topEchoPin = top[FPSTR(_topEcho_pin)] | topEchoPin; topEchoPin = top[FPSTR(_topEcho_pin)] | topEchoPin;
// topEchoPin = min(39,max(-1,(int)topEchoPin)); // bounds check
useUSSensorBottom = top[FPSTR(_useBottomUltrasoundSensor)] | useUSSensorBottom; useUSSensorBottom = top[FPSTR(_useBottomUltrasoundSensor)] | useUSSensorBottom;
bottomPIRorTriggerPin = top[FPSTR(_bottomPIRorTrigger_pin)] | bottomPIRorTriggerPin; bottomPIRorTriggerPin = top[FPSTR(_bottomPIRorTrigger_pin)] | bottomPIRorTriggerPin;
// bottomPIRorTriggerPin = min(33,max(-1,(int)bottomPIRorTriggerPin)); // bounds check
bottomEchoPin = top[FPSTR(_bottomEcho_pin)] | bottomEchoPin; bottomEchoPin = top[FPSTR(_bottomEcho_pin)] | bottomEchoPin;
// bottomEchoPin = min(39,max(-1,(int)bottomEchoPin)); // bounds check
topMaxDist = top[FPSTR(_topEchoCm)] | topMaxDist; topMaxDist = top[FPSTR(_topEchoCm)] | topMaxDist;
topMaxDist = min(150,max(30,(int)topMaxDist)); // max distnace ~1.5m (a lag of 9ms may be expected) topMaxDist = min(150,max(30,(int)topMaxDist)); // max distnace ~1.5m (a lag of 9ms may be expected)
@ -504,22 +508,22 @@ class Animated_Staircase : public Usermod {
* tab of the web-UI. * tab of the web-UI.
*/ */
void addToJsonInfo(JsonObject& root) { void addToJsonInfo(JsonObject& root) {
JsonObject staircase = root["u"]; JsonObject user = root["u"];
if (staircase.isNull()) { if (user.isNull()) {
staircase = root.createNestedObject("u"); user = root.createNestedObject("u");
} }
JsonArray usermodEnabled = staircase.createNestedArray(F("Staircase")); // name JsonArray infoArr = user.createNestedArray(FPSTR(_name)); // name
String btn = F("<button class=\"btn infobtn\" onclick=\"requestJson({staircase:{enabled:");
if (enabled) { String uiDomString = F("<button class=\"btn btn-xs\" onclick=\"requestJson({");
btn += F("false}});\">"); uiDomString += FPSTR(_name);
btn += F("enabled"); uiDomString += F(":{");
} else { uiDomString += FPSTR(_enabled);
btn += F("true}});\">"); uiDomString += enabled ? F(":false}});\">") : F(":true}});\">");
btn += F("disabled"); uiDomString += F("<i class=\"icons ");
} uiDomString += enabled ? "on" : "off";
btn += F("</button>"); uiDomString += F("\">&#xe08f;</i></button>");
usermodEnabled.add(btn); // value infoArr.add(uiDomString);
} }
}; };