mirror of
https://github.com/78/xiaozhi-esp32.git
synced 2026-02-11 06:33:48 +00:00
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>
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user