diff --git a/wled00/json.cpp b/wled00/json.cpp index 159e621d..8415b5aa 100644 --- a/wled00/json.cpp +++ b/wled00/json.cpp @@ -11,8 +11,6 @@ void deserializeSegment(JsonObject elem, byte it, byte presetId) byte id = elem["id"] | it; if (id >= strip.getMaxSegments()) return; - bool repeat = elem["rpt"] | false; - WS2812FX::Segment& seg = strip.getSegment(id); //WS2812FX::Segment prev; //prev = seg; //make a backup so we can tell if something changed @@ -24,6 +22,23 @@ void deserializeSegment(JsonObject elem, byte it, byte presetId) stop = (len > 0) ? start + len : seg.stop; } + bool repeat = elem["rpt"] | false; + if (repeat && stop>0) { + elem.remove("id"); // remove for recursive call + elem.remove("rpt"); // remove for recursive call + elem.remove("n"); // remove for recursive call + uint16_t len = stop - start; + for (byte i=1; i= strip.getLengthTotal()) break; + elem["start"] = start; + elem["stop"] = start + len; + elem["rev"] = !elem["rev"]; // alternate reverse on even/odd segments + deserializeSegment(elem, i, presetId); // recursive call with new id + } + return; + } + if (elem["n"]) { // name field exists if (seg.name) { //clear old name @@ -212,21 +227,6 @@ void deserializeSegment(JsonObject elem, byte it, byte presetId) seg.setOption(SEG_OPTION_FREEZE, false); } - if (repeat) { - elem.remove("id"); - elem.remove("rpt"); - elem.remove("n"); - len = stop - start; - for (byte i=1; i= strip.getLengthTotal()) break; - elem["start"] = start; - elem["stop"] = start + len; - elem["rev"] = !elem["rev"]; - deserializeSegment(elem, i, presetId); - } - } - return; // seg.differs(prev); }