Files
esphome-lsm6ds/esphome/components/lvgl/light/lvgl_light.h
T
2341d510d3 [lvgl] Migrate to library v9.5.0 (#12312)
Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com>
Co-authored-by: Jonathan Swoboda <154711427+swoboda1337@users.noreply.github.com>
2026-03-19 20:31:33 +13:00

49 lines
1.2 KiB
C++

#pragma once
#include "esphome/core/component.h"
#include "esphome/components/light/light_output.h"
#include "../lvgl_esphome.h"
namespace esphome {
namespace lvgl {
class LVLight : public light::LightOutput {
public:
light::LightTraits get_traits() override {
auto traits = light::LightTraits();
traits.set_supported_color_modes({light::ColorMode::RGB});
return traits;
}
void write_state(light::LightState *state) override {
float red, green, blue;
state->current_values_as_rgb(&red, &green, &blue);
auto color = lv_color_make(red * 255, green * 255, blue * 255);
if (this->obj_ != nullptr) {
this->set_value_(color);
} else {
this->initial_value_ = color;
}
}
void set_obj(lv_obj_t *obj) {
this->obj_ = obj;
if (this->initial_value_) {
lv_led_set_color(obj, this->initial_value_.value());
lv_led_on(obj);
this->initial_value_.reset();
}
}
protected:
void set_value_(lv_color_t value) {
lv_led_set_color(this->obj_, value);
lv_led_on(this->obj_);
lv_obj_send_event(this->obj_, lv_api_event, nullptr);
}
lv_obj_t *obj_{};
optional<lv_color_t> initial_value_{};
};
} // namespace lvgl
} // namespace esphome