Implement global JSON API boolean toggle.
This commit is contained in:
parent
e1075a3bbf
commit
2b616b688d
@ -341,6 +341,7 @@ void userLoop();
|
|||||||
int getNumVal(const String* req, uint16_t pos);
|
int getNumVal(const String* req, uint16_t pos);
|
||||||
void parseNumber(const char* str, byte* val, byte minv=0, byte maxv=255);
|
void parseNumber(const char* str, byte* val, byte minv=0, byte maxv=255);
|
||||||
bool getVal(JsonVariant elem, byte* val, byte minv=0, byte maxv=255);
|
bool getVal(JsonVariant elem, byte* val, byte minv=0, byte maxv=255);
|
||||||
|
bool getBoolVal(JsonVariant elem, bool dflt);
|
||||||
bool updateVal(const char* req, const char* key, byte* val, byte minv=0, byte maxv=255);
|
bool updateVal(const char* req, const char* key, byte* val, byte minv=0, byte maxv=255);
|
||||||
bool oappend(const char* txt); // append new c string to temp buffer efficiently
|
bool oappend(const char* txt); // append new c string to temp buffer efficiently
|
||||||
bool oappendi(int i); // append new number to temp buffer efficiently
|
bool oappendi(int i); // append new number to temp buffer efficiently
|
||||||
|
@ -133,12 +133,8 @@ bool deserializeSegment(JsonObject elem, byte it, byte presetId)
|
|||||||
seg.setOption(SEG_OPTION_ON, segbri); // use transition
|
seg.setOption(SEG_OPTION_ON, segbri); // use transition
|
||||||
}
|
}
|
||||||
|
|
||||||
bool on = elem["on"] | seg.on;
|
seg.setOption(SEG_OPTION_ON, getBoolVal(elem["on"], seg.on)); // use transition
|
||||||
if (elem["on"].is<const char*>() && elem["on"].as<const char*>()[0] == 't') on = !on;
|
seg.freeze = getBoolVal(elem["frz"], seg.freeze);
|
||||||
seg.setOption(SEG_OPTION_ON, on); // use transition
|
|
||||||
bool frz = elem["frz"] | seg.freeze;
|
|
||||||
if (elem["frz"].is<const char*>() && elem["frz"].as<const char*>()[0] == 't') frz = !seg.freeze;
|
|
||||||
seg.freeze = frz;
|
|
||||||
|
|
||||||
seg.setCCT(elem["cct"] | seg.cct);
|
seg.setCCT(elem["cct"] | seg.cct);
|
||||||
|
|
||||||
@ -201,15 +197,15 @@ bool deserializeSegment(JsonObject elem, byte it, byte presetId)
|
|||||||
bool reverse = seg.reverse;
|
bool reverse = seg.reverse;
|
||||||
bool mirror = seg.mirror;
|
bool mirror = seg.mirror;
|
||||||
#endif
|
#endif
|
||||||
seg.selected = elem["sel"] | seg.selected;
|
seg.selected = getBoolVal(elem["sel"], seg.selected);
|
||||||
seg.reverse = elem["rev"] | seg.reverse;
|
seg.reverse = getBoolVal(elem["rev"], seg.reverse);
|
||||||
seg.mirror = elem["mi"] | seg.mirror;
|
seg.mirror = getBoolVal(elem["mi"] , seg.mirror);
|
||||||
#ifndef WLED_DISABLE_2D
|
#ifndef WLED_DISABLE_2D
|
||||||
bool reverse_y = seg.reverse_y;
|
bool reverse_y = seg.reverse_y;
|
||||||
bool mirror_y = seg.mirror_y;
|
bool mirror_y = seg.mirror_y;
|
||||||
seg.reverse_y = elem["rY"] | seg.reverse_y;
|
seg.reverse_y = getBoolVal(elem["rY"] , seg.reverse_y);
|
||||||
seg.mirror_y = elem["mY"] | seg.mirror_y;
|
seg.mirror_y = getBoolVal(elem["mY"] , seg.mirror_y);
|
||||||
seg.transpose = elem[F("tp")] | seg.transpose;
|
seg.transpose = getBoolVal(elem[F("tp")], seg.transpose);
|
||||||
if (seg.is2D() && seg.map1D2D == M12_pArc && (reverse != seg.reverse || reverse_y != seg.reverse_y || mirror != seg.mirror || mirror_y != seg.mirror_y)) seg.fill(BLACK); // clear entire segment (in case of Arc 1D to 2D expansion)
|
if (seg.is2D() && seg.map1D2D == M12_pArc && (reverse != seg.reverse || reverse_y != seg.reverse_y || mirror != seg.mirror || mirror_y != seg.mirror_y)) seg.fill(BLACK); // clear entire segment (in case of Arc 1D to 2D expansion)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -234,9 +230,9 @@ bool deserializeSegment(JsonObject elem, byte it, byte presetId)
|
|||||||
getVal(elem["c3"], &cust3); // we can't pass reference to bifield
|
getVal(elem["c3"], &cust3); // we can't pass reference to bifield
|
||||||
seg.custom3 = constrain(cust3, 0, 31);
|
seg.custom3 = constrain(cust3, 0, 31);
|
||||||
|
|
||||||
seg.check1 = elem["o1"] | seg.check1;
|
seg.check1 = getBoolVal(elem["o1"], seg.check1);
|
||||||
seg.check2 = elem["o2"] | seg.check2;
|
seg.check2 = getBoolVal(elem["o2"], seg.check2);
|
||||||
seg.check3 = elem["o3"] | seg.check3;
|
seg.check3 = getBoolVal(elem["o3"], seg.check3);
|
||||||
|
|
||||||
JsonArray iarr = elem[F("i")]; //set individual LEDs
|
JsonArray iarr = elem[F("i")]; //set individual LEDs
|
||||||
if (!iarr.isNull()) {
|
if (!iarr.isNull()) {
|
||||||
@ -349,13 +345,13 @@ bool deserializeState(JsonObject root, byte callMode, byte presetId)
|
|||||||
if (tr >= 0) strip.timebase = ((uint32_t)tr) - millis();
|
if (tr >= 0) strip.timebase = ((uint32_t)tr) - millis();
|
||||||
|
|
||||||
JsonObject nl = root["nl"];
|
JsonObject nl = root["nl"];
|
||||||
nightlightActive = nl["on"] | nightlightActive;
|
nightlightActive = getBoolVal(nl["on"], nightlightActive);
|
||||||
nightlightDelayMins = nl["dur"] | nightlightDelayMins;
|
nightlightDelayMins = nl["dur"] | nightlightDelayMins;
|
||||||
nightlightMode = nl["mode"] | nightlightMode;
|
nightlightMode = nl["mode"] | nightlightMode;
|
||||||
nightlightTargetBri = nl[F("tbri")] | nightlightTargetBri;
|
nightlightTargetBri = nl[F("tbri")] | nightlightTargetBri;
|
||||||
|
|
||||||
JsonObject udpn = root["udpn"];
|
JsonObject udpn = root["udpn"];
|
||||||
sendNotificationsRT = udpn["send"] | sendNotificationsRT;
|
sendNotificationsRT = getBoolVal(udpn["send"], sendNotificationsRT);
|
||||||
syncGroups = udpn["sgrp"] | syncGroups;
|
syncGroups = udpn["sgrp"] | syncGroups;
|
||||||
receiveGroups = udpn["rgrp"] | receiveGroups;
|
receiveGroups = udpn["rgrp"] | receiveGroups;
|
||||||
if ((bool)udpn[F("nn")]) callMode = CALL_MODE_NO_NOTIFY; //send no notification just for this request
|
if ((bool)udpn[F("nn")]) callMode = CALL_MODE_NO_NOTIFY; //send no notification just for this request
|
||||||
|
@ -69,6 +69,15 @@ bool getVal(JsonVariant elem, byte* val, byte vmin, byte vmax) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool getBoolVal(JsonVariant elem, bool dflt) {
|
||||||
|
if (elem.is<const char*>() && elem.as<const char*>()[0] == 't') {
|
||||||
|
return !dflt;
|
||||||
|
} else {
|
||||||
|
return elem | dflt;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool updateVal(const char* req, const char* key, byte* val, byte minv, byte maxv)
|
bool updateVal(const char* req, const char* key, byte* val, byte minv, byte maxv)
|
||||||
{
|
{
|
||||||
const char *v = strstr(req, key);
|
const char *v = strstr(req, key);
|
||||||
|
Loading…
Reference in New Issue
Block a user