ESPHome
2026.5.0b1
Loading...
Searching...
No Matches
esphome
components
lvgl
light
lvgl_light.h
Go to the documentation of this file.
1
#pragma once
2
3
#include "
esphome/core/component.h
"
4
#include "
esphome/components/light/light_output.h
"
5
#include "
../lvgl_esphome.h
"
6
7
namespace
esphome::lvgl
{
8
9
class
LVLight
:
public
light::LightOutput
{
10
public
:
11
light::LightTraits
get_traits
()
override
{
12
auto
traits =
light::LightTraits
();
13
traits.set_supported_color_modes({
light::ColorMode::RGB
});
14
return
traits;
15
}
16
void
write_state
(
light::LightState
*
state
)
override
{
17
float
red, green, blue;
18
state
->current_values_as_rgb(&red, &green, &blue);
19
auto
color = lv_color_make(red * 255, green * 255, blue * 255);
20
if
(this->
obj_
!=
nullptr
) {
21
this->
set_value_
(color);
22
}
else
{
23
this->
initial_value_
= color;
24
}
25
}
26
27
void
set_obj
(lv_obj_t *obj) {
28
this->
obj_
= obj;
29
if
(this->
initial_value_
) {
30
lv_led_set_color(obj, this->
initial_value_
.value());
31
lv_led_on(obj);
32
this->
initial_value_
.reset();
33
}
34
}
35
36
protected
:
37
void
set_value_
(lv_color_t value) {
38
lv_led_set_color(this->
obj_
, value);
39
lv_led_on(this->
obj_
);
40
lv_obj_send_event(this->
obj_
,
lv_update_event
,
nullptr
);
41
}
42
lv_obj_t *
obj_
{};
43
optional<lv_color_t>
initial_value_
{};
44
};
45
46
}
// namespace esphome::lvgl
esphome::light::LightOutput
Interface to write LightStates to hardware.
Definition
light_output.h:11
esphome::light::LightState
This class represents the communication layer between the front-end MQTT layer and the hardware outpu...
Definition
light_state.h:93
esphome::light::LightTraits
This class is used to represent the capabilities of a light.
Definition
light_traits.h:9
esphome::lvgl::LVLight
Definition
lvgl_light.h:9
esphome::lvgl::LVLight::get_traits
light::LightTraits get_traits() override
Definition
lvgl_light.h:11
esphome::lvgl::LVLight::initial_value_
optional< lv_color_t > initial_value_
Definition
lvgl_light.h:43
esphome::lvgl::LVLight::set_obj
void set_obj(lv_obj_t *obj)
Definition
lvgl_light.h:27
esphome::lvgl::LVLight::write_state
void write_state(light::LightState *state) override
Definition
lvgl_light.h:16
esphome::lvgl::LVLight::set_value_
void set_value_(lv_color_t value)
Definition
lvgl_light.h:37
esphome::lvgl::LVLight::obj_
lv_obj_t * obj_
Definition
lvgl_light.h:42
component.h
state
bool state
Definition
fan.h:2
light_output.h
lvgl_esphome.h
esphome::light::ColorMode::RGB
@ RGB
RGB color output.
esphome::lvgl
Definition
lvgl_light.h:7
esphome::lvgl::lv_update_event
lv_event_code_t lv_update_event
Definition
lvgl_esphome.cpp:150
Generated by
1.12.0