image alarm

This commit is contained in:
Mikkeli Matlock
2026-02-15 21:46:18 +09:00
parent 7eb05ea983
commit 33936650c6
9 changed files with 144 additions and 15 deletions

View File

@@ -18,6 +18,11 @@ static const char *TAG = "audio_client";
#define PLAYBACK_PRIORITY 4
#define WS_BUFFER_SIZE 8192
/* Status image constants */
#define STATUS_IMG_W 120
#define STATUS_IMG_H 120
#define STATUS_IMG_BYTES (STATUS_IMG_W * STATUS_IMG_H / 8) /* 1800 */
static esp_websocket_client_handle_t s_client = NULL;
static CodecPort *s_codec = NULL;
static QueueHandle_t s_pcm_queue = NULL;
@@ -25,6 +30,12 @@ static TaskHandle_t s_playback_task = NULL;
static volatile audio_state_t s_state = AUDIO_IDLE;
static volatile bool s_playing = false;
/* Status image state */
static uint8_t s_img_buf[STATUS_IMG_BYTES];
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_updated = false; /* new image ready for UI consumption */
/* Forward declarations */
static void playback_task(void *arg);
static void ws_event_handler(void *arg, esp_event_base_t event_base,
@@ -56,6 +67,13 @@ static void handle_text_frame(const char *data, int len)
return;
}
if (strcmp(type->valuestring, "status_image") == 0) {
ESP_LOGI(TAG, "Status image header received");
s_img_pending = true;
cJSON_Delete(root);
return;
}
if (strcmp(type->valuestring, "alarm_start") == 0) {
int sr = 24000;
int ch = 2;
@@ -98,6 +116,19 @@ static void handle_text_frame(const char *data, int len)
static void handle_binary_frame(const uint8_t *data, int len)
{
/* Status image binary payload */
if (s_img_pending) {
if (len == STATUS_IMG_BYTES) {
memcpy(s_img_buf, data, STATUS_IMG_BYTES);
s_img_updated = true;
ESP_LOGI(TAG, "Status image received (%d bytes)", len);
} else {
ESP_LOGW(TAG, "Status image size mismatch: got %d, expected %d", len, STATUS_IMG_BYTES);
}
s_img_pending = false;
return;
}
if (!s_playing) return;
uint8_t *chunk = (uint8_t *)heap_caps_malloc(len, MALLOC_CAP_SPIRAM);
@@ -172,6 +203,14 @@ void audio_client_init(const char *uri, void *codec)
{
s_codec = (CodecPort *)codec;
/* Initialize status image descriptor */
memset(&s_img_dsc, 0, sizeof(s_img_dsc));
s_img_dsc.header.cf = LV_IMG_CF_ALPHA_1BIT;
s_img_dsc.header.w = STATUS_IMG_W;
s_img_dsc.header.h = STATUS_IMG_H;
s_img_dsc.data_size = STATUS_IMG_BYTES;
s_img_dsc.data = s_img_buf;
s_pcm_queue = xQueueCreate(PCM_QUEUE_DEPTH, sizeof(uint8_t *));
if (!s_pcm_queue) {
ESP_LOGE(TAG, "Failed to create PCM queue");
@@ -222,3 +261,14 @@ audio_state_t audio_client_get_state(void)
{
return s_state;
}
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;
}