Use sprintf_P for color array generation

This commit is contained in:
cschwinne 2021-06-19 11:13:05 +02:00
parent f43bf03768
commit 1539e703e9

View File

@ -328,39 +328,27 @@ void serializeSegment(JsonObject& root, WS2812FX::Segment& seg, byte id, bool fo
byte segbri = seg.opacity; byte segbri = seg.opacity;
root["bri"] = (segbri) ? segbri : 255; root["bri"] = (segbri) ? segbri : 255;
JsonArray colarr = root.createNestedArray("col"); char colstr[70]; colstr[0] = '['; colstr[1] = '\0'; //max len 68 (5 chan, all 255)
char colstr[70]; //max len 68 (5 chan, all 255)
obuf = colstr; olen = 0;
oappend("[");
for (uint8_t i = 0; i < 3; i++) 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 if (id == strip.getMainSegmentId() && i < 2) //temporary, to make transition work on main segment
{ {
byte* c = (i == 0)? col:colSec; c = (i == 0)? col:colSec;
oappendi(c[0]); oappend(",");
oappendi(c[1]); oappend(",");
oappendi(c[2]);
if (strip.isRgbw) {
oappend(","); oappendi(c[3]);
}
} else { } else {
oappendi((seg.colors[i] >> 16) & 0xFF); oappend(","); segcol[0] = (byte)(seg.colors[i] >> 16); segcol[1] = (byte)(seg.colors[i] >> 8);
oappendi((seg.colors[i] >> 8) & 0xFF); oappend(","); segcol[2] = (byte)(seg.colors[i]); segcol[3] = (byte)(seg.colors[i] >> 24);
oappendi((seg.colors[i]) & 0xFF);
if (strip.isRgbw) {
oappend(","); oappendi((seg.colors[i] >> 24) & 0xFF);
}
} }
oappend("]"); char tmpcol[22];
if (i < 2) oappend(","); 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["col"] = serialized(colstr);
root[F("fx")] = seg.mode; root[F("fx")] = seg.mode;