Random colors via JSON API in Segment object like "col":["r","r","r"] #4996 (#5000)

Add support for random colors via JSON API in Segment object like col=["r","r","r"] #4996
This commit is contained in:
AlexeyMal
2026-01-07 04:47:04 +01:00
committed by GitHub
parent 8433fd24c3
commit 254e0099ca

View File

@@ -209,7 +209,7 @@ static bool deserializeSegment(JsonObject elem, byte it, byte presetId = 0)
// JSON "col" array can contain the following values for each of segment's colors (primary, background, custom): // JSON "col" array can contain the following values for each of segment's colors (primary, background, custom):
// "col":[int|string|object|array, int|string|object|array, int|string|object|array] // "col":[int|string|object|array, int|string|object|array, int|string|object|array]
// int = Kelvin temperature or 0 for black // int = Kelvin temperature or 0 for black
// string = hex representation of [WW]RRGGBB // string = hex representation of [WW]RRGGBB or "r" for random color
// object = individual channel control {"r":0,"g":127,"b":255,"w":255}, each being optional (valid to send {}) // object = individual channel control {"r":0,"g":127,"b":255,"w":255}, each being optional (valid to send {})
// array = direct channel values [r,g,b,w] (w element being optional) // array = direct channel values [r,g,b,w] (w element being optional)
int rgbw[] = {0,0,0,0}; int rgbw[] = {0,0,0,0};
@@ -233,6 +233,9 @@ static bool deserializeSegment(JsonObject elem, byte it, byte presetId = 0)
if (kelvin == 0) seg.setColor(i, 0); if (kelvin == 0) seg.setColor(i, 0);
if (kelvin > 0) colorKtoRGB(kelvin, brgbw); if (kelvin > 0) colorKtoRGB(kelvin, brgbw);
colValid = true; colValid = true;
} else if (hexCol[0] == 'r' && hexCol[1] == '\0') { // Random colors via JSON API in Segment object like col=["r","r","r"] · Issue #4996
setRandomColor(brgbw);
colValid = true;
} else { //HEX string, e.g. "FFAA00" } else { //HEX string, e.g. "FFAA00"
colValid = colorFromHexString(brgbw, hexCol); colValid = colorFromHexString(brgbw, hexCol);
} }