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 59 #endif // USE_LVGL_IMAGE 64 virtual void set_obj(lv_obj_t *lv_obj) { this->
obj = lv_obj; }
74 this->
obj = lv_obj_create(
nullptr);
90 void play(Ts...
x)
override { this->lamb_(
x...); }
93 std::function<void(Ts...)>
lamb_;
99 const lv_font_t *get_lv_font();
108 uint32_t last_letter_{};
110 lv_font_t lv_font_{};
112 #endif // USE_LVGL_FONT 113 #ifdef USE_LVGL_ANIMIMG 115 #endif // USE_LVGL_ANIMIMG 118 constexpr
static const char *
const TAG =
"lvgl";
121 LvglComponent(std::vector<display::Display *> displays,
float buffer_frac,
bool full_refresh,
int draw_rounding,
122 bool resume_on_input);
123 static void static_flush_cb(lv_disp_drv_t *disp_drv,
const lv_area_t *area, lv_color_t *color_p);
126 void setup()
override;
127 void update()
override;
128 void loop()
override;
130 this->idle_callbacks_.add(std::move(callback));
132 void add_on_pause_callback(std::function<
void(
bool)> &&callback) { this->pause_callbacks_.add(std::move(callback)); }
133 void dump_config()
override;
134 bool is_idle(uint32_t idle_ms) {
return lv_disp_get_inactive_time(this->disp_) > idle_ms; }
136 lv_obj_t *
get_scr_act() {
return lv_disp_get_scr_act(this->disp_); }
140 void set_paused(
bool paused,
bool show_snow);
144 if (this->paused_ && this->resume_on_input_) {
145 this->set_paused(
false,
false);
152 static void esphome_lvgl_init();
153 static void add_event_cb(lv_obj_t *obj,
event_callback_t callback, lv_event_code_t event);
154 static void add_event_cb(lv_obj_t *obj,
event_callback_t callback, lv_event_code_t event1, lv_event_code_t event2);
155 static void add_event_cb(lv_obj_t *obj,
event_callback_t callback, lv_event_code_t event1, lv_event_code_t event2,
156 lv_event_code_t event3);
158 void show_page(
size_t index, lv_scr_load_anim_t anim, uint32_t time);
159 void show_next_page(lv_scr_load_anim_t anim, uint32_t time);
160 void show_prev_page(lv_scr_load_anim_t anim, uint32_t time);
162 void set_focus_mark(lv_group_t *group) { this->focus_marks_[group] = lv_group_get_focused(group); }
164 auto *mark = this->focus_marks_[group];
165 if (mark !=
nullptr) {
166 lv_group_focus_obj(mark);
170 size_t draw_rounding{2};
175 void write_random_();
176 void draw_buffer_(
const lv_area_t *area, lv_color_t *ptr);
177 void flush_cb_(lv_disp_drv_t *disp_drv,
const lv_area_t *area, lv_color_t *color_p);
179 std::vector<display::Display *> displays_{};
180 size_t buffer_frac_{1};
181 bool full_refresh_{};
182 bool resume_on_input_{};
184 lv_disp_draw_buf_t draw_buf_{};
185 lv_disp_drv_t disp_drv_{};
188 std::vector<LvPageType *> pages_{};
189 size_t current_page_{0};
191 bool page_wrap_{
true};
192 std::map<lv_group_t *, lv_obj_t *> focus_marks_{};
196 lv_color_t *rotate_buf_{};
219 void play(Ts...
x)
override { this->action_(this->parent_); }
222 std::function<void(LvglComponent *)> action_{};
228 : condition_lambda_(
std::move(condition_lambda)) {}
229 bool check(Ts...
x)
override {
return this->condition_lambda_(this->parent_); }
232 std::function<bool(LvglComponent *)> condition_lambda_{};
235 #ifdef USE_LVGL_TOUCHSCREEN 241 touch_pressed_ =
false;
242 this->parent_->maybe_wakeup();
244 lv_indev_drv_t *
get_drv() {
return &this->drv_; }
247 lv_indev_drv_t drv_{};
249 bool touch_pressed_{};
251 #endif // USE_LVGL_TOUCHSCREEN 253 #ifdef USE_LVGL_KEY_LISTENER 258 #ifdef USE_BINARY_SENSOR 264 #ifdef USE_LVGL_ROTARY_ENCODER 268 #endif // USE_LVGL_ROTARY_ENCODER 271 if (!this->parent_->is_paused()) {
272 this->pressed_ = pressed;
274 }
else if (!pressed) {
276 this->parent_->maybe_wakeup();
281 if (!this->parent_->is_paused()) {
282 this->count_ = count;
284 this->parent_->maybe_wakeup();
288 lv_indev_drv_t *
get_drv() {
return &this->drv_; }
291 lv_indev_drv_t drv_{};
294 int32_t last_count_{};
297 #endif // USE_LVGL_KEY_LISTENER 299 #if defined(USE_LVGL_DROPDOWN) || defined(LV_USE_ROLLER) 302 virtual size_t get_selected_index() = 0;
303 virtual void set_selected_index(
size_t index, lv_anim_enable_t anim) = 0;
304 void set_selected_text(
const std::string &text, lv_anim_enable_t anim);
305 std::string get_selected_text();
307 void set_options(std::vector<std::string>
options);
310 virtual void set_option_string(
const char *options) = 0;
311 std::vector<std::string> options_{};
314 #ifdef USE_LVGL_DROPDOWN 318 void set_selected_index(
size_t index, lv_anim_enable_t anim)
override { lv_dropdown_set_selected(this->obj, index); }
323 #endif // USE_LVGL_DROPDOWN 325 #ifdef USE_LVGL_ROLLER 330 lv_roller_set_selected(this->obj, index, anim);
336 lv_roller_mode_t mode_{LV_ROLLER_MODE_NORMAL};
339 #endif // defined(USE_LVGL_DROPDOWN) || defined(LV_USE_ROLLER) 341 #ifdef USE_LVGL_BUTTONMATRIX 344 void set_obj(lv_obj_t *lv_obj)
override;
345 uint16_t
get_selected() {
return lv_btnmatrix_get_selected_btn(this->obj); }
346 void set_key(
size_t idx, uint8_t key) { this->key_map_[idx] = key; }
349 std::map<size_t, uint8_t> key_map_{};
351 #endif // USE_LVGL_BUTTONMATRIX 353 #ifdef USE_LVGL_KEYBOARD 356 void set_obj(lv_obj_t *lv_obj)
override;
358 #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
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.
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