diff --git a/wled00/json.cpp b/wled00/json.cpp index 85da62aed..debe3efc3 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;