From 1539e703e997ea22b478627641af967d0cb83e1a Mon Sep 17 00:00:00 2001 From: cschwinne Date: Sat, 19 Jun 2021 11:13:05 +0200 Subject: [PATCH] Use sprintf_P for color array generation --- wled00/json.cpp | 34 +++++++++++----------------------- 1 file changed, 11 insertions(+), 23 deletions(-) diff --git a/wled00/json.cpp b/wled00/json.cpp index 85da62ae..debe3efc 100644 --- a/wled00/json.cpp +++ b/wled00/json.cpp @@ -328,39 +328,27 @@ void serializeSegment(JsonObject& root, WS2812FX::Segment& seg, byte id, bool fo byte segbri = seg.opacity; root["bri"] = (segbri) ? segbri : 255; - JsonArray colarr = root.createNestedArray("col"); - - char colstr[70]; //max len 68 (5 chan, all 255) - obuf = colstr; olen = 0; - oappend("["); + char colstr[70]; colstr[0] = '['; colstr[1] = '\0'; //max len 68 (5 chan, all 255) for (uint8_t i = 0; i < 3; i++) { - oappend("["); + byte segcol[4]; byte* c = segcol; if (id == strip.getMainSegmentId() && i < 2) //temporary, to make transition work on main segment { - byte* c = (i == 0)? col:colSec; - - oappendi(c[0]); oappend(","); - oappendi(c[1]); oappend(","); - oappendi(c[2]); - if (strip.isRgbw) { - oappend(","); oappendi(c[3]); - } + c = (i == 0)? col:colSec; } else { - oappendi((seg.colors[i] >> 16) & 0xFF); oappend(","); - oappendi((seg.colors[i] >> 8) & 0xFF); oappend(","); - oappendi((seg.colors[i]) & 0xFF); - if (strip.isRgbw) { - oappend(","); oappendi((seg.colors[i] >> 24) & 0xFF); - } + segcol[0] = (byte)(seg.colors[i] >> 16); segcol[1] = (byte)(seg.colors[i] >> 8); + segcol[2] = (byte)(seg.colors[i]); segcol[3] = (byte)(seg.colors[i] >> 24); } - oappend("]"); - if (i < 2) oappend(","); + char tmpcol[22]; + if (strip.isRgbw) sprintf_P(tmpcol, PSTR("[%u,%u,%u,%u]"), c[0], c[1], c[2], c[3]); + else sprintf_P(tmpcol, PSTR("[%u,%u,%u]"), c[0], c[1], c[2]); + + strcat(colstr, i<2 ? strcat(tmpcol,",") : tmpcol); } - oappend("]"); + strcat(colstr,"]"); root["col"] = serialized(colstr); root[F("fx")] = seg.mode;