From 85b1c309d1b4970fec798b772d8e986b110eb6e5 Mon Sep 17 00:00:00 2001 From: cschwinne Date: Fri, 4 Mar 2022 14:42:35 +0100 Subject: [PATCH] Relative value wrapping and operator fix (fixes #2566 ) --- wled00/json.cpp | 2 +- wled00/set.cpp | 12 +++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/wled00/json.cpp b/wled00/json.cpp index f81c35314..b7d2167fc 100644 --- a/wled00/json.cpp +++ b/wled00/json.cpp @@ -200,7 +200,7 @@ void deserializeSegment(JsonObject elem, byte it, byte presetId) JsonArray icol = iarr[i]; if (!icol.isNull()) { //array, e.g. [255,0,0] byte sz = icol.size(); - if (sz > 0 || sz < 5) copyArray(icol, rgbw); + if (sz > 0 && sz < 5) copyArray(icol, rgbw); } else { //hex string, e.g. "FF0000" byte brgbw[] = {0,0,0,0}; const char* hexCol = iarr[i]; diff --git a/wled00/set.cpp b/wled00/set.cpp index 28f9f40d3..89e5efc9b 100644 --- a/wled00/set.cpp +++ b/wled00/set.cpp @@ -552,6 +552,8 @@ void parseNumber(const char* str, byte* val, byte minv, byte maxv) { if (str == nullptr || str[0] == '\0') return; if (str[0] == 'r') {*val = random8(minv,maxv); return;} + bool wrap = false; + if (str[0] == 'w' && strlen(str) > 1) {str++; wrap = true;} if (str[0] == '~') { int out = atoi(str +1); if (out == 0) @@ -564,9 +566,13 @@ void parseNumber(const char* str, byte* val, byte minv, byte maxv) *val = (int)(*val +1) > (int)maxv ? minv : max((int)minv,(*val +1)); //+1, wrap around } } else { - out += *val; - if (out > maxv) out = maxv; - if (out < minv) out = minv; + if (wrap && *val == maxv && out > 0) out = minv; + else if (wrap && *val == minv && out < 0) out = maxv; + else { + out += *val; + if (out > maxv) out = maxv; + if (out < minv) out = minv; + } *val = out; } } else