Fix the initial run of lambda light effects (#5921)

The timer used for `millis()` is a monotonic timer based on the last
start time of the device. If, for some reason, you pick a long
`update_interval` and try to apply it as soon as you start the device,
nothing happens because the device hasn't been on for longer than the
`update_interval`
This commit is contained in:
Jacob Masen-Smith 2023-12-13 12:33:24 -08:00 committed by GitHub
parent f355972c9d
commit 9a8bc9484d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 2 additions and 2 deletions

View file

@ -57,7 +57,7 @@ class AddressableLambdaLightEffect : public AddressableLightEffect {
void start() override { this->initial_run_ = true; } void start() override { this->initial_run_ = true; }
void apply(AddressableLight &it, const Color &current_color) override { void apply(AddressableLight &it, const Color &current_color) override {
const uint32_t now = millis(); const uint32_t now = millis();
if (now - this->last_run_ >= this->update_interval_) { if (now - this->last_run_ >= this->update_interval_ || this->initial_run_) {
this->last_run_ = now; this->last_run_ = now;
this->f_(it, current_color, this->initial_run_); this->f_(it, current_color, this->initial_run_);
this->initial_run_ = false; this->initial_run_ = false;

View file

@ -118,7 +118,7 @@ class LambdaLightEffect : public LightEffect {
void start() override { this->initial_run_ = true; } void start() override { this->initial_run_ = true; }
void apply() override { void apply() override {
const uint32_t now = millis(); const uint32_t now = millis();
if (now - this->last_run_ >= this->update_interval_) { if (now - this->last_run_ >= this->update_interval_ || this->initial_run_) {
this->last_run_ = now; this->last_run_ = now;
this->f_(this->initial_run_); this->f_(this->initial_run_);
this->initial_run_ = false; this->initial_run_ = false;