Relative value wrapping and operator fix (fixes #2566 )
This commit is contained in:
parent
6fe43b7b5c
commit
85b1c309d1
@ -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];
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user