diff --git a/main/display.c b/main/display.c index 54428517d..488eec089 100644 --- a/main/display.c +++ b/main/display.c @@ -24,13 +24,23 @@ #define LCD_CMD_BITS 8 #define LCD_PARAM_BITS 8 +#define DISPLAY_TIMEOUT_UPDATE_MS 60000 + static const char * TAG = "display"; +static esp_lcd_panel_handle_t panel_handle = NULL; +lv_timer_t * display_timeout_timer = NULL; +static bool display_state_on = false; +static uint16_t display_timeout_counter = 0; + static lv_theme_t theme; static lv_style_t scr_style; extern const lv_font_t lv_font_portfolio_6x8; +esp_err_t display_on(void); +esp_err_t display_off(void); + static void theme_apply(lv_theme_t *theme, lv_obj_t *obj) { if (lv_obj_get_parent(obj) == NULL) { lv_obj_add_style(obj, &scr_style, LV_PART_MAIN); @@ -61,7 +71,6 @@ esp_err_t display_init(void * pvParameters) ESP_RETURN_ON_ERROR(esp_lcd_new_panel_io_i2c(i2c_master_bus_handle, &io_config, &io_handle), TAG, "Failed to initialise i2c panel bus"); ESP_LOGI(TAG, "Install SSD1306 panel driver"); - esp_lcd_panel_handle_t panel_handle = NULL; esp_lcd_panel_dev_config_t panel_config = { .bits_per_pixel = 1, .reset_gpio_num = -1, @@ -122,7 +131,10 @@ esp_err_t display_init(void * pvParameters) if (esp_lcd_panel_init_err == ESP_OK) { // Only turn on the screen when it has been cleared - ESP_RETURN_ON_ERROR(esp_lcd_panel_disp_on_off(panel_handle, true), TAG, "Panel display on failed"); + esp_err_t esp_err = display_on(); + if (ESP_OK != esp_err) { + return esp_err; + } GLOBAL_STATE->SYSTEM_MODULE.is_screen_active = true; } else { @@ -131,3 +143,53 @@ esp_err_t display_init(void * pvParameters) return ESP_OK; } + +static void display_timeout_cb(lv_timer_t * timer) +{ + const uint16_t display_timeout_config = nvs_config_get_u16(NVS_CONFIG_DISPLAY_TIMEOUT, 0); + + if (0 < display_timeout_config) { + if (display_timeout_config <= display_timeout_counter) { + display_off(); + } else { + display_timeout_counter++; + } + } else { + display_on(); + } +} + +esp_err_t display_timeout_start(void * pvParameters) +{ + GlobalState * GLOBAL_STATE = (GlobalState *) pvParameters; + + if (GLOBAL_STATE->SYSTEM_MODULE.is_screen_active) { + display_timeout_timer = lv_timer_create(display_timeout_cb, DISPLAY_TIMEOUT_UPDATE_MS, NULL); + } + + return ESP_OK; +} + +esp_err_t display_on(void) +{ + if (!display_state_on && (NULL != panel_handle)) { + ESP_RETURN_ON_ERROR(esp_lcd_panel_disp_on_off(panel_handle, true), TAG, "Panel display on failed"); + display_state_on = true; + display_timeout_counter = 0; + if (NULL != display_timeout_timer) { + lv_timer_reset(display_timeout_timer); + } + } + + return ESP_OK; +} + +esp_err_t display_off(void) +{ + if (display_state_on && (NULL != panel_handle)) { + ESP_RETURN_ON_ERROR(esp_lcd_panel_disp_on_off(panel_handle, false), TAG, "Panel display off failed"); + display_state_on = false; + } + + return ESP_OK; +} diff --git a/main/display.h b/main/display.h index 9cdc5e97d..5c885d563 100644 --- a/main/display.h +++ b/main/display.h @@ -2,5 +2,8 @@ #define DISPLAY_H_ esp_err_t display_init(void * pvParameters); +esp_err_t display_timeout_start(void * pvParameters); +esp_err_t display_on(void); +esp_err_t display_off(void); #endif /* DISPLAY_H_ */ diff --git a/main/http_server/axe-os/src/app/components/edit/edit.component.html b/main/http_server/axe-os/src/app/components/edit/edit.component.html index 8211d66cb..6a5477058 100644 --- a/main/http_server/axe-os/src/app/components/edit/edit.component.html +++ b/main/http_server/axe-os/src/app/components/edit/edit.component.html @@ -163,6 +163,15 @@ +
+ +
+ + +
+
+
valueint); } + if ((item = cJSON_GetObjectItem(root, "displayTimeout")) != NULL) { + nvs_config_set_u16(NVS_CONFIG_DISPLAY_TIMEOUT, item->valueint); + } if ((item = cJSON_GetObjectItem(root, "invertfanpolarity")) != NULL) { nvs_config_set_u16(NVS_CONFIG_INVERT_FAN_POLARITY, item->valueint); } @@ -427,6 +430,7 @@ static esp_err_t GET_system_info(httpd_req_t * req) cJSON_AddNumberToObject(root, "flipscreen", nvs_config_get_u16(NVS_CONFIG_FLIP_SCREEN, 1)); cJSON_AddNumberToObject(root, "overheat_mode", nvs_config_get_u16(NVS_CONFIG_OVERHEAT_MODE, 0)); cJSON_AddNumberToObject(root, "invertscreen", nvs_config_get_u16(NVS_CONFIG_INVERT_SCREEN, 0)); + cJSON_AddNumberToObject(root, "displayTimeout", nvs_config_get_u16(NVS_CONFIG_DISPLAY_TIMEOUT, 0)); cJSON_AddNumberToObject(root, "invertfanpolarity", nvs_config_get_u16(NVS_CONFIG_INVERT_FAN_POLARITY, 1)); cJSON_AddNumberToObject(root, "autofanspeed", nvs_config_get_u16(NVS_CONFIG_AUTO_FAN_SPEED, 1)); diff --git a/main/input.c b/main/input.c index bcbb912be..7f5a4a34c 100644 --- a/main/input.c +++ b/main/input.c @@ -5,6 +5,8 @@ #include "esp_lvgl_port.h" #include "driver/gpio.h" +#include "display.h" + #define BUTTON_BOOT_GPIO GPIO_NUM_0 #define ESP_INTR_FLAG_DEFAULT 0 #define LONG_PRESS_DURATION_MS 2000 @@ -31,6 +33,7 @@ static void IRAM_ATTR button_isr_handler(void *arg) static void button_short_clicked_event_cb(lv_event_t *e) { ESP_LOGI(TAG, "Short button click detected"); + display_on(); button_short_clicked_fn(); } diff --git a/main/nvs_config.h b/main/nvs_config.h index bf8e3ad08..aed8fd144 100644 --- a/main/nvs_config.h +++ b/main/nvs_config.h @@ -23,6 +23,7 @@ #define NVS_CONFIG_BOARD_VERSION "boardversion" #define NVS_CONFIG_FLIP_SCREEN "flipscreen" #define NVS_CONFIG_INVERT_SCREEN "invertscreen" +#define NVS_CONFIG_DISPLAY_TIMEOUT "displayTimeout" #define NVS_CONFIG_INVERT_FAN_POLARITY "invertfanpol" #define NVS_CONFIG_AUTO_FAN_SPEED "autofanspeed" #define NVS_CONFIG_FAN_SPEED "fanspeed" diff --git a/main/system.c b/main/system.c index f80a38572..96e91f724 100644 --- a/main/system.c +++ b/main/system.c @@ -152,6 +152,10 @@ void SYSTEM_init_peripherals(GlobalState * GLOBAL_STATE) { ESP_LOGW(TAG, "Screen init failed"); } + if (display_timeout_start(GLOBAL_STATE) != ESP_OK) { + ESP_LOGW(TAG, "Display timeout init failed"); + } + netif = esp_netif_get_handle_from_ifkey("WIFI_STA_DEF"); }