ESPHome 2025.5.2
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
slow_pwm_output.h
Go to the documentation of this file.
1#pragma once
4#include "esphome/core/hal.h"
6
7namespace esphome {
8namespace slow_pwm {
9
11 public:
12 void set_pin(GPIOPin *pin) { pin_ = pin; };
13 void set_period(unsigned int period) { period_ = period; };
14 void set_restart_cycle_on_state_change(bool restart_cycle_on_state_change) {
15 restart_cycle_on_state_change_ = restart_cycle_on_state_change;
16 }
18
20 void setup() override;
21 void dump_config() override;
23 float get_setup_priority() const override { return setup_priority::HARDWARE; }
24
26 // Lazy create
27 if (!this->turn_on_trigger_)
28 this->turn_on_trigger_ = make_unique<Trigger<>>();
29 return this->turn_on_trigger_.get();
30 }
32 if (!this->turn_off_trigger_)
33 this->turn_off_trigger_ = make_unique<Trigger<>>();
34 return this->turn_off_trigger_.get();
35 }
36
38 if (!this->state_change_trigger_)
39 this->state_change_trigger_ = make_unique<Trigger<bool>>();
40 return this->state_change_trigger_.get();
41 }
42
43 protected:
44 void loop() override;
45 void write_state(float state) override;
47 void set_output_state_(bool state);
48
49 GPIOPin *pin_{nullptr};
50 std::unique_ptr<Trigger<>> turn_on_trigger_{nullptr};
51 std::unique_ptr<Trigger<>> turn_off_trigger_{nullptr};
52 std::unique_ptr<Trigger<bool>> state_change_trigger_{nullptr};
53 float state_{0};
54 bool current_state_{false};
55 unsigned int period_start_time_{0};
56 unsigned int period_;
58};
59
60} // namespace slow_pwm
61} // namespace esphome
Base class for all output components that can output a variable level, like PWM.
Trigger< bool > * get_state_change_trigger()
void set_output_state_(bool state)
turn on/off the configured output
void setup() override
Initialize pin.
void write_state(float state) override
std::unique_ptr< Trigger<> > turn_on_trigger_
void set_period(unsigned int period)
float get_setup_priority() const override
HARDWARE setup_priority.
void set_restart_cycle_on_state_change(bool restart_cycle_on_state_change)
std::unique_ptr< Trigger< bool > > state_change_trigger_
std::unique_ptr< Trigger<> > turn_off_trigger_
bool state
Definition fan.h:0
const float HARDWARE
For components that deal with hardware and are very important like GPIO switch.
Definition component.cpp:18
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7
uint32_t IRAM_ATTR HOT millis()
Definition core.cpp:28