process order fix

This commit is contained in:
2026-02-16 22:00:23 +09:00
parent 5ae0c64ba9
commit 3b4d61c56d
3 changed files with 28 additions and 1 deletions

View File

@@ -35,6 +35,7 @@ static uint8_t s_img_buf[STATUS_IMG_BYTES];
static lv_img_dsc_t s_img_dsc; static lv_img_dsc_t s_img_dsc;
static volatile bool s_img_pending = false; /* expecting binary frame with image data */ static volatile bool s_img_pending = false; /* expecting binary frame with image data */
static volatile bool s_img_updated = false; /* new image ready for UI consumption */ static volatile bool s_img_updated = false; /* new image ready for UI consumption */
static volatile bool s_need_request_image = false; /* deferred image request on connect */
static TaskHandle_t s_img_notify_task = NULL; /* task to wake on new image */ static TaskHandle_t s_img_notify_task = NULL; /* task to wake on new image */
/* Forward declarations */ /* Forward declarations */
@@ -158,7 +159,10 @@ static void ws_event_handler(void *arg, esp_event_base_t event_base,
ESP_LOGI(TAG, "Audio WS connected"); ESP_LOGI(TAG, "Audio WS connected");
s_state = AUDIO_CONNECTED; s_state = AUDIO_CONNECTED;
s_img_pending = false; s_img_pending = false;
esp_websocket_client_send_text(s_client, "{\"type\":\"request_image\"}", 23, pdMS_TO_TICKS(1000)); s_need_request_image = true;
if (s_img_notify_task) {
xTaskNotifyGive(s_img_notify_task);
}
break; break;
case WEBSOCKET_EVENT_DISCONNECTED: case WEBSOCKET_EVENT_DISCONNECTED:
@@ -286,3 +290,16 @@ void audio_client_ack_status_image(void)
{ {
s_img_updated = false; s_img_updated = false;
} }
bool audio_client_send_pending_request(void)
{
if (!s_need_request_image || !s_client) return false;
s_need_request_image = false;
int ret = esp_websocket_client_send_text(s_client, "{\"type\":\"request_image\"}", 23, pdMS_TO_TICKS(1000));
if (ret < 0) {
ESP_LOGE(TAG, "Failed to send image request: %d", ret);
return false;
}
ESP_LOGI(TAG, "Sent image request to server");
return true;
}

View File

@@ -51,6 +51,13 @@ const lv_img_dsc_t *audio_client_get_status_image(bool *updated);
*/ */
void audio_client_ack_status_image(void); void audio_client_ack_status_image(void);
/**
* Send any pending image request to the server.
* Call from a task context (not from an event handler).
* @return true if a request was sent, false if none pending or send failed.
*/
bool audio_client_send_pending_request(void);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@@ -194,6 +194,9 @@ static void sensor_task(void *arg)
*/ */
ulTaskNotifyTake(pdTRUE, pdMS_TO_TICKS(1000)); ulTaskNotifyTake(pdTRUE, pdMS_TO_TICKS(1000));
/* Send deferred image request if connect just happened */
audio_client_send_pending_request();
/* Check for status image updates immediately */ /* Check for status image updates immediately */
bool img_updated = false; bool img_updated = false;
const lv_img_dsc_t *img = audio_client_get_status_image(&img_updated); const lv_img_dsc_t *img = audio_client_get_status_image(&img_updated);