feat(ux): improve wifi, voice, and print feedback flows
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
#define VOICE_MIC_KEY_QUEUE_LEN 8
|
||||
#define VOICE_MIC_KEY_SESSION_READY_WAIT_MS 2000
|
||||
#define VOICE_MIC_KEY_SESSION_READY_POLL_MS 30
|
||||
#define VOICE_MIC_KEY_STATUS_PREVIEW_TIMEOUT_MS 3000
|
||||
|
||||
typedef enum {
|
||||
VOICE_MIC_KEY_CMD_PRESS_DOWN = 0,
|
||||
@@ -22,6 +23,26 @@ static TaskHandle_t s_mic_key_task;
|
||||
static bool s_mic_key_task_with_caps;
|
||||
static bool s_mic_key_ready;
|
||||
|
||||
static void voice_mic_key_show_status(const char *text) {
|
||||
if (text == NULL || text[0] == '\0') {
|
||||
return;
|
||||
}
|
||||
|
||||
char preview_err[96] = {0};
|
||||
esp_err_t preview_rc = screen_preview_show_text(text,
|
||||
VOICE_MIC_KEY_STATUS_PREVIEW_TIMEOUT_MS,
|
||||
preview_err,
|
||||
sizeof(preview_err));
|
||||
if (preview_rc == ESP_OK || preview_rc == ESP_ERR_NOT_SUPPORTED) {
|
||||
return;
|
||||
}
|
||||
|
||||
ESP_LOGW(TAG,
|
||||
"mic_key_status_preview_failed: rc=0x%x msg=%s",
|
||||
(unsigned)preview_rc,
|
||||
preview_err[0] != '\0' ? preview_err : "show text failed");
|
||||
}
|
||||
|
||||
static bool voice_mic_key_round_busy(const voice_interaction_status_t *voice,
|
||||
const printer_runtime_status_t *printer) {
|
||||
if (voice == NULL || printer == NULL) {
|
||||
@@ -56,6 +77,7 @@ static void voice_mic_key_handle_press_down(void) {
|
||||
|
||||
if (voice.tap_active) {
|
||||
ESP_LOGI(TAG, "MIC_KEY press ignored: tap already active");
|
||||
voice_mic_key_show_status("语音已在录制中");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -68,10 +90,12 @@ static void voice_mic_key_handle_press_down(void) {
|
||||
voice.marker_image_gen_running,
|
||||
printer.busy,
|
||||
printer.queue_depth);
|
||||
voice_mic_key_show_status("设备忙碌中\n请等待当前任务完成");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!voice_mic_key_session_ready(&voice)) {
|
||||
voice_mic_key_show_status("语音连接中...\n请稍候");
|
||||
char start_err[128] = {0};
|
||||
esp_err_t start_rc = voice_interaction_start_with_timeout(0, start_err, sizeof(start_err));
|
||||
if (start_rc != ESP_OK) {
|
||||
@@ -79,6 +103,7 @@ static void voice_mic_key_handle_press_down(void) {
|
||||
"MIC_KEY auto session start failed: %s (%s)",
|
||||
esp_err_to_name(start_rc),
|
||||
start_err[0] != '\0' ? start_err : "-");
|
||||
voice_mic_key_show_status("语音连接失败\n请稍后重试");
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -90,6 +115,7 @@ static void voice_mic_key_handle_press_down(void) {
|
||||
voice.session_active,
|
||||
voice.ws_connected,
|
||||
voice.started);
|
||||
voice_mic_key_show_status("语音服务暂不可用\n请稍后重试");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -100,9 +126,11 @@ static void voice_mic_key_handle_press_down(void) {
|
||||
"MIC_KEY tap start failed: %s (%s)",
|
||||
esp_err_to_name(tap_rc),
|
||||
tap_err[0] != '\0' ? tap_err : "-");
|
||||
voice_mic_key_show_status("开始录音失败\n请重试");
|
||||
return;
|
||||
}
|
||||
|
||||
voice_mic_key_show_status("请开始说话");
|
||||
ESP_LOGI(TAG, "MIC_KEY tap started");
|
||||
}
|
||||
|
||||
@@ -120,9 +148,11 @@ static void voice_mic_key_handle_press_up(void) {
|
||||
"MIC_KEY tap stop failed: %s (%s)",
|
||||
esp_err_to_name(tap_rc),
|
||||
tap_err[0] != '\0' ? tap_err : "-");
|
||||
voice_mic_key_show_status("结束录音失败\n请重试");
|
||||
return;
|
||||
}
|
||||
|
||||
voice_mic_key_show_status("已结束录音\n正在处理...");
|
||||
ESP_LOGI(TAG, "MIC_KEY tap stopped");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user