ESPHome  2024.10.2
hbridge_fan.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <set>
4 
9 
10 namespace esphome {
11 namespace hbridge {
12 
13 enum DecayMode {
16 };
17 
18 class HBridgeFan : public Component, public fan::Fan {
19  public:
20  HBridgeFan(int speed_count, DecayMode decay_mode) : speed_count_(speed_count), decay_mode_(decay_mode) {}
21 
22  void set_pin_a(output::FloatOutput *pin_a) { pin_a_ = pin_a; }
23  void set_pin_b(output::FloatOutput *pin_b) { pin_b_ = pin_b; }
24  void set_enable_pin(output::FloatOutput *enable) { enable_ = enable; }
25  void set_preset_modes(const std::set<std::string> &presets) { preset_modes_ = presets; }
26 
27  void setup() override;
28  void dump_config() override;
29  fan::FanTraits get_traits() override { return this->traits_; }
30 
32 
33  protected:
38  int speed_count_{};
41  std::set<std::string> preset_modes_{};
42 
43  void control(const fan::FanCall &call) override;
44  void write_state_();
45 
46  void set_hbridge_levels_(float a_level, float b_level);
47  void set_hbridge_levels_(float a_level, float b_level, float enable);
48 };
49 
50 template<typename... Ts> class BrakeAction : public Action<Ts...> {
51  public:
52  explicit BrakeAction(HBridgeFan *parent) : parent_(parent) {}
53 
54  void play(Ts... x) override { this->parent_->brake(); }
55 
57 };
58 
59 } // namespace hbridge
60 } // namespace esphome
fan::FanTraits get_traits() override
Definition: hbridge_fan.h:29
void control(const fan::FanCall &call) override
Definition: hbridge_fan.cpp:51
void set_preset_modes(const std::set< std::string > &presets)
Definition: hbridge_fan.h:25
void set_hbridge_levels_(float a_level, float b_level)
Definition: hbridge_fan.cpp:9
Base class for all output components that can output a variable level, like PWM.
Definition: float_output.h:31
uint16_t x
Definition: tt21100.cpp:17
output::FloatOutput * pin_a_
Definition: hbridge_fan.h:34
void set_pin_b(output::FloatOutput *pin_b)
Definition: hbridge_fan.h:23
BrakeAction(HBridgeFan *parent)
Definition: hbridge_fan.h:52
void play(Ts... x) override
Definition: hbridge_fan.h:54
output::FloatOutput * enable_
Definition: hbridge_fan.h:36
HBridgeFan(int speed_count, DecayMode decay_mode)
Definition: hbridge_fan.h:20
output::FloatOutput * pin_b_
Definition: hbridge_fan.h:35
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
std::set< std::string > preset_modes_
Definition: hbridge_fan.h:41
void set_enable_pin(output::FloatOutput *enable)
Definition: hbridge_fan.h:24
output::BinaryOutput * oscillating_
Definition: hbridge_fan.h:37
void set_pin_a(output::FloatOutput *pin_a)
Definition: hbridge_fan.h:22