From b890b5f0dc63a2d225b039d91695adda55bd60b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bla=C5=BE=20Kristan?= Date: Mon, 20 Dec 2021 11:29:03 +0100 Subject: [PATCH] millis() rollover fix for effects --- wled00/FX.h | 1 + wled00/FX_fcn.cpp | 6 ++++++ wled00/json.cpp | 4 ++-- wled00/wled.cpp | 1 + 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/wled00/FX.h b/wled00/FX.h index 4e2a7f6c..03429309 100644 --- a/wled00/FX.h +++ b/wled00/FX.h @@ -648,6 +648,7 @@ class WS2812FX { calcGammaTable(float), trigger(void), setSegment(uint8_t n, uint16_t start, uint16_t stop, uint8_t grouping = 0, uint8_t spacing = 0, uint16_t offset = UINT16_MAX), + restartRuntime(), resetSegments(), makeAutoSegments(), fixInvalidSegments(), diff --git a/wled00/FX_fcn.cpp b/wled00/FX_fcn.cpp index b5416d52..60fcfddc 100644 --- a/wled00/FX_fcn.cpp +++ b/wled00/FX_fcn.cpp @@ -606,6 +606,12 @@ void WS2812FX::setSegment(uint8_t n, uint16_t i1, uint16_t i2, uint8_t grouping, _segment_runtimes[n].reset(); } +void WS2812FX::restartRuntime() { + for (uint8_t i = 0; i < MAX_NUM_SEGMENTS; i++) { + _segment_runtimes[i].reset(); + } +} + void WS2812FX::resetSegments() { for (uint8_t i = 0; i < MAX_NUM_SEGMENTS; i++) if (_segments[i].name) delete _segments[i].name; mainSegment = 0; diff --git a/wled00/json.cpp b/wled00/json.cpp index 30506c16..746d6a22 100644 --- a/wled00/json.cpp +++ b/wled00/json.cpp @@ -320,7 +320,7 @@ bool deserializeState(JsonObject root, byte callMode, byte presetId) byte lowestActive = 99; for (byte s = 0; s < strip.getMaxSegments(); s++) { - WS2812FX::Segment sg = strip.getSegment(s); + WS2812FX::Segment &sg = strip.getSegment(s); if (sg.isActive()) { if (lowestActive == 99) lowestActive = s; @@ -486,7 +486,7 @@ void serializeState(JsonObject root, bool forPreset, bool includeBri, bool segme JsonArray seg = root.createNestedArray("seg"); for (byte s = 0; s < strip.getMaxSegments(); s++) { - WS2812FX::Segment sg = strip.getSegment(s); + WS2812FX::Segment &sg = strip.getSegment(s); if (sg.isActive()) { JsonObject seg0 = seg.createNestedObject(); diff --git a/wled00/wled.cpp b/wled00/wled.cpp index 2a80ccce..dd080d24 100644 --- a/wled00/wled.cpp +++ b/wled00/wled.cpp @@ -120,6 +120,7 @@ void WLED::loop() if (lastMqttReconnectAttempt > millis()) { rolloverMillis++; lastMqttReconnectAttempt = 0; + strip.restartRuntime(); } if (millis() - lastMqttReconnectAttempt > 30000) { lastMqttReconnectAttempt = millis();