From 92e44b8238d0190ec2b7c04303f766e43b3509f8 Mon Sep 17 00:00:00 2001 From: John Britton Date: Wed, 7 Dec 2022 01:27:14 -0500 Subject: [PATCH] Expose lambda action to reset a cycle in `slow_pwm` (#4158) --- esphome/components/slow_pwm/slow_pwm_output.cpp | 2 +- esphome/components/slow_pwm/slow_pwm_output.h | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/esphome/components/slow_pwm/slow_pwm_output.cpp b/esphome/components/slow_pwm/slow_pwm_output.cpp index 81c721a866..d6b2cdfe12 100644 --- a/esphome/components/slow_pwm/slow_pwm_output.cpp +++ b/esphome/components/slow_pwm/slow_pwm_output.cpp @@ -70,7 +70,7 @@ void SlowPWMOutput::dump_config() { void SlowPWMOutput::write_state(float state) { this->state_ = state; if (this->restart_cycle_on_state_change_) - this->period_start_time_ = millis(); + this->restart_cycle(); } } // namespace slow_pwm diff --git a/esphome/components/slow_pwm/slow_pwm_output.h b/esphome/components/slow_pwm/slow_pwm_output.h index be45736864..3e5a3e2a40 100644 --- a/esphome/components/slow_pwm/slow_pwm_output.h +++ b/esphome/components/slow_pwm/slow_pwm_output.h @@ -14,6 +14,7 @@ class SlowPWMOutput : public output::FloatOutput, public Component { void set_restart_cycle_on_state_change(bool restart_cycle_on_state_change) { restart_cycle_on_state_change_ = restart_cycle_on_state_change; } + void restart_cycle() { this->period_start_time_ = millis(); } /// Initialize pin void setup() override;