ESPHome  2024.12.0
hbridge_switch.h
Go to the documentation of this file.
1 #pragma once
2 
4 #include "esphome/core/hal.h"
6 
7 #include <vector>
8 
9 namespace esphome {
10 namespace hbridge {
11 
12 enum RelayState : uint8_t {
18 };
19 
20 class HBridgeSwitch : public switch_::Switch, public Component {
21  public:
22  void set_on_pin(GPIOPin *pin) { this->on_pin_ = pin; }
23  void set_off_pin(GPIOPin *pin) { this->off_pin_ = pin; }
24  void set_pulse_length(uint32_t pulse_length) { this->pulse_length_ = pulse_length; }
25  void set_wait_time(uint32_t wait_time) { this->wait_time_ = wait_time; }
26  void set_optimistic(bool optimistic) { this->optimistic_ = optimistic; }
27 
28  // ========== INTERNAL METHODS ==========
29  // (In most use cases you won't need these)
30  float get_setup_priority() const override;
31 
32  void setup() override;
33  void dump_config() override;
34 
35  protected:
36  void write_state(bool state) override;
37  void timer_fn_();
38 
39  bool timer_running_{false};
40  bool desired_state_{false};
42  GPIOPin *on_pin_{nullptr};
43  GPIOPin *off_pin_{nullptr};
44  uint32_t pulse_length_{0};
45  uint32_t wait_time_{0};
46  bool optimistic_{false};
47 };
48 
49 } // namespace hbridge
50 } // namespace esphome
Base class for all switches.
Definition: switch.h:39
void set_pulse_length(uint32_t pulse_length)
float get_setup_priority() const override
void set_off_pin(GPIOPin *pin)
void write_state(bool state) override
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
void set_wait_time(uint32_t wait_time)
void set_optimistic(bool optimistic)
bool state
The current reported state of the binary sensor.
Definition: switch.h:53