Relative value wrapping and operator fix (fixes #2566 )

pull/995/head
cschwinne 2022-03-04 14:42:35 +01:00
rodzic 6fe43b7b5c
commit 85b1c309d1
2 zmienionych plików z 10 dodań i 4 usunięć

Wyświetl plik

@ -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];

Wyświetl plik

@ -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 {
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