From d9a3c63530d38c0b49c65fd1f9406dc47b62b212 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 30 Jan 2026 15:09:22 +0000 Subject: [PATCH] Use Application::Schedule() for display updates in callbacks Instead of calling SetChatMessage directly from download/upgrade progress callbacks, queue the updates using Application::Schedule(). This prevents blocking the network receive task and avoids potential UART FIFO overflow issues with 4G modems. The scheduled callbacks execute in the main task thread, maintaining proper thread safety. Co-authored-by: 78 <4488133+78@users.noreply.github.com> --- main/application.cc | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/main/application.cc b/main/application.cc index a920378b..f9c95cb8 100644 --- a/main/application.cc +++ b/main/application.cc @@ -368,10 +368,12 @@ void Application::CheckAssetsVersion() { board.SetPowerSaveLevel(PowerSaveLevel::PERFORMANCE); display->SetChatMessage("system", Lang::Strings::PLEASE_WAIT); - bool success = assets.Download(download_url, [display](int progress, size_t speed) -> void { + bool success = assets.Download(download_url, [this, display](int progress, size_t speed) -> void { char buffer[32]; snprintf(buffer, sizeof(buffer), "%d%% %uKB/s", progress, speed / 1024); - display->SetChatMessage("system", buffer); + Schedule([display, message = std::string(buffer)]() { + display->SetChatMessage("system", message.c_str()); + }); }); board.SetPowerSaveLevel(PowerSaveLevel::LOW_POWER); @@ -919,10 +921,12 @@ bool Application::UpgradeFirmware(const std::string& url, const std::string& ver audio_service_.Stop(); vTaskDelay(pdMS_TO_TICKS(1000)); - bool upgrade_success = Ota::Upgrade(upgrade_url, [display](int progress, size_t speed) { + bool upgrade_success = Ota::Upgrade(upgrade_url, [this, display](int progress, size_t speed) { char buffer[32]; snprintf(buffer, sizeof(buffer), "%d%% %uKB/s", progress, speed / 1024); - display->SetChatMessage("system", buffer); + Schedule([display, message = std::string(buffer)]() { + display->SetChatMessage("system", message.c_str()); + }); }); if (!upgrade_success) {