Enhance EInkDisplayHandler and LVGLHandler with deep sleep functionality and partial refresh improvements

This commit is contained in:
GW_MC
2026-01-27 19:12:37 +08:00
parent dc2a76e131
commit de2f166151
5 changed files with 343 additions and 80 deletions

View File

@@ -156,19 +156,33 @@ void LVGL_Checkerboard(
// Add safety checks
if (!handler) {
ESP_LOGE("LVGL", "Handler is null!");
delete params;
vTaskDelete(NULL);
return;
}
ESP_LOGI("HEAP", "Free: %d", esp_get_free_heap_size());
// Wait for LVGL system to fully initialize
vTaskDelay(pdMS_TO_TICKS(200));
// Acquire LVGL lock with proper timeout
if (!lvgl_port_lock(pdMS_TO_TICKS(1000))) {
if (!lvgl_port_lock(pdMS_TO_TICKS(5000))) {
ESP_LOGE(TAG, "Failed to acquire LVGL lock for checkerboard");
delete params;
vTaskDelete(NULL);
return;
}
// Verify LVGL is properly initialized
if (lv_display_get_default() == nullptr) {
ESP_LOGE(TAG, "LVGL default display not available");
lvgl_port_unlock();
delete params;
vTaskDelete(NULL);
return;
}
// Create LVGL objects for checkerboard
lv_obj_t* scr = lv_scr_act();
if (scr == nullptr) {
@@ -187,25 +201,42 @@ void LVGL_Checkerboard(
return;
}
lv_obj_set_size(checkerboard, DISPLAY_WIDTH, DISPLAY_HEIGHT);
lv_obj_center(checkerboard);
// remove border and padding
lv_obj_set_style_pad_all(checkerboard, 0, 0);
lv_obj_set_style_border_width(checkerboard, 0, 0);
const int CELL_SIZE = 40;
lvgl_port_unlock();
// Create checkerboard pattern using LVGL
for (int y = 0; y < DISPLAY_HEIGHT; y += CELL_SIZE) {
lvgl_port_lock(pdMS_TO_TICKS(1000));
for (int x = 0; x < DISPLAY_WIDTH; x += CELL_SIZE) {
lv_color_t color = (((x / CELL_SIZE) % 2) == ((y / CELL_SIZE) % 2)) ? lv_color_hex(0xFFFFFF) : lv_color_hex(0x000000);
lv_obj_t* cell = lv_obj_create(checkerboard);
if (cell == nullptr) {
ESP_LOGE(TAG, "Failed to create LVGL checkerboard cell");
lvgl_port_unlock();
continue;
}
lv_obj_set_size(cell, CELL_SIZE, CELL_SIZE);
lv_obj_set_style_bg_color(cell, color, 0);
lv_obj_set_pos(cell, x, y);
// remove border and padding
lv_obj_set_style_pad_all(cell, 0, 0);
lv_obj_set_style_border_width(cell, 0, 0);
lv_obj_t* label = lv_label_create(cell);
if (label != nullptr) {
lv_label_set_text_fmt(label, "(%d,%d)", x, y);
lv_obj_center(label);
}
}
lvgl_port_unlock();
// Yield to allow LVGL to process rendering
vTaskDelay(5000 / portTICK_PERIOD_MS);
}
ESP_LOGI(TAG, "LVGL Checkerboard pattern displayed successfully.");
lvgl_port_unlock();
delete params;
vTaskDelete(NULL);
};
@@ -251,19 +282,18 @@ void app_main(void) {
// NetworkHandler* network_handler = new NetworkHandler(std::move(wifi_handler));
EInkDisplayHandler* display_handler = new EInkDisplayHandler();
// Initialize display and touch
display_handler->init_devices(system_event_group);
// display_handler->init_devices();
display_handler->clear_display();
// display_handler->init_devices(system_event_group);
display_handler->init_devices();
ESP_LOGI(TAG, "E-Ink display handler initialized.\n");
// LVGL Handler
// std::unique_ptr<EInkDisplayHandler> display_uptr(display_handler);
// LVGLHandler lvgl_handler(std::move(display_uptr));
// esp_err_t err = lvgl_handler.initLVGL(system_event_group);
// if (err != ESP_OK) {
// ESP_LOGE(TAG, "Failed to initialize LVGL handler: %s", esp_err_to_name(err));
// vTaskDelay(5000 / portTICK_PERIOD_MS);
// return esp_restart();
// }
std::unique_ptr<EInkDisplayHandler> display_uptr(display_handler);
LVGLHandler lvgl_handler(std::move(display_uptr));
esp_err_t err = lvgl_handler.initLVGL(system_event_group);
if (err != ESP_OK) {
ESP_LOGE(TAG, "Failed to initialize LVGL handler: %s", esp_err_to_name(err));
vTaskDelay(5000 / portTICK_PERIOD_MS);
return esp_restart();
}
//
// kv_storage_handler->init(system_event_group);
@@ -282,9 +312,12 @@ void app_main(void) {
);
ESP_LOGI(TAG, "System is ready. Starting main application...\n");
// Allow LVGL system to stabilize before creating objects
vTaskDelay(pdMS_TO_TICKS(100));
// Show checkerboard pattern on display for testing
EInk_Checkerboard(display_handler);
// LVGL_Checkerboard(&lvgl_handler);
// EInk_Checkerboard(display_handler);
LVGL_Checkerboard(&lvgl_handler);
// Register apps with AppRegistry by creating their descriptors
// Each descriptor will create and register the app instance