diff --git a/wled00/FX.h b/wled00/FX.h index 14e486b1..8603328a 100644 --- a/wled00/FX.h +++ b/wled00/FX.h @@ -647,7 +647,7 @@ class WS2812FX { setTransitionMode(bool t), calcGammaTable(float), trigger(void), - setSegment(uint8_t n, uint16_t start, uint16_t stop, uint8_t grouping = 0, uint8_t spacing = 0), + setSegment(uint8_t n, uint16_t start, uint16_t stop, uint8_t grouping = 0, uint8_t spacing = 0, uint16_t offset = UINT16_MAX), resetSegments(), makeAutoSegments(), fixInvalidSegments(), diff --git a/wled00/FX_fcn.cpp b/wled00/FX_fcn.cpp index 9077cdaa..1b52772d 100644 --- a/wled00/FX_fcn.cpp +++ b/wled00/FX_fcn.cpp @@ -567,12 +567,14 @@ bool WS2812FX::hasCCTBus(void) { return false; } -void WS2812FX::setSegment(uint8_t n, uint16_t i1, uint16_t i2, uint8_t grouping, uint8_t spacing) { +void WS2812FX::setSegment(uint8_t n, uint16_t i1, uint16_t i2, uint8_t grouping, uint8_t spacing, uint16_t offset) { if (n >= MAX_NUM_SEGMENTS) return; Segment& seg = _segments[n]; //return if neither bounds nor grouping have changed - if (seg.start == i1 && seg.stop == i2 && (!grouping || (seg.grouping == grouping && seg.spacing == spacing))) return; + if (seg.start == i1 && seg.stop == i2 + && (!grouping || (seg.grouping == grouping && seg.spacing == spacing)) + && (offset == UINT16_MAX || offset == seg.offset)) return; if (seg.stop) setRange(seg.start, seg.stop -1, 0); //turn old segment range off if (i2 <= i1) //disable segment @@ -602,6 +604,7 @@ void WS2812FX::setSegment(uint8_t n, uint16_t i1, uint16_t i2, uint8_t grouping, seg.grouping = grouping; seg.spacing = spacing; } + if (offset < UINT16_MAX) seg.offset = offset; _segment_runtimes[n].reset(); } diff --git a/wled00/json.cpp b/wled00/json.cpp index f9fc7515..de55faf4 100644 --- a/wled00/json.cpp +++ b/wled00/json.cpp @@ -64,7 +64,7 @@ void deserializeSegment(JsonObject elem, byte it, byte presetId) uint16_t grp = elem["grp"] | seg.grouping; uint16_t spc = elem[F("spc")] | seg.spacing; - strip.setSegment(id, start, stop, grp, spc); + uint16_t of = seg.offset; uint16_t len = 1; if (stop > start) len = stop - start; @@ -73,9 +73,10 @@ void deserializeSegment(JsonObject elem, byte it, byte presetId) int offsetAbs = abs(offset); if (offsetAbs > len - 1) offsetAbs %= len; if (offset < 0) offsetAbs = len - offsetAbs; - seg.offset = offsetAbs; + of = offsetAbs; } - if (stop > start && seg.offset > len -1) seg.offset = len -1; + if (stop > start && of > len -1) of = len -1; + strip.setSegment(id, start, stop, grp, spc, of); byte segbri = 0; if (getVal(elem["bri"], &segbri)) {