4 #ifdef USE_BINARY_SENSOR 6 #endif // USE_BINARY_SENSOR 9 #endif // USE_LVGL_IMAGE 10 #ifdef USE_LVGL_ROTARY_ENCODER 12 #endif // USE_LVGL_ROTARY_ENCODER 16 #define LV_CONF_SKIP 1 // NOLINT 30 #endif // USE_LVGL_FONT 31 #ifdef USE_LVGL_TOUCHSCREEN 33 #endif // USE_LVGL_TOUCHSCREEN 35 #if defined(USE_LVGL_BUTTONMATRIX) || defined(USE_LVGL_KEYBOARD) 37 #endif // USE_LVGL_BUTTONMATRIX 45 #if LV_COLOR_DEPTH == 16 47 #elif LV_COLOR_DEPTH == 32 49 #else // LV_COLOR_DEPTH 51 #endif // LV_COLOR_DEPTH 62 #endif // USE_LVGL_IMAGE 63 #ifdef USE_LVGL_ANIMIMG 65 auto *dsc =
static_cast<std::vector<lv_img_dsc_t *> *
>(lv_obj_get_user_data(img));
68 dsc =
new std::vector<lv_img_dsc_t *>(images.size());
69 lv_obj_set_user_data(img, dsc);
72 for (
auto &image : images) {
73 dsc->push_back(image->get_lv_img_dsc());
78 #endif // USE_LVGL_ANIMIMG 83 virtual void set_obj(lv_obj_t *lv_obj) { this->
obj = lv_obj; }
93 this->
obj = lv_obj_create(
nullptr);
109 void play(Ts...
x)
override { this->lamb_(
x...); }
118 const lv_font_t *get_lv_font();
127 uint32_t last_letter_{};
129 lv_font_t lv_font_{};
131 #endif // USE_LVGL_FONT 132 #ifdef USE_LVGL_ANIMIMG 134 #endif // USE_LVGL_ANIMIMG 137 constexpr
static const char *
const TAG =
"lvgl";
140 LvglComponent(std::vector<display::Display *> displays,
float buffer_frac,
bool full_refresh,
int draw_rounding,
141 bool resume_on_input);
142 static void static_flush_cb(lv_disp_drv_t *disp_drv,
const lv_area_t *area, lv_color_t *color_p);
145 void setup()
override;
146 void update()
override;
147 void loop()
override;
149 this->idle_callbacks_.add(std::move(callback));
151 void add_on_pause_callback(std::function<
void(
bool)> &&callback) { this->pause_callbacks_.add(std::move(callback)); }
152 void dump_config()
override;
153 bool is_idle(uint32_t idle_ms) {
return lv_disp_get_inactive_time(this->disp_) > idle_ms; }
155 lv_obj_t *
get_scr_act() {
return lv_disp_get_scr_act(this->disp_); }
159 void set_paused(
bool paused,
bool show_snow);
163 if (this->paused_ && this->resume_on_input_) {
164 this->set_paused(
false,
false);
171 static void esphome_lvgl_init();
172 static void add_event_cb(lv_obj_t *obj,
event_callback_t callback, lv_event_code_t event);
173 static void add_event_cb(lv_obj_t *obj,
event_callback_t callback, lv_event_code_t event1, lv_event_code_t event2);
174 static void add_event_cb(lv_obj_t *obj,
event_callback_t callback, lv_event_code_t event1, lv_event_code_t event2,
175 lv_event_code_t event3);
177 void show_page(
size_t index, lv_scr_load_anim_t anim, uint32_t time);
178 void show_next_page(lv_scr_load_anim_t anim, uint32_t time);
179 void show_prev_page(lv_scr_load_anim_t anim, uint32_t time);
181 void set_focus_mark(lv_group_t *group) { this->focus_marks_[group] = lv_group_get_focused(group); }
183 auto *mark = this->focus_marks_[group];
184 if (mark !=
nullptr) {
185 lv_group_focus_obj(mark);
189 size_t draw_rounding{2};
194 void write_random_();
195 void draw_buffer_(
const lv_area_t *area, lv_color_t *ptr);
196 void flush_cb_(lv_disp_drv_t *disp_drv,
const lv_area_t *area, lv_color_t *color_p);
198 std::vector<display::Display *> displays_{};
199 size_t buffer_frac_{1};
200 bool full_refresh_{};
201 bool resume_on_input_{};
203 lv_disp_draw_buf_t draw_buf_{};
204 lv_disp_drv_t disp_drv_{};
207 std::vector<LvPageType *> pages_{};
208 size_t current_page_{0};
210 bool page_wrap_{
true};
211 std::map<lv_group_t *, lv_obj_t *> focus_marks_{};
215 lv_color_t *rotate_buf_{};
238 void play(Ts...
x)
override { this->action_(this->parent_); }
241 std::function<void(LvglComponent *)> action_{};
247 : condition_lambda_(
std::move(condition_lambda)) {}
248 bool check(Ts...
x)
override {
return this->condition_lambda_(this->parent_); }
251 std::function<bool(LvglComponent *)> condition_lambda_{};
254 #ifdef USE_LVGL_TOUCHSCREEN 260 touch_pressed_ =
false;
261 this->parent_->maybe_wakeup();
263 lv_indev_drv_t *
get_drv() {
return &this->drv_; }
266 lv_indev_drv_t drv_{};
268 bool touch_pressed_{};
270 #endif // USE_LVGL_TOUCHSCREEN 272 #ifdef USE_LVGL_KEY_LISTENER 277 #ifdef USE_BINARY_SENSOR 283 #ifdef USE_LVGL_ROTARY_ENCODER 287 #endif // USE_LVGL_ROTARY_ENCODER 290 if (!this->parent_->is_paused()) {
291 this->pressed_ = pressed;
293 }
else if (!pressed) {
295 this->parent_->maybe_wakeup();
300 if (!this->parent_->is_paused()) {
301 this->count_ = count;
303 this->parent_->maybe_wakeup();
307 lv_indev_drv_t *
get_drv() {
return &this->drv_; }
310 lv_indev_drv_t drv_{};
313 int32_t last_count_{};
316 #endif // USE_LVGL_KEY_LISTENER 318 #if defined(USE_LVGL_DROPDOWN) || defined(LV_USE_ROLLER) 321 virtual size_t get_selected_index() = 0;
322 virtual void set_selected_index(
size_t index, lv_anim_enable_t anim) = 0;
323 void set_selected_text(
const std::string &text, lv_anim_enable_t anim);
324 std::string get_selected_text();
326 void set_options(std::vector<std::string>
options);
329 virtual void set_option_string(
const char *options) = 0;
330 std::vector<std::string> options_{};
333 #ifdef USE_LVGL_DROPDOWN 337 void set_selected_index(
size_t index, lv_anim_enable_t anim)
override { lv_dropdown_set_selected(this->obj, index); }
342 #endif // USE_LVGL_DROPDOWN 344 #ifdef USE_LVGL_ROLLER 349 lv_roller_set_selected(this->obj, index, anim);
355 lv_roller_mode_t mode_{LV_ROLLER_MODE_NORMAL};
358 #endif // defined(USE_LVGL_DROPDOWN) || defined(LV_USE_ROLLER) 360 #ifdef USE_LVGL_BUTTONMATRIX 363 void set_obj(lv_obj_t *lv_obj)
override;
364 uint16_t
get_selected() {
return lv_btnmatrix_get_selected_btn(this->obj); }
365 void set_key(
size_t idx, uint8_t key) { this->key_map_[idx] = key; }
368 std::map<size_t, uint8_t> key_map_{};
370 #endif // USE_LVGL_BUTTONMATRIX 372 #ifdef USE_LVGL_KEYBOARD 375 void set_obj(lv_obj_t *lv_obj)
override;
377 #endif // USE_LVGL_KEYBOARD
std::string lv_event_code_name_for(uint8_t event_code)
void add_on_idle_callback(std::function< void(uint32_t)> &&callback)
void set_sensor(rotary_encoder::RotaryEncoderSensor *sensor)
void lv_img_set_src(lv_obj_t *obj, esphome::image::Image *image)
LvglCondition(std::function< bool(LvglComponent *)> &&condition_lambda)
bool check(Ts... x) override
std::vector< TouchPoint > TouchPoints_t
bool is_idle(uint32_t idle_ms)
void register_listener(std::function< void(uint32_t)> listener)
void set_selected_index(size_t index, lv_anim_enable_t anim) override
interface for components that provide keypresses
float get_setup_priority() const override
void set_option_string(const char *options) override
void lv_disp_set_bg_image(lv_disp_t *disp, esphome::image::Image *image)
lv_indev_drv_t * get_drv()
void play(Ts... x) override
Component for rendering LVGL.
This class simplifies creating components that periodically check a state.
void set_mode(lv_roller_mode_t mode)
void add_button(binary_sensor::BinarySensor *button, lv_key_t key)
void(_lv_event_t *) event_callback_t
TemplatableValue< bool > paused_
lv_event_code_t lv_update_event
std::function< void(float)> set_value_lambda_t
lv_event_code_t lv_api_event
void restore_focus_mark(lv_group_t *group)
virtual void set_obj(lv_obj_t *lv_obj)
Base class for all automation conditions.
void add_on_pause_callback(std::function< void(bool)> &&callback)
BedjetMode mode
BedJet operating mode.
void set_page_wrap(bool wrap)
std::function< void(Ts...)> lamb_
LvglAction(std::function< void(LvglComponent *)> &&lamb)
const float PROCESSOR
For components that use data from sensors like displays.
void lv_animimg_set_src(lv_obj_t *img, std::vector< image::Image *> images)
size_t get_selected_index() override
TemplatableValue< uint32_t > timeout_
lv_img_dsc_t * get_lv_img_dsc()
std::function< void(lv_obj_t *)> LvLambdaType
void event(int key, bool pressed)
std::function< const char *()> text_lambda_t
void add_on_state_callback(std::function< void(bool)> &&callback)
Add a callback to be notified of state changes.
void set_focus_mark(lv_group_t *group)
Implementation of SPI Controller mode.
Base class for all binary_sensor-type classes.
std::vector< std::string > get_options()
lv_indev_drv_t * get_drv()
void set_count(int32_t count)
void lv_animimg_stop(lv_obj_t *obj)
size_t get_selected_index() override
ObjUpdateAction(std::function< void(Ts...)> &&lamb)
esphome::sensor::Sensor * sensor
Helper class to easily give an object a parent of type T.
void play(Ts... x) override
void set_selected_index(size_t index, lv_anim_enable_t anim) override
void set_option_string(const char *options) override