new client connection logic
- esp32 requests for image when ready to receive - server serves initial image on request
This commit is contained in:
@@ -157,11 +157,14 @@ static void ws_event_handler(void *arg, esp_event_base_t event_base,
|
||||
case WEBSOCKET_EVENT_CONNECTED:
|
||||
ESP_LOGI(TAG, "Audio WS connected");
|
||||
s_state = AUDIO_CONNECTED;
|
||||
s_img_pending = false;
|
||||
esp_websocket_client_send_text(s_client, "{\"type\":\"request_image\"}", 23, pdMS_TO_TICKS(1000));
|
||||
break;
|
||||
|
||||
case WEBSOCKET_EVENT_DISCONNECTED:
|
||||
ESP_LOGW(TAG, "Audio WS disconnected");
|
||||
s_playing = false;
|
||||
s_img_pending = false;
|
||||
flush_queue();
|
||||
s_state = AUDIO_IDLE;
|
||||
break;
|
||||
@@ -275,9 +278,11 @@ const lv_img_dsc_t *audio_client_get_status_image(bool *updated)
|
||||
{
|
||||
if (updated) {
|
||||
*updated = s_img_updated;
|
||||
if (s_img_updated) {
|
||||
s_img_updated = false;
|
||||
}
|
||||
}
|
||||
return &s_img_dsc;
|
||||
}
|
||||
|
||||
void audio_client_ack_status_image(void)
|
||||
{
|
||||
s_img_updated = false;
|
||||
}
|
||||
|
||||
@@ -40,11 +40,17 @@ void audio_client_set_image_notify_task(TaskHandle_t task);
|
||||
|
||||
/**
|
||||
* Get the latest status image descriptor.
|
||||
* @param updated Set to true if a new image arrived since last call, then reset.
|
||||
* @param updated Set to true if a new image arrived since last call.
|
||||
* @return Pointer to the static image descriptor (always valid).
|
||||
*/
|
||||
const lv_img_dsc_t *audio_client_get_status_image(bool *updated);
|
||||
|
||||
/**
|
||||
* Acknowledge that the status image was successfully rendered.
|
||||
* Clears the updated flag so subsequent get_status_image calls return false.
|
||||
*/
|
||||
void audio_client_ack_status_image(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -200,6 +200,7 @@ static void sensor_task(void *arg)
|
||||
if (img_updated && Lvgl_lock(100)) {
|
||||
dashboard_ui_update_status_image(img);
|
||||
Lvgl_unlock();
|
||||
audio_client_ack_status_image();
|
||||
}
|
||||
|
||||
/* Sensor + clock updates at ~1s cadence (skip if woken early) */
|
||||
|
||||
Reference in New Issue
Block a user