refactor: improve watchdog handling and screen loading in UI and display handlers

This commit is contained in:
GW_MC
2026-01-25 19:39:21 +08:00
parent 5865f6d383
commit f3dfc4f43f
2 changed files with 14 additions and 5 deletions

View File

@@ -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));