From c564d24cf10cafce64d5236c4297cb07fe38babb Mon Sep 17 00:00:00 2001 From: Xiaoxia Date: Sat, 25 Jan 2025 15:35:00 +0800 Subject: [PATCH] Fix UI condition racing (#110) * move display init code to board * fix ui condition race --- main/application.cc | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/main/application.cc b/main/application.cc index ec0498f2..a961835e 100644 --- a/main/application.cc +++ b/main/application.cc @@ -380,19 +380,25 @@ void Application::Start() { auto text = cJSON_GetObjectItem(root, "text"); if (text != NULL) { ESP_LOGI(TAG, "<< %s", text->valuestring); - display->SetChatMessage("assistant", text->valuestring); + Schedule([this, display, message = std::string(text->valuestring)]() { + display->SetChatMessage("assistant", message); + }); } } } else if (strcmp(type->valuestring, "stt") == 0) { auto text = cJSON_GetObjectItem(root, "text"); if (text != NULL) { ESP_LOGI(TAG, ">> %s", text->valuestring); - display->SetChatMessage("user", text->valuestring); + Schedule([this, display, message = std::string(text->valuestring)]() { + display->SetChatMessage("user", message); + }); } } else if (strcmp(type->valuestring, "llm") == 0) { auto emotion = cJSON_GetObjectItem(root, "emotion"); if (emotion != NULL) { - display->SetEmotion(emotion->valuestring); + Schedule([this, display, emotion_str = std::string(emotion->valuestring)]() { + display->SetEmotion(emotion_str); + }); } } else if (strcmp(type->valuestring, "iot") == 0) { auto commands = cJSON_GetObjectItem(root, "commands");