From 503c68320a73181ce560b15349efab7875b6a4b9 Mon Sep 17 00:00:00 2001 From: Damian Schneider Date: Fri, 5 Apr 2024 07:23:28 +0200 Subject: [PATCH] Bugfix: millis rollover (fix for #3870) millis()/1000 rollover after 18h was not handled, truncating to 16bits after division fixes it. --- wled00/FX_fcn.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/wled00/FX_fcn.cpp b/wled00/FX_fcn.cpp index 617558ff..fcf6cd0c 100644 --- a/wled00/FX_fcn.cpp +++ b/wled00/FX_fcn.cpp @@ -455,9 +455,9 @@ CRGBPalette16 IRAM_ATTR &Segment::currentPalette(CRGBPalette16 &targetPalette, u // relies on WS2812FX::service() to call it for each frame void Segment::handleRandomPalette() { // is it time to generate a new palette? - if ((millis()/1000U) - _lastPaletteChange > randomPaletteChangeTime) { + if (((millis()/1000U) & 0xFFFF) - _lastPaletteChange > randomPaletteChangeTime) { _newRandomPalette = useHarmonicRandomPalette ? generateHarmonicRandomPalette(_randomPalette) : generateRandomPalette(); - _lastPaletteChange = millis()/1000U; + _lastPaletteChange = millis()/1000U; //take lower 16bits _lastPaletteBlend = (uint16_t)(millis() & 0xFFFF)-512; // starts blending immediately } @@ -466,7 +466,7 @@ void Segment::handleRandomPalette() { // assumes that 128 updates are sufficient to blend a palette, so shift by 7 (can be more, can be less) // in reality there need to be 255 blends to fully blend two entirely different palettes if ((millis() & 0xFFFF) - _lastPaletteBlend < strip.getTransition() >> 7) return; // not yet time to fade, delay the update - _lastPaletteBlend = millis(); + _lastPaletteBlend = millis(); //take lower 16bits } nblendPaletteTowardPalette(_randomPalette, _newRandomPalette, 48); }