ESPHome  2022.6.3
slow_pwm_output.h
Go to the documentation of this file.
1 #pragma once
4 #include "esphome/core/hal.h"
6 
7 namespace esphome {
8 namespace 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  }
17 
19  void setup() override;
20  void dump_config() override;
22  float get_setup_priority() const override { return setup_priority::HARDWARE; }
23 
25  // Lazy create
26  if (!this->turn_on_trigger_)
27  this->turn_on_trigger_ = make_unique<Trigger<>>();
28  return this->turn_on_trigger_.get();
29  }
31  if (!this->turn_off_trigger_)
32  this->turn_off_trigger_ = make_unique<Trigger<>>();
33  return this->turn_off_trigger_.get();
34  }
35 
37  if (!this->state_change_trigger_)
38  this->state_change_trigger_ = make_unique<Trigger<bool>>();
39  return this->state_change_trigger_.get();
40  }
41 
42  protected:
43  void loop() override;
44  void write_state(float state) override;
46  void set_output_state_(bool state);
47 
48  GPIOPin *pin_{nullptr};
49  std::unique_ptr<Trigger<>> turn_on_trigger_{nullptr};
50  std::unique_ptr<Trigger<>> turn_off_trigger_{nullptr};
51  std::unique_ptr<Trigger<bool>> state_change_trigger_{nullptr};
52  float state_{0};
53  bool current_state_{false};
54  unsigned int period_start_time_{0};
55  unsigned int period_;
57 };
58 
59 } // namespace slow_pwm
60 } // namespace esphome
void write_state(float state) override
std::unique_ptr< Trigger<> > turn_off_trigger_
float get_setup_priority() const override
HARDWARE setup_priority.
Base class for all output components that can output a variable level, like PWM.
Definition: float_output.h:31
std::unique_ptr< Trigger<> > turn_on_trigger_
void set_output_state_(bool state)
turn on/off the configured output
void set_period(unsigned int period)
void set_restart_cycle_on_state_change(bool restart_cycle_on_state_change)
const float HARDWARE
For components that deal with hardware and are very important like GPIO switch.
Definition: component.cpp:17
Trigger< bool > * get_state_change_trigger()
void setup() override
Initialize pin.
Definition: a4988.cpp:4
std::unique_ptr< Trigger< bool > > state_change_trigger_
bool state
Definition: fan.h:34