esp32 improvements

- better clock seconds
- better alarm (image before audio, supposedly)
This commit is contained in:
Mikkeli Matlock
2026-02-15 22:55:53 +09:00
parent 0b2f274719
commit d63322d304
3 changed files with 48 additions and 16 deletions

View File

@@ -82,11 +82,13 @@ void UserApp_TaskInit(void)
/* Start WebSocket client */
ws_client_start();
/* Start audio streaming client */
audio_client_start();
/* Sensor polling task - Core 1, 4KB stack */
xTaskCreatePinnedToCore(sensor_task, "sensor", 4 * 1024, NULL, 3, NULL, 1);
TaskHandle_t sensor_handle = NULL;
xTaskCreatePinnedToCore(sensor_task, "sensor", 4 * 1024, NULL, 3, &sensor_handle, 1);
/* Start audio streaming client, notify sensor task on new images */
audio_client_set_image_notify_task(sensor_handle);
audio_client_start();
/* Button handling task - Core 1 */
xTaskCreatePinnedToCore(button_task, "button", 2 * 1024, NULL, 2, NULL, 1);
@@ -182,9 +184,32 @@ static void sensor_task(void *arg)
float temp = 0, humidity = 0;
rtcTimeStruct_t rtc_time = {};
int sensor_divider = 0;
TickType_t last_sensor_tick = xTaskGetTickCount();
for (;;) {
/* Read RTC every second */
/*
* Sleep until either:
* - a new status image arrives (xTaskNotifyGive from audio_client), or
* - 1 second elapses (clock refresh cadence)
*/
ulTaskNotifyTake(pdTRUE, pdMS_TO_TICKS(1000));
/* Check for status image updates immediately */
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();
}
/* Sensor + clock updates at ~1s cadence (skip if woken early) */
TickType_t now = xTaskGetTickCount();
if ((now - last_sensor_tick) < pdMS_TO_TICKS(900)) {
continue;
}
last_sensor_tick = now;
/* Read RTC */
Rtc_GetTime(&rtc_time);
/* Read SHTC3 + battery every 5 seconds */
@@ -203,23 +228,13 @@ static void sensor_task(void *arg)
}
sensor_divider = (sensor_divider + 1) % 5;
/* Update clock every second */
/* Update clock */
if (Lvgl_lock(100)) {
dashboard_ui_update_time(rtc_time.hour, rtc_time.minute, rtc_time.second,
rtc_time.year, rtc_time.month, rtc_time.day,
rtc_time.week);
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));
}
}