Fix touch crash + make rain a reachability signal + calm the alarm churn
TOUCH CRASH (the blue screen): app_on_touch ran a blocking WebSocket send (up to 5s) directly in the LVGL touch callback, stalling the MIPI-DSI flush into a garbage/blue frame + task-watchdog reboot on every tap. Now touch_cb only gives a semaphore; a dedicated app_task does the blocking sends, audio, and face changes off the render thread. WS send timeout cut 5s to 1.5s as belt-and-braces. RAIN = REACHABILITY (user request): rain now falls only while the gateway WebSocket is live (gated on gw_connected in rain_tick). It drains gracefully on disconnect, resumes on reconnect, a genuine glanceable reachable signal. Idle density bumped 2 to 4 so connected-idle reads distinctly from disconnected-black. CALM THE WEDGE CHURN (user request): transient wifi/WS drops no longer slam to the x_x error face or a CONNECTING banner. Boot goes straight to the calm idle face (dry until connected). Only a sustained 30s+ outage escalates to x_x (clock_cb); the ~15s wedge-recovery just shows a brief rain pause. Two fixes from adversarial concurrency review before flashing: - persistent single capture task (was xTaskCreate per utterance; a rapid re-tap or WS-stop-vs-app-start race could put two readers on one mic/I2S handle and corrupt the codec) - reset s_talking on disconnect (app_on_disconnect) so the first tap after a mid-utterance drop starts fresh, not the stop branch Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -2,10 +2,18 @@
|
||||
*
|
||||
* Boot: display + face -> audio (gong) -> Wi-Fi (C6/ESP-Hosted) -> gateway WS.
|
||||
* Interaction (phase 2): touch-to-talk — tap to speak, tap again to finish.
|
||||
*
|
||||
* Touch is DECOUPLED from the LVGL thread: the touch callback only signals a
|
||||
* semaphore; all the real work (blocking WebSocket sends, audio, face changes)
|
||||
* runs in app_task. A blocking WS send on the LVGL render thread stalls the
|
||||
* MIPI-DSI flush -> blue/garbage frame + task-watchdog reboot.
|
||||
*/
|
||||
|
||||
#include "esp_log.h"
|
||||
#include "esp_system.h"
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/semphr.h"
|
||||
#include "freertos/task.h"
|
||||
#include "bsp/esp-bsp.h"
|
||||
|
||||
#include "desklock.h"
|
||||
@@ -15,13 +23,31 @@
|
||||
|
||||
static const char *TAG = "desklock";
|
||||
|
||||
static SemaphoreHandle_t s_touch_sem;
|
||||
static bool s_talking;
|
||||
|
||||
/* Called from the LVGL touch callback — MUST be fast and non-blocking. */
|
||||
void app_on_touch(void)
|
||||
{
|
||||
if (s_touch_sem != NULL) {
|
||||
xSemaphoreGive(s_touch_sem);
|
||||
}
|
||||
}
|
||||
|
||||
/* Called from the WS event task when the link drops: forget any half-utterance
|
||||
* so the next tap starts a fresh one instead of hitting the "stop" branch. */
|
||||
void app_on_disconnect(void)
|
||||
{
|
||||
s_talking = false;
|
||||
}
|
||||
|
||||
/* Runs in app_task (normal context): blocking sends here don't stall rendering. */
|
||||
static void handle_touch(void)
|
||||
{
|
||||
face_activity();
|
||||
|
||||
if (!gw_connected()) {
|
||||
s_talking = false; /* link gone; nothing to talk to */
|
||||
return;
|
||||
}
|
||||
if (!s_talking) {
|
||||
@@ -42,17 +68,29 @@ void app_on_touch(void)
|
||||
}
|
||||
}
|
||||
|
||||
static void app_task(void *arg)
|
||||
{
|
||||
(void)arg;
|
||||
for (;;) {
|
||||
if (xSemaphoreTake(s_touch_sem, portMAX_DELAY) == pdTRUE) {
|
||||
vTaskDelay(pdMS_TO_TICKS(60)); /* debounce */
|
||||
xSemaphoreTake(s_touch_sem, 0); /* coalesce repeats during debounce */
|
||||
handle_touch();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void app_on_playback_done(void)
|
||||
{
|
||||
#if !WIFI_DIAG_MODE
|
||||
face_set(FACE_IDLE); /* in diag mode the status line must stay visible */
|
||||
#endif
|
||||
face_set(FACE_IDLE);
|
||||
}
|
||||
|
||||
void app_main(void)
|
||||
{
|
||||
ESP_LOGI(TAG, "DeskLock starting");
|
||||
|
||||
s_touch_sem = xSemaphoreCreateBinary();
|
||||
|
||||
bsp_display_start();
|
||||
bsp_display_backlight_on();
|
||||
face_init();
|
||||
@@ -62,6 +100,8 @@ void app_main(void)
|
||||
audio_play_gong(); /* cold boot only — recovery reboots stay silent */
|
||||
}
|
||||
|
||||
xTaskCreate(app_task, "app", 4096, NULL, 5, NULL);
|
||||
|
||||
#if WIFI_DIAG_MODE
|
||||
wifi_diag_start();
|
||||
#else
|
||||
|
||||
Reference in New Issue
Block a user