ESPHome 2025.5.0
Loading...
Searching...
No Matches
lvgl_light.h
Go to the documentation of this file.
1#pragma once
2
5#include "../lvgl_esphome.h"
6
7namespace esphome {
8namespace lvgl {
9
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
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.
light::LightTraits get_traits() override
Definition lvgl_light.h:12
optional< lv_color_t > initial_value_
Definition lvgl_light.h:44
void set_obj(lv_obj_t *obj)
Definition lvgl_light.h:28
void write_state(light::LightState *state) override
Definition lvgl_light.h:17
void set_value_(lv_color_t value)
Definition lvgl_light.h:38
value_type const & value() const
Definition optional.h:89
bool state
Definition fan.h:0
@ RGB
RGB color output.
lv_event_code_t lv_api_event
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7