ESPHome 2025.5.0
Loading...
Searching...
No Matches
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
9namespace esphome {
10namespace hbridge {
11
19
20class 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
void write_state(bool state) override
void set_pulse_length(uint32_t pulse_length)
void set_optimistic(bool optimistic)
void set_wait_time(uint32_t wait_time)
float get_setup_priority() const override
Base class for all switches.
Definition switch.h:39
bool state
The current reported state of the binary sensor.
Definition switch.h:53
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7