mirror of
https://github.com/esphome/esphome.git
synced 2024-12-22 21:44:55 +01:00
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:
parent
f355972c9d
commit
9a8bc9484d
2 changed files with 2 additions and 2 deletions
|
@ -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 ¤t_color) override {
|
void apply(AddressableLight &it, const Color ¤t_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;
|
||||||
|
|
|
@ -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;
|
||||||
|
|
Loading…
Reference in a new issue