Relative value wrapping and operator fix (fixes #2566 )

This commit is contained in:
cschwinne 2022-03-04 14:42:35 +01:00
parent 6fe43b7b5c
commit 85b1c309d1
2 changed files with 10 additions and 4 deletions

View File

@ -200,7 +200,7 @@ void deserializeSegment(JsonObject elem, byte it, byte presetId)
JsonArray icol = iarr[i]; JsonArray icol = iarr[i];
if (!icol.isNull()) { //array, e.g. [255,0,0] if (!icol.isNull()) { //array, e.g. [255,0,0]
byte sz = icol.size(); 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" } else { //hex string, e.g. "FF0000"
byte brgbw[] = {0,0,0,0}; byte brgbw[] = {0,0,0,0};
const char* hexCol = iarr[i]; const char* hexCol = iarr[i];

View File

@ -552,6 +552,8 @@ void parseNumber(const char* str, byte* val, byte minv, byte maxv)
{ {
if (str == nullptr || str[0] == '\0') return; if (str == nullptr || str[0] == '\0') return;
if (str[0] == 'r') {*val = random8(minv,maxv); 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] == '~') { if (str[0] == '~') {
int out = atoi(str +1); int out = atoi(str +1);
if (out == 0) 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 *val = (int)(*val +1) > (int)maxv ? minv : max((int)minv,(*val +1)); //+1, wrap around
} }
} else { } else {
if (wrap && *val == maxv && out > 0) out = minv;
else if (wrap && *val == minv && out < 0) out = maxv;
else {
out += *val; out += *val;
if (out > maxv) out = maxv; if (out > maxv) out = maxv;
if (out < minv) out = minv; if (out < minv) out = minv;
}
*val = out; *val = out;
} }
} else } else