From 80a657965e0726f3ec48b1dc47a8dba0876ed413 Mon Sep 17 00:00:00 2001 From: cschwinne Date: Mon, 22 Nov 2021 21:41:04 +0100 Subject: [PATCH] Fixed preset cycle not working from preset called by UI --- CHANGELOG.md | 5 +++++ wled00/json.cpp | 6 ++++-- wled00/set.cpp | 10 ++++------ wled00/wled.h | 4 +++- 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ff04e1de..ba305fbb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,11 @@ ### Builds after release 0.12.0 +#### Build 2111220 + +- Fixed preset cycle not working from preset called by UI +- Reintroduced permanent min. and max. cycle bounds + #### Build 2111190 - Changed default ESP32 LED pin from 16 to 2 diff --git a/wled00/json.cpp b/wled00/json.cpp index 4ac81fe7..de40f561 100644 --- a/wled00/json.cpp +++ b/wled00/json.cpp @@ -339,9 +339,11 @@ bool deserializeState(JsonObject root, byte callMode, byte presetId) deletePreset(ps); } - if (getVal(root["ps"], &presetCycCurr, 1, 5)) { //load preset (clears state request!) + ps = presetCycCurr; + if (getVal(root["ps"], &ps, presetCycMin, presetCycMax)) { //load preset (clears state request!) if (!presetId) unloadPlaylist(); //stop playlist if preset changed manually - applyPreset(presetCycCurr, callMode); + if (ps >= presetCycMin && ps <= presetCycMax) presetCycCurr = ps; + applyPreset(ps, callMode); return stateResponse; } diff --git a/wled00/set.cpp b/wled00/set.cpp index cfd737b9..eda22508 100644 --- a/wled00/set.cpp +++ b/wled00/set.cpp @@ -547,6 +547,7 @@ void parseNumber(const char* str, byte* val, byte minv, byte maxv) const char* str2 = strchr(str,'~'); //min/max range (for preset cycle, e.g. "1~5~") if (str2) { byte p2 = atoi(str2+1); + presetCycMin = p1; presetCycMax = p2; while (isdigit((str2+1)[0])) str2++; parseNumber(str2+1, val, p1, p2); } else { @@ -655,17 +656,14 @@ bool handleSet(AsyncWebServerRequest *request, const String& req, bool apply) pos = req.indexOf(F("PS=")); //saves current in preset if (pos > 0) savePreset(getNumVal(&req, pos)); - byte presetCycleMin = 1; - byte presetCycleMax = 5; - pos = req.indexOf(F("P1=")); //sets first preset for cycle - if (pos > 0) presetCycleMin = getNumVal(&req, pos); + if (pos > 0) presetCycMin = getNumVal(&req, pos); pos = req.indexOf(F("P2=")); //sets last preset for cycle - if (pos > 0) presetCycleMax = getNumVal(&req, pos); + if (pos > 0) presetCycMax = getNumVal(&req, pos); //apply preset - if (updateVal(&req, "PL=", &presetCycCurr, presetCycleMin, presetCycleMax)) { + if (updateVal(&req, "PL=", &presetCycCurr, presetCycMin, presetCycMax)) { applyPreset(presetCycCurr); } diff --git a/wled00/wled.h b/wled00/wled.h index 0c53f56c..54d9743e 100644 --- a/wled00/wled.h +++ b/wled00/wled.h @@ -8,7 +8,7 @@ */ // version code in format yymmddb (b = daily build) -#define VERSION 2111190 +#define VERSION 2111220 //uncomment this if you have a "my_config.h" file you'd like to use //#define WLED_USE_MY_CONFIG @@ -515,6 +515,8 @@ WLED_GLOBAL unsigned long presetCycledTime _INIT(0); WLED_GLOBAL int16_t currentPlaylist _INIT(-1); //still used for "PL=~" HTTP API command WLED_GLOBAL byte presetCycCurr _INIT(0); +WLED_GLOBAL byte presetCycMin _INIT(1); +WLED_GLOBAL byte presetCycMax _INIT(5); // realtime WLED_GLOBAL byte realtimeMode _INIT(REALTIME_MODE_INACTIVE);