Skip to content

Commit 254e009

Browse files
authored
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
1 parent 8433fd2 commit 254e009

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

wled00/json.cpp

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

0 commit comments

Comments
 (0)