update display only necessary

This commit is contained in:
GW_MC
2026-02-02 21:17:39 +08:00
parent 1dff88ed1a
commit d0c9a7c4cc

View File

@@ -109,13 +109,21 @@ void MainUIHandler::on_status_update_(StatusUpdateEventData data) {
ESP_LOGI(TAG, "on_status_update_ called with state: %d", data.state); ESP_LOGI(TAG, "on_status_update_ called with state: %d", data.state);
// Update state in thread-safe manner // Update state in thread-safe manner
bool update_ui = false;
if (state_mutex_ && xSemaphoreTake(state_mutex_, pdMS_TO_TICKS(100)) == pdTRUE) { if (state_mutex_ && xSemaphoreTake(state_mutex_, pdMS_TO_TICKS(100)) == pdTRUE) {
if (data.state != current_state_) {
update_ui = true;
}
current_state_ = data.state; current_state_ = data.state;
xSemaphoreGive(state_mutex_); xSemaphoreGive(state_mutex_);
ESP_LOGI(TAG, "State updated in mutex"); ESP_LOGI(TAG, "State updated in mutex");
} }
// Update UI // Update UI
if (!update_ui) {
ESP_LOGI(TAG, "State unchanged, skipping UI update");
return;
}
ESP_LOGI(TAG, "Calling update_ui_()"); ESP_LOGI(TAG, "Calling update_ui_()");
update_ui_(); update_ui_();
ESP_LOGI(TAG, "on_status_update_ complete"); ESP_LOGI(TAG, "on_status_update_ complete");
@@ -127,6 +135,7 @@ void MainUIHandler::update_ui_() {
if (main_ui_) { if (main_ui_) {
StatusUpdateEventData::VoiceState state; StatusUpdateEventData::VoiceState state;
if (state_mutex_ && xSemaphoreTake(state_mutex_, pdMS_TO_TICKS(100)) == pdTRUE) { if (state_mutex_ && xSemaphoreTake(state_mutex_, pdMS_TO_TICKS(100)) == pdTRUE) {
state = current_state_; state = current_state_;
xSemaphoreGive(state_mutex_); xSemaphoreGive(state_mutex_);
} else { } else {