ESPHome 2025.5.0
Loading...
Searching...
No Matches
hbridge_light_output.h
Go to the documentation of this file.
1#pragma once
2
6#include "esphome/core/log.h"
7
8namespace esphome {
9namespace 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 simplifies creating components that periodically check a state.
Definition component.h:301
void set_pinb_pin(output::FloatOutput *pinb_pin)
void write_state(light::LightState *state) override
light::LightTraits get_traits() override
void set_pina_pin(output::FloatOutput *pina_pin)
Interface to write LightStates to hardware.
This class represents the communication layer between the front-end MQTT layer and the hardware outpu...
Definition light_state.h:63
This class is used to represent the capabilities of a light.
Base class for all output components that can output a variable level, like PWM.
void set_level(float state)
Set the level of this float output, this is called from the front-end.
bool state
Definition fan.h:0
@ COLD_WARM_WHITE
Cold and warm white output with individually controllable brightness.
const float HARDWARE
For components that deal with hardware and are very important like GPIO switch.
Definition component.cpp:18
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7