From 4e9d95639c1d67362f6e30dfca8b8546c59352f1 Mon Sep 17 00:00:00 2001 From: AlexeyMal <75260807+AlexeyMal@users.noreply.github.com> Date: Sat, 11 Oct 2025 18:15:59 +0200 Subject: [PATCH 1/4] Random colors via JSON API in Segment object like col=["r","r","r"] #4996 --- wled00/colors.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/wled00/colors.cpp b/wled00/colors.cpp index 612b33108b..fceb62bdf6 100644 --- a/wled00/colors.cpp +++ b/wled00/colors.cpp @@ -492,6 +492,10 @@ void colorFromDecOrHexString(byte* rgb, const char* in) //contrary to the colorFromDecOrHexString() function, this uses the more standard RRGGBB / RRGGBBWW order bool colorFromHexString(byte* rgb, const char* in) { if (in == nullptr) return false; + if (in[0] == 'r') { // Random colors via JSON API in Segment object like col=["r","r","r"] · Issue #4996 + setRandomColor(rgb); + return true; + } size_t inputSize = strnlen(in, 9); if (inputSize != 6 && inputSize != 8) return false; From 3e2e3c9733f862ba2a283225b20477738bbeeeb8 Mon Sep 17 00:00:00 2001 From: AlexeyMal <75260807+AlexeyMal@users.noreply.github.com> Date: Sat, 11 Oct 2025 22:38:58 +0200 Subject: [PATCH 2/4] moved the code to json.cpp as suggested by the reviewer --- wled00/colors.cpp | 4 ---- wled00/json.cpp | 2 ++ 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/wled00/colors.cpp b/wled00/colors.cpp index fceb62bdf6..612b33108b 100644 --- a/wled00/colors.cpp +++ b/wled00/colors.cpp @@ -492,10 +492,6 @@ void colorFromDecOrHexString(byte* rgb, const char* in) //contrary to the colorFromDecOrHexString() function, this uses the more standard RRGGBB / RRGGBBWW order bool colorFromHexString(byte* rgb, const char* in) { if (in == nullptr) return false; - if (in[0] == 'r') { // Random colors via JSON API in Segment object like col=["r","r","r"] · Issue #4996 - setRandomColor(rgb); - return true; - } size_t inputSize = strnlen(in, 9); if (inputSize != 6 && inputSize != 8) return false; diff --git a/wled00/json.cpp b/wled00/json.cpp index d2b771c590..52a28220b8 100644 --- a/wled00/json.cpp +++ b/wled00/json.cpp @@ -229,6 +229,8 @@ static bool deserializeSegment(JsonObject elem, byte it, byte presetId = 0) if (kelvin == 0) seg.setColor(i, 0); if (kelvin > 0) colorKtoRGB(kelvin, brgbw); 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); } else { //HEX string, e.g. "FFAA00" colValid = colorFromHexString(brgbw, hexCol); } From a752a5ecab62b38528f39fee36231b176d088850 Mon Sep 17 00:00:00 2001 From: AlexeyMal <75260807+AlexeyMal@users.noreply.github.com> Date: Sat, 11 Oct 2025 22:44:24 +0200 Subject: [PATCH 3/4] added colValid = true; --- wled00/json.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/wled00/json.cpp b/wled00/json.cpp index 52a28220b8..64774b4461 100644 --- a/wled00/json.cpp +++ b/wled00/json.cpp @@ -231,6 +231,7 @@ static bool deserializeSegment(JsonObject elem, byte it, byte presetId = 0) 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" colValid = colorFromHexString(brgbw, hexCol); } From 44e41a65a2535e40ab9a33ac9e9e5fa6fbec49ce Mon Sep 17 00:00:00 2001 From: AlexeyMal <75260807+AlexeyMal@users.noreply.github.com> Date: Sat, 18 Oct 2025 17:50:53 +0200 Subject: [PATCH 4/4] added Docstring --- wled00/json.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wled00/json.cpp b/wled00/json.cpp index 64774b4461..40e7b4f645 100644 --- a/wled00/json.cpp +++ b/wled00/json.cpp @@ -205,7 +205,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): // "col":[int|string|object|array, int|string|object|array, int|string|object|array] // 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 {}) // array = direct channel values [r,g,b,w] (w element being optional) int rgbw[] = {0,0,0,0};