From 2738bff96a7a0c86a73f93d668c885ce0394ebe0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kuba=20Szczodrzy=C5=84ski?= Date: Sat, 10 Feb 2024 12:11:37 +0100 Subject: [PATCH] Allow changing LVGL refresh and animation period --- src/hasp_config.h | 1 + src/hasp_gui.cpp | 35 +++++++++++++++++++++++++++++++++++ src/hasp_gui.h | 1 + 3 files changed, 37 insertions(+) diff --git a/src/hasp_config.h b/src/hasp_config.h index 04160d30..ca5429ae 100644 --- a/src/hasp_config.h +++ b/src/hasp_config.h @@ -90,6 +90,7 @@ const char FP_GUI_BACKLIGHTINVERT[] PROGMEM = "bcklinv"; const char FP_GUI_POINTER[] PROGMEM = "cursor"; const char FP_GUI_LONG_TIME[] PROGMEM = "long"; const char FP_GUI_REPEAT_TIME[] PROGMEM = "repeat"; +const char FP_GUI_FPS[] PROGMEM = "fps"; const char FP_DEBUG_TELEPERIOD[] PROGMEM = "tele"; const char FP_DEBUG_ANSI[] PROGMEM = "ansi"; const char FP_GPIO_CONFIG[] PROGMEM = "config"; diff --git a/src/hasp_gui.cpp b/src/hasp_gui.cpp index 9fd55c9b..5c39f590 100644 --- a/src/hasp_gui.cpp +++ b/src/hasp_gui.cpp @@ -57,6 +57,8 @@ 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 bool gui_initialized = false; +static uint32_t anim_fps_deferred = 0; static inline void gui_init_lvgl() { @@ -100,6 +102,27 @@ void gui_hide_pointer(bool hidden) if(cursor) lv_obj_set_hidden(cursor, hidden || !gui_settings.show_pointer); } +bool gui_set_fps(uint32_t fps) +{ + if(!gui_initialized) { + LOG_ERROR(TAG_GUI, F("GUI not initialized, deferring FPS setting")); + anim_fps_deferred = fps; + return false; + } + + bool changed = false; + uint32_t period = 1000 / fps; + // find animation task by its period + lv_task_t* task = NULL; + while(task = lv_task_get_next(task)) { + if(!(task->period == LV_DISP_DEF_REFR_PERIOD)) continue; + changed |= (task->period != period); + LOG_INFO(TAG_GUI, F("Changing animation period: %u -> %u (%u FPS)"), task->period, period, fps); + task->period = period; + } + return changed; +} + IRAM_ATTR void gui_flush_cb(lv_disp_drv_t* disp, const lv_area_t* area, lv_color_t* color_p) { haspTft.flush_pixels(disp, area, color_p); @@ -373,6 +396,13 @@ void guiSetup() } #endif // ESP32 && HASP_USE_ESP_MQTT + // apply deferred FPS setting + gui_initialized = true; + if(anim_fps_deferred != 0) { + gui_set_fps(anim_fps_deferred); + anim_fps_deferred = 0; + } + LOG_INFO(TAG_LVGL, F(D_SERVICE_STARTED)); } @@ -612,6 +642,11 @@ bool guiSetConfig(const JsonObject& settings) changed |= status; } + if(!settings[FPSTR(FP_GUI_FPS)].isNull()) { + uint32_t fps = settings[FPSTR(FP_GUI_FPS)].as(); + changed |= gui_set_fps(fps); + } + return changed; } #endif // HASP_USE_CONFIG diff --git a/src/hasp_gui.h b/src/hasp_gui.h index 8b5b12af..adb5ddb6 100644 --- a/src/hasp_gui.h +++ b/src/hasp_gui.h @@ -48,6 +48,7 @@ void guiEverySecond(void); void guiStart(void); void guiStop(void); void gui_hide_pointer(bool hidden); +bool gui_set_fps(uint32_t fps); /* ===== Special Event Processors ===== */ void guiCalibrate(void);