image alarm
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
idf_component_register(
|
||||
SRCS "audio_client.cpp"
|
||||
REQUIRES espressif__esp_websocket_client port_bsp codec_board
|
||||
REQUIRES espressif__esp_websocket_client port_bsp codec_board lvgl__lvgl
|
||||
PRIV_REQUIRES esp_event json
|
||||
INCLUDE_DIRS "./")
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdbool.h>
|
||||
#include "lvgl.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@@ -29,6 +30,13 @@ void audio_client_stop(void);
|
||||
/** Get current audio client state. */
|
||||
audio_state_t audio_client_get_state(void);
|
||||
|
||||
/**
|
||||
* Get the latest status image descriptor.
|
||||
* @param updated Set to true if a new image arrived since last call, then reset.
|
||||
* @return Pointer to the static image descriptor (always valid).
|
||||
*/
|
||||
const lv_img_dsc_t *audio_client_get_status_image(bool *updated);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -39,11 +39,13 @@ static lv_obj_t *lbl_cpu_temp;
|
||||
static lv_obj_t *tbl_services;
|
||||
static int s_service_count;
|
||||
|
||||
/* Local sensors */
|
||||
static lv_obj_t *lbl_room_temp;
|
||||
static lv_obj_t *lbl_room_humi;
|
||||
/* Local sensors (bottom bar) */
|
||||
static lv_obj_t *lbl_local;
|
||||
static lv_obj_t *lbl_uptime;
|
||||
|
||||
/* Status image placeholder */
|
||||
static lv_obj_t *img_status;
|
||||
|
||||
/* Network */
|
||||
static lv_obj_t *lbl_net;
|
||||
|
||||
@@ -267,11 +269,10 @@ static void create_main_section(lv_obj_t *parent)
|
||||
ry += row_h;
|
||||
lbl_uptime = create_label(parent, rx + 4, ry, &InziuIosevka_Slab_CC_12px, "Uptime: --h");
|
||||
|
||||
/* === Local Sensors (below pi vitals) === */
|
||||
int sy = ry + row_h + 4;
|
||||
create_label(parent, rx + 4, sy, &InziuIosevka_Slab_CC_12px, "LOCAL SENSORS");
|
||||
lbl_room_temp = create_label(parent, rx + 4, sy + 16, &InziuIosevka_Slab_CC_16px, "Room: --.-C");
|
||||
lbl_room_humi = create_label(parent, rx + 4, sy + 42, &InziuIosevka_Slab_CC_16px, "Humi: --%");
|
||||
/* === Status image (120x120, bottom-right above bot bar) === */
|
||||
img_status = lv_img_create(parent);
|
||||
lv_obj_set_pos(img_status, 280, 156);
|
||||
lv_obj_set_size(img_status, 120, 120);
|
||||
}
|
||||
|
||||
static void create_bottom_bar(lv_obj_t *parent)
|
||||
@@ -295,6 +296,13 @@ static void create_bottom_bar(lv_obj_t *parent)
|
||||
lv_obj_set_style_text_color(lbl_net, lv_color_black(), 0);
|
||||
lv_obj_align(lbl_net, LV_ALIGN_LEFT_MID, 0, 0);
|
||||
lv_label_set_text(lbl_net, "NETWORK RX: ---- kbps TX: ---- kbps");
|
||||
|
||||
/* Local sensor readings — right-aligned */
|
||||
lbl_local = lv_label_create(bot_cont);
|
||||
lv_obj_set_style_text_font(lbl_local, &InziuIosevka_Slab_CC_12px, 0);
|
||||
lv_obj_set_style_text_color(lbl_local, lv_color_black(), 0);
|
||||
lv_obj_align(lbl_local, LV_ALIGN_RIGHT_MID, 0, 0);
|
||||
lv_label_set_text(lbl_local, "T: --.- H: --%");
|
||||
}
|
||||
|
||||
void dashboard_ui_create(void)
|
||||
@@ -365,11 +373,8 @@ void dashboard_ui_update_local(float temp, float humidity, uint8_t battery)
|
||||
{
|
||||
char buf[32];
|
||||
|
||||
snprintf(buf, sizeof(buf), "Room: %.1fC", temp);
|
||||
lv_label_set_text(lbl_room_temp, buf);
|
||||
|
||||
snprintf(buf, sizeof(buf), "Humi: %.0f%%", humidity);
|
||||
lv_label_set_text(lbl_room_humi, buf);
|
||||
snprintf(buf, sizeof(buf), "T: %.1f H: %.0f%%", temp, humidity);
|
||||
lv_label_set_text(lbl_local, buf);
|
||||
|
||||
/* Update top bar battery text + bar */
|
||||
snprintf(buf, sizeof(buf), "%d%%", battery);
|
||||
@@ -406,3 +411,10 @@ void dashboard_ui_update_connection(ws_state_t ws_state, bool wifi_connected, co
|
||||
}
|
||||
lv_label_set_text(lbl_ws, ws_str);
|
||||
}
|
||||
|
||||
void dashboard_ui_update_status_image(const lv_img_dsc_t *dsc)
|
||||
{
|
||||
if (dsc) {
|
||||
lv_img_set_src(img_status, dsc);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,6 +35,12 @@ void dashboard_ui_update_time(int h, int m, int s, int year, int month, int day,
|
||||
*/
|
||||
void dashboard_ui_update_connection(ws_state_t ws_state, bool wifi_connected, const char *ip_str);
|
||||
|
||||
/**
|
||||
* Update the status image widget. LVGL lock must be held by caller.
|
||||
* @param dsc Image descriptor (1-bit monochrome, 120x120)
|
||||
*/
|
||||
void dashboard_ui_update_status_image(const lv_img_dsc_t *dsc);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -211,6 +211,14 @@ static void sensor_task(void *arg)
|
||||
Lvgl_unlock();
|
||||
}
|
||||
|
||||
/* Poll for status image updates */
|
||||
bool img_updated = false;
|
||||
const lv_img_dsc_t *img = audio_client_get_status_image(&img_updated);
|
||||
if (img_updated && Lvgl_lock(100)) {
|
||||
dashboard_ui_update_status_image(img);
|
||||
Lvgl_unlock();
|
||||
}
|
||||
|
||||
vTaskDelay(pdMS_TO_TICKS(1000));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user