ESPHome  2024.12.2
lvgl_light.h
Go to the documentation of this file.
1 #pragma once
2 
5 #include "../lvgl_esphome.h"
6 
7 namespace esphome {
8 namespace lvgl {
9 
10 class LVLight : public light::LightOutput {
11  public:
13  auto traits = light::LightTraits();
14  traits.set_supported_color_modes({light::ColorMode::RGB});
15  return traits;
16  }
18  float red, green, blue;
19  state->current_values_as_rgb(&red, &green, &blue, false);
20  auto color = lv_color_make(red * 255, green * 255, blue * 255);
21  if (this->obj_ != nullptr) {
22  this->set_value_(color);
23  } else {
24  this->initial_value_ = color;
25  }
26  }
27 
28  void set_obj(lv_obj_t *obj) {
29  this->obj_ = obj;
30  if (this->initial_value_) {
31  lv_led_set_color(obj, this->initial_value_.value());
32  lv_led_on(obj);
33  this->initial_value_.reset();
34  }
35  }
36 
37  protected:
38  void set_value_(lv_color_t value) {
39  lv_led_set_color(this->obj_, value);
40  lv_led_on(this->obj_);
41  lv_event_send(this->obj_, lv_api_event, nullptr);
42  }
43  lv_obj_t *obj_{};
45 };
46 
47 } // namespace lvgl
48 } // namespace esphome
value_type const & value() const
Definition: optional.h:89
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
optional< lv_color_t > initial_value_
Definition: lvgl_light.h:44
void set_value_(lv_color_t value)
Definition: lvgl_light.h:38
void current_values_as_rgb(float *red, float *green, float *blue, bool color_interlock=false)
lv_event_code_t lv_api_event
void set_obj(lv_obj_t *obj)
Definition: lvgl_light.h:28
light::LightTraits get_traits() override
Definition: lvgl_light.h:12
void write_state(light::LightState *state) override
Definition: lvgl_light.h:17
This class is used to represent the capabilities of a light.
Definition: light_traits.h:11
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
Color can be controlled using RGB format (includes a brightness control for the color).
bool state
Definition: fan.h:34