refactor: improve watchdog handling and screen loading in UI and display handlers
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
#include "common/constants.h"
|
||||
#include "esp_log.h"
|
||||
#include "esp_heap_caps.h"
|
||||
#include "esp_task_wdt.h"
|
||||
#include <cstring>
|
||||
|
||||
#define TAG "EInkDisplayHandler"
|
||||
@@ -382,10 +383,10 @@ void EInkDisplayHandler::_perform_full_refresh(const uint8_t* framebuffer) {
|
||||
break;
|
||||
}
|
||||
|
||||
// Yield every 1000 bytes to prevent watchdog timeout
|
||||
if (i % 1000 == 999) {
|
||||
// Yield every 100 bytes to prevent watchdog timeout
|
||||
if (i % 100 == 99) {
|
||||
xSemaphoreGive(_spi_mutex);
|
||||
vTaskDelay(pdMS_TO_TICKS(1)); // Small delay
|
||||
vTaskDelay(pdMS_TO_TICKS(5)); // Increased delay for better yielding
|
||||
if (xSemaphoreTake(_spi_mutex, pdMS_TO_TICKS(5000)) != pdTRUE) {
|
||||
ESP_LOGE(TAG, "SPI mutex timeout during yield at byte %zu", i);
|
||||
return;
|
||||
@@ -501,6 +502,7 @@ void EInkDisplayHandler::_wait_for_busy() {
|
||||
int timeout = 0;
|
||||
while (gpio_get_level(PIN_BUSY) == BUSY_ACTIVE_LEVEL) { // 0=BUSY, 1=FREE
|
||||
vTaskDelay(pdMS_TO_TICKS(100));
|
||||
esp_task_wdt_reset(); // Feed the watchdog during long wait
|
||||
timeout++;
|
||||
if (timeout > 100) { // 10 second timeout
|
||||
ESP_LOGE(TAG, "Display BUSY timeout! Pin level: %d", gpio_get_level(PIN_BUSY));
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include "ui/root_layout.h"
|
||||
#include "ui/app_registry.h"
|
||||
#include "esp_log.h"
|
||||
#include "lvgl.h"
|
||||
|
||||
#define TAG "UIHandler"
|
||||
|
||||
@@ -45,8 +46,14 @@ esp_err_t UIHandler::init(void) {
|
||||
ESP_LOGW(TAG, "Failed to render app icons");
|
||||
}
|
||||
|
||||
// Load the main screen
|
||||
lv_screen_load(_main_screen);
|
||||
// Defer screen loading to prevent blocking during initialization
|
||||
// Use LVGL timer to load screen after allowing watchdog reset
|
||||
lv_timer_create([](lv_timer_t* timer) {
|
||||
lv_obj_t* screen = static_cast<lv_obj_t*>(lv_timer_get_user_data(timer));
|
||||
ESP_LOGI("UIHandler", "Loading main screen via timer");
|
||||
lv_screen_load(screen);
|
||||
lv_timer_del(timer);
|
||||
}, 100, _main_screen); // 100ms delay to allow watchdog reset
|
||||
|
||||
ESP_LOGI(TAG, "UIHandler initialized successfully");
|
||||
return ESP_OK;
|
||||
|
||||
Reference in New Issue
Block a user