From 180326f8433bfbb1d968610d3abf173ea106688a Mon Sep 17 00:00:00 2001 From: fvanroie Date: Mon, 10 Oct 2022 15:33:48 +0200 Subject: [PATCH] Prevent screen updates during antiburn #389 --- src/hasp/hasp.cpp | 27 +++++++++++++++++++++------ src/hasp_gui.cpp | 47 ++++++++++++++++++++++++++++++++--------------- src/hasp_gui.h | 4 ++++ 3 files changed, 57 insertions(+), 21 deletions(-) diff --git a/src/hasp/hasp.cpp b/src/hasp/hasp.cpp index 06bbc40b..0b9309db 100644 --- a/src/hasp/hasp.cpp +++ b/src/hasp/hasp.cpp @@ -186,10 +186,15 @@ static lv_task_t* antiburn_task; bool hasp_stop_antiburn() { - bool changed = false; - lv_obj_t* layer = lv_disp_get_layer_sys(NULL); + bool changed = false; + /* Refresh screen to flush callback */ + lv_disp_t* disp = lv_disp_get_default(); + disp->driver.flush_cb = gui_flush_cb; + + // lv_obj_t* layer = lv_disp_get_layer_sys(NULL); // if(layer) lv_obj_set_style_local_bg_opa(layer, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, LV_OPA_TRANSP); + if(antiburn_task) { lv_task_del(antiburn_task); lv_obj_invalidate(lv_scr_act()); @@ -197,8 +202,8 @@ bool hasp_stop_antiburn() } antiburn_task = NULL; hasp_set_wakeup_touch(haspDevice.get_backlight_power() == false); // enabled if backlight is OFF - gui_hide_pointer(false); + // gui_hide_pointer(false); return changed; } @@ -208,7 +213,6 @@ void hasp_antiburn_cb(lv_task_t* task) if(layer) { // lv_color_t color[5] = {LV_COLOR_BLACK, LV_COLOR_WHITE, LV_COLOR_RED, LV_COLOR_LIME, LV_COLOR_BLUE}; // lv_obj_set_style_local_bg_color(layer, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, color[task->repeat_count % 5]); - // lv_obj_set_style_local_bg_opa(layer, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, LV_OPA_COVER); lv_disp_t* disp = lv_disp_get_default(); lv_disp_drv_t* disp_drv = &disp->driver; lv_area_t area; @@ -231,6 +235,9 @@ void hasp_antiburn_cb(lv_task_t* task) if(task->repeat_count != 1) return; // don't stop yet } + // lv_obj_invalidate(lv_scr_act()); + if(task->repeat_count != 1) return; // don't stop yet + // task is about to get deleted hasp_stop_antiburn(); dispatch_state_antiburn(HASP_EVENT_OFF); @@ -245,13 +252,21 @@ void hasp_set_antiburn(int32_t repeat_count, uint32_t period) lv_obj_t* layer = lv_disp_get_layer_sys(NULL); if(!layer) return; - if(!antiburn_task) antiburn_task = lv_task_create(hasp_antiburn_cb, period, LV_TASK_PRIO_LOWEST, NULL); + if(!antiburn_task) antiburn_task = lv_task_create(hasp_antiburn_cb, period, LV_TASK_PRIO_LOW, NULL); if(antiburn_task) { + // lv_obj_set_style_local_bg_color(layer, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_BLACK); + // lv_obj_set_style_local_bg_opa(layer, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, LV_OPA_COVER); lv_obj_set_event_cb(layer, first_touch_event_handler); lv_obj_set_click(layer, true); lv_task_set_repeat_count(antiburn_task, repeat_count); lv_task_set_period(antiburn_task, period); - gui_hide_pointer(true); + // gui_hide_pointer(true); + + /* Refresh screen to antiburn callback */ + lv_disp_t* disp = lv_disp_get_default(); + disp->driver.flush_cb = gui_antiburn_cb; + lv_obj_invalidate(lv_scr_act()); + } else { LOG_INFO(TAG_HASP, F("Antiburn %s"), D_INFO_FAILED); } diff --git a/src/hasp_gui.cpp b/src/hasp_gui.cpp index 59c10dde..0c9745f0 100644 --- a/src/hasp_gui.cpp +++ b/src/hasp_gui.cpp @@ -50,10 +50,10 @@ uint16_t tft_height = TFT_HEIGHT; bool screenshotIsDirty = true; uint32_t screenshotEtag = 0; +void (*drv_display_flush_cb)(struct _disp_drv_t* disp_drv, const lv_area_t* area, lv_color_t* color_p); static lv_disp_buf_t disp_buf; - static inline void gui_init_lvgl() { LOG_VERBOSE(TAG_LVGL, F("Version : %u.%u.%u %s"), LVGL_VERSION_MAJOR, LVGL_VERSION_MINOR, LVGL_VERSION_PATCH, @@ -141,6 +141,27 @@ IRAM_ATTR void gui_flush_cb(lv_disp_drv_t* disp, const lv_area_t* area, lv_color screenshotIsDirty = true; } +void gui_antiburn_cb(lv_disp_drv_t* disp, const lv_area_t* area, lv_color_t* color_p) +{ + /* uint32_t w = (area->x2 - area->x1 + 1); + uint32_t h = (area->y2 - area->y1 + 1); + uint32_t len = w * h; + + lv_color_t dots[w]; + lv_area_t line = *area; + + for(lv_coord_t y = 0; y < h; y++) { + for(lv_coord_t x = 0; x < w; x++) { + dots[x].full = HASP_RANDOM(UINT16_MAX); + } + line.y1 = area->y1 + y; + line.y2 = line.y1; + haspTft.flush_pixels(disp, &line, dots); + } */ + /* Tell lvgl that flushing is done */ + lv_disp_flush_ready(disp); +} + IRAM_ATTR void gui_monitor_cb(lv_disp_drv_t* disp_drv, uint32_t time, uint32_t px) { // if(screenshotIsDirty) return; @@ -602,8 +623,7 @@ static void gui_screenshot_to_file(lv_disp_drv_t* disp, const lv_area_t* area, l if(res != len) gui_flush_not_complete(); // indirect callback to flush screenshot data to the screen - // drv_display_flush_cb(disp, area, color_p); - haspTft.flush_pixels(disp, area, color_p); + drv_display_flush_cb(disp, area, color_p); } /** Take Screenshot. @@ -628,14 +648,13 @@ void guiTakeScreenshot(const char* pFileName) LOG_VERBOSE(TAG_GUI, F("Bitmap header written")); /* Refresh screen to screenshot callback */ - lv_disp_t* disp = lv_disp_get_default(); - void (*flush_cb)(struct _disp_drv_t * disp_drv, const lv_area_t* area, lv_color_t* color_p); - flush_cb = disp->driver.flush_cb; /* store callback */ + lv_disp_t* disp = lv_disp_get_default(); + drv_display_flush_cb = disp->driver.flush_cb; /* store callback */ disp->driver.flush_cb = gui_screenshot_to_file; lv_obj_invalidate(lv_scr_act()); - lv_refr_now(NULL); /* Will call our disp_drv.disp_flush function */ - disp->driver.flush_cb = flush_cb; /* restore callback */ + lv_refr_now(NULL); /* Will call our disp_drv.disp_flush function */ + disp->driver.flush_cb = drv_display_flush_cb; /* restore callback */ LOG_VERBOSE(TAG_GUI, F("Bitmap data flushed to %s"), pFileName); @@ -660,8 +679,7 @@ static void gui_screenshot_to_http(lv_disp_drv_t* disp, const lv_area_t* area, l if(res != len) gui_flush_not_complete(); // indirect callback to flush screenshot data to the screen - // drv_display_flush_cb(disp, area, color_p); - haspTft.flush_pixels(disp, area, color_p); + drv_display_flush_cb(disp, area, color_p); } /** Take Screenshot. @@ -680,13 +698,12 @@ void guiTakeScreenshot() LOG_VERBOSE(TAG_GUI, F("Bitmap header sent")); /* Refresh screen to screenshot callback */ - lv_disp_t* disp = lv_disp_get_default(); - void (*flush_cb)(struct _disp_drv_t * disp_drv, const lv_area_t* area, lv_color_t* color_p); - flush_cb = disp->driver.flush_cb; /* store callback */ + lv_disp_t* disp = lv_disp_get_default(); + drv_display_flush_cb = disp->driver.flush_cb; /* store callback */ disp->driver.flush_cb = gui_screenshot_to_http; lv_obj_invalidate(lv_scr_act()); - lv_refr_now(NULL); /* Will call our disp_drv.disp_flush function */ - disp->driver.flush_cb = flush_cb; /* restore callback */ + lv_refr_now(NULL); /* Will call our disp_drv.disp_flush function */ + disp->driver.flush_cb = drv_display_flush_cb; /* restore callback */ screenshotIsDirty = false; LOG_VERBOSE(TAG_GUI, F("Bitmap data flushed to webclient")); diff --git a/src/hasp_gui.h b/src/hasp_gui.h index cb98f527..446e0169 100644 --- a/src/hasp_gui.h +++ b/src/hasp_gui.h @@ -56,6 +56,10 @@ void guiTakeScreenshot(void); // webclient bool guiScreenshotIsDirty(); uint32_t guiScreenshotEtag(); +/* ===== Callbacks ===== */ +void gui_flush_cb(lv_disp_drv_t* disp, const lv_area_t* area, lv_color_t* color_p); +void gui_antiburn_cb(lv_disp_drv_t* disp, const lv_area_t* area, lv_color_t* color_p); + /* ===== Read/Write Configuration ===== */ #if HASP_USE_CONFIG > 0 bool guiGetConfig(const JsonObject& settings);