ESPHome  2024.12.2
hbridge_light_output.h
Go to the documentation of this file.
1 #pragma once
2 
6 #include "esphome/core/log.h"
7 
8 namespace esphome {
9 namespace hbridge {
10 
11 // Using PollingComponent as the updates are more consistent and reduces flickering
13  public:
15 
16  void set_pina_pin(output::FloatOutput *pina_pin) { pina_pin_ = pina_pin; }
17  void set_pinb_pin(output::FloatOutput *pinb_pin) { pinb_pin_ = pinb_pin; }
18 
20  auto traits = light::LightTraits();
21  traits.set_supported_color_modes({light::ColorMode::COLD_WARM_WHITE});
22  traits.set_min_mireds(153);
23  traits.set_max_mireds(500);
24  return traits;
25  }
26 
27  void setup() override { this->forward_direction_ = false; }
28 
29  void update() override {
30  // This method runs around 60 times per second
31  // We cannot do the PWM ourselves so we are reliant on the hardware PWM
32  if (!this->forward_direction_) { // First LED Direction
33  this->pina_pin_->set_level(this->pina_duty_);
34  this->pinb_pin_->set_level(0);
35  this->forward_direction_ = true;
36  } else { // Second LED Direction
37  this->pina_pin_->set_level(0);
38  this->pinb_pin_->set_level(this->pinb_duty_);
39  this->forward_direction_ = false;
40  }
41  }
42 
43  float get_setup_priority() const override { return setup_priority::HARDWARE; }
44 
46  state->current_values_as_cwww(&this->pina_duty_, &this->pinb_duty_, false);
47  }
48 
49  protected:
52  float pina_duty_ = 0;
53  float pinb_duty_ = 0;
54  bool forward_direction_ = false;
55 };
56 
57 } // namespace hbridge
58 } // namespace esphome
This class represents the communication layer between the front-end MQTT layer and the hardware outpu...
Definition: light_state.h:63
Interface to write LightStates to hardware.
Definition: light_output.h:12
Base class for all output components that can output a variable level, like PWM.
Definition: float_output.h:31
void set_pinb_pin(output::FloatOutput *pinb_pin)
light::LightTraits get_traits() override
void set_pina_pin(output::FloatOutput *pina_pin)
void write_state(light::LightState *state) override
This class simplifies creating components that periodically check a state.
Definition: component.h:283
void set_level(float state)
Set the level of this float output, this is called from the front-end.
Brightness of cold and warm white output can be controlled.
void current_values_as_cwww(float *cold_white, float *warm_white, bool constant_brightness=false)
This class is used to represent the capabilities of a light.
Definition: light_traits.h:11
const float HARDWARE
For components that deal with hardware and are very important like GPIO switch.
Definition: component.cpp:18
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
bool state
Definition: fan.h:34