[wled] Fix millis overflow in blank timeout (#14300)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: J. Nick Koston <nick+github@koston.org>
This commit is contained in:
Jonathan Swoboda
2026-02-25 18:01:49 -05:00
committed by GitHub
parent 0a81a7a50b
commit 534857db9c
2 changed files with 14 additions and 10 deletions
+12 -9
View File
@@ -24,7 +24,7 @@ namespace wled {
// https://github.com/Aircoookie/WLED/wiki/UDP-Realtime-Control
enum Protocol { WLED_NOTIFIER = 0, WARLS = 1, DRGB = 2, DRGBW = 3, DNRGB = 4 };
const int DEFAULT_BLANK_TIME = 1000;
constexpr uint32_t DEFAULT_BLANK_TIME = 1000;
static const char *const TAG = "wled_light_effect";
@@ -34,9 +34,10 @@ void WLEDLightEffect::start() {
AddressableLightEffect::start();
if (this->blank_on_start_) {
this->blank_at_ = 0;
this->blank_start_ = millis();
this->blank_timeout_ = 0;
} else {
this->blank_at_ = UINT32_MAX;
this->blank_start_.reset();
}
}
@@ -81,10 +82,10 @@ void WLEDLightEffect::apply(light::AddressableLight &it, const Color &current_co
}
}
// FIXME: Use roll-over safe arithmetic
if (blank_at_ < millis()) {
if (this->blank_start_.has_value() && millis() - *this->blank_start_ >= this->blank_timeout_) {
blank_all_leds_(it);
blank_at_ = millis() + DEFAULT_BLANK_TIME;
this->blank_start_ = millis();
this->blank_timeout_ = DEFAULT_BLANK_TIME;
}
}
@@ -142,11 +143,13 @@ bool WLEDLightEffect::parse_frame_(light::AddressableLight &it, const uint8_t *p
}
if (timeout == UINT8_MAX) {
blank_at_ = UINT32_MAX;
this->blank_start_.reset();
} else if (timeout > 0) {
blank_at_ = millis() + timeout * 1000;
this->blank_start_ = millis();
this->blank_timeout_ = timeout * 1000;
} else {
blank_at_ = millis() + DEFAULT_BLANK_TIME;
this->blank_start_ = millis();
this->blank_timeout_ = DEFAULT_BLANK_TIME;
}
it.schedule_show();
+2 -1
View File
@@ -35,7 +35,8 @@ class WLEDLightEffect : public light::AddressableLightEffect {
uint16_t port_{0};
std::unique_ptr<UDP> udp_;
uint32_t blank_at_{0};
optional<uint32_t> blank_start_{};
uint32_t blank_timeout_{0};
uint32_t dropped_{0};
uint8_t sync_group_mask_{0};
bool blank_on_start_{true};