Proper fix for {"on":"t","bri":100}

This commit is contained in:
Blaz Kristan 2022-08-08 15:56:15 +02:00
parent 9e828eccf6
commit 4db4329ce3
2 changed files with 14 additions and 5 deletions

View File

@ -7259,7 +7259,7 @@ static const char _data_RESERVED[] PROGMEM = "Reserved";
// if vector size() is smaller than id (single) data is appended at the end (regardless of id) // if vector size() is smaller than id (single) data is appended at the end (regardless of id)
void WS2812FX::addEffect(uint8_t id, mode_ptr mode_fn, const char *mode_name) { void WS2812FX::addEffect(uint8_t id, mode_ptr mode_fn, const char *mode_name) {
if (id == 255) { // find empty slot if (id == 255) { // find empty slot
for (int i=1; i<_mode.size(); i++) if (_modeData[i] == _data_RESERVED) { id = i; break; } for (size_t i=1; i<_mode.size(); i++) if (_modeData[i] == _data_RESERVED) { id = i; break; }
} }
if (id < _mode.size()) { if (id < _mode.size()) {
if (_modeData[id] != _data_RESERVED) return; // do not overwrite alerady added effect if (_modeData[id] != _data_RESERVED) return; // do not overwrite alerady added effect
@ -7277,7 +7277,7 @@ void WS2812FX::setupEffectData() {
_mode.push_back(&mode_static); _mode.push_back(&mode_static);
_modeData.push_back(_data_FX_MODE_STATIC); _modeData.push_back(_data_FX_MODE_STATIC);
// fill reserved word in case there will be any gaps in the array // fill reserved word in case there will be any gaps in the array
for (int i=1; i<_modeCount; i++) { for (size_t i=1; i<_modeCount; i++) {
_mode.push_back(&mode_static); _mode.push_back(&mode_static);
_modeData.push_back(_data_RESERVED); _modeData.push_back(_data_RESERVED);
} }

View File

@ -316,13 +316,22 @@ bool deserializeState(JsonObject root, byte callMode, byte presetId)
bool stateResponse = root[F("v")] | false; bool stateResponse = root[F("v")] | false;
bool onBefore = bri; bool onBefore = bri;
getVal(root["bri"], &bri); uint8_t tmpBri = bri;
getVal(root["bri"], &tmpBri);
if (root["on"].isNull()) { if (root["on"].isNull()) {
if ((onBefore && bri==0) || (!onBefore && bri>0)) toggleOnOff(); if ((onBefore && tmpBri==0) || (!onBefore && tmpBri>0)) toggleOnOff();
bri = tmpBri;
} else { } else {
bool on = root["on"] | onBefore; bool on = root["on"] | onBefore;
if (on != onBefore || (root["on"].is<const char*>() && root["on"].as<const char*>()[0] == 't')) toggleOnOff(); if (on != onBefore || (root["on"].is<const char*>() && root["on"].as<const char*>()[0] == 't')) {
toggleOnOff();
// a hack is needed after toggleOnOf()
if (!root["bri"].isNull()) {
if (bri==0) briLast = tmpBri;
else bri = tmpBri;
}
}
} }
if (bri && !onBefore) { // unfreeze all segments when turning on if (bri && !onBefore) { // unfreeze all segments when turning on