WS刚连接成功可以进行 对话,超过30sWS断开后,语音上行停止,需要修复
This commit is contained in:
@@ -24,6 +24,8 @@
|
||||
#define CONFIG_TQ_BOOT_SOUND_FILE ""
|
||||
#endif
|
||||
|
||||
#define CONTROL_PLANE_WIFI_SUCCESS_PROMPT_FILE "/littlefs/audio_prompts/network_connect_success.opus"
|
||||
|
||||
#define CONTROL_PLANE_STA_CONNECT_MAX_ATTEMPTS 3
|
||||
#define CONTROL_PLANE_STA_RETRY_BASE_DELAY_MS 300
|
||||
|
||||
@@ -79,8 +81,13 @@ static int control_plane_normalize_connect_timeout_ms(int timeout_ms, int min_ti
|
||||
static void control_plane_play_wifi_success_prompt(void)
|
||||
{
|
||||
bool played = false;
|
||||
esp_err_t audio_err = domain_runtime_multimodal_audio_init();
|
||||
if (audio_err != ESP_OK && audio_err != ESP_ERR_INVALID_STATE) {
|
||||
ESP_LOGW(TAG, "Prepare audio for Wi-Fi success prompt failed: %s", esp_err_to_name(audio_err));
|
||||
}
|
||||
played = (control_plane_wifi_play_prompt_file(CONTROL_PLANE_WIFI_SUCCESS_PROMPT_FILE) == ESP_OK);
|
||||
#ifdef CONFIG_VOICE_PROMPT_WIFI_SUCCESS_FILE
|
||||
if (CONFIG_VOICE_PROMPT_WIFI_SUCCESS_FILE[0] != '\0') {
|
||||
if (!played && CONFIG_VOICE_PROMPT_WIFI_SUCCESS_FILE[0] != '\0') {
|
||||
played = (control_plane_wifi_play_prompt_file(CONFIG_VOICE_PROMPT_WIFI_SUCCESS_FILE) == ESP_OK);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -94,6 +94,7 @@ typedef struct {
|
||||
int raw_level;
|
||||
bool debounced_pressed;
|
||||
bool debounce_pending;
|
||||
bool wait_inactive_before_press;
|
||||
bool long_press_sent;
|
||||
bool click_pending;
|
||||
int64_t debounce_deadline_ms;
|
||||
@@ -252,6 +253,14 @@ static void control_plane_handle_debounced_transition(const control_plane_key_co
|
||||
int level,
|
||||
int64_t now_ms)
|
||||
{
|
||||
if (state->wait_inactive_before_press) {
|
||||
if (pressed) {
|
||||
state->debounced_pressed = false;
|
||||
return;
|
||||
}
|
||||
state->wait_inactive_before_press = false;
|
||||
}
|
||||
|
||||
if (pressed == state->debounced_pressed) {
|
||||
return;
|
||||
}
|
||||
@@ -374,8 +383,14 @@ static void control_plane_key_input_task(void *arg)
|
||||
const control_plane_key_config_t *config = &s_key_configs[i];
|
||||
s_key_states[i].initialized = true;
|
||||
s_key_states[i].raw_level = gpio_get_level(config->gpio_num);
|
||||
s_key_states[i].debounced_pressed =
|
||||
control_plane_key_level_is_pressed(config, s_key_states[i].raw_level);
|
||||
bool initial_pressed = control_plane_key_level_is_pressed(config, s_key_states[i].raw_level);
|
||||
s_key_states[i].debounced_pressed = initial_pressed;
|
||||
if (config->key_id == CONTROL_PLANE_KEY_ID_PTT && initial_pressed) {
|
||||
ESP_LOGW(TAG,
|
||||
"PTT initial level is active; wait for next stable press before emitting press event");
|
||||
s_key_states[i].debounced_pressed = false;
|
||||
s_key_states[i].wait_inactive_before_press = true;
|
||||
}
|
||||
|
||||
setup_err = control_plane_configure_key_gpio(config);
|
||||
if (setup_err != ESP_OK) {
|
||||
|
||||
@@ -726,7 +726,7 @@ static void control_plane_websocket_wait_task(void *arg)
|
||||
return;
|
||||
}
|
||||
|
||||
static esp_err_t control_plane_schedule_websocket_wait_task(void)
|
||||
esp_err_t control_plane_schedule_websocket_wait_task(void)
|
||||
{
|
||||
bool should_create = false;
|
||||
|
||||
|
||||
@@ -30,6 +30,10 @@
|
||||
#define CONFIG_TQ_SYSTEM_EVENT_TASK_STACK 4096
|
||||
#endif
|
||||
|
||||
#define CONTROL_PLANE_PTT_HOLD_STEP_MS 80
|
||||
#define CONTROL_PLANE_PTT_HOLD_TASK_STACK 4096
|
||||
#define CONTROL_PLANE_PTT_HOLD_TASK_PRIORITY 4
|
||||
|
||||
#ifndef CONFIG_TQ_LOCAL_TASK_CORE
|
||||
#define CONFIG_TQ_LOCAL_TASK_CORE 1
|
||||
#endif
|
||||
@@ -44,7 +48,9 @@ static const char *TAG = "cp_system_event";
|
||||
|
||||
static QueueHandle_t s_system_event_queue;
|
||||
static TaskHandle_t s_system_event_task;
|
||||
static TaskHandle_t s_ptt_hold_task;
|
||||
static volatile bool s_stop_requested;
|
||||
static volatile bool s_ptt_hold_active;
|
||||
|
||||
static const char *control_plane_event_family_name(control_plane_event_family_t family)
|
||||
{
|
||||
@@ -106,6 +112,80 @@ const char *control_plane_key_event_type_name(control_plane_key_event_type_t typ
|
||||
}
|
||||
}
|
||||
|
||||
static void control_plane_ptt_hold_task(void *arg)
|
||||
{
|
||||
(void)arg;
|
||||
ESP_LOGI(TAG, "PTT hold task started");
|
||||
bool start_requested = false;
|
||||
|
||||
while (s_ptt_hold_active && !s_stop_requested) {
|
||||
if (!control_plane_is_sta_connected()) {
|
||||
vTaskDelay(pdMS_TO_TICKS(CONTROL_PLANE_PTT_HOLD_STEP_MS));
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!control_plane_multimodal_is_connected() && !start_requested) {
|
||||
esp_err_t schedule_err = control_plane_schedule_websocket_wait_task();
|
||||
if (schedule_err != ESP_OK && schedule_err != ESP_ERR_INVALID_STATE) {
|
||||
ESP_LOGW(TAG,
|
||||
"PTT multimodal start schedule failed: %s",
|
||||
esp_err_to_name(schedule_err));
|
||||
} else {
|
||||
start_requested = true;
|
||||
}
|
||||
}
|
||||
|
||||
esp_err_t press_err = control_plane_multimodal_handle_ptt_press_step();
|
||||
if (press_err != ESP_OK &&
|
||||
press_err != ESP_ERR_INVALID_STATE &&
|
||||
press_err != ESP_ERR_NOT_SUPPORTED) {
|
||||
ESP_LOGW(TAG, "PTT press step failed: %s", esp_err_to_name(press_err));
|
||||
}
|
||||
|
||||
vTaskDelay(pdMS_TO_TICKS(CONTROL_PLANE_PTT_HOLD_STEP_MS));
|
||||
}
|
||||
|
||||
ESP_LOGI(TAG, "PTT hold task stopped");
|
||||
s_ptt_hold_task = NULL;
|
||||
vTaskDelete(NULL);
|
||||
}
|
||||
|
||||
static esp_err_t control_plane_start_ptt_hold_task(void)
|
||||
{
|
||||
s_ptt_hold_active = true;
|
||||
if (s_ptt_hold_task != NULL) {
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
BaseType_t created = xTaskCreatePinnedToCore(control_plane_ptt_hold_task,
|
||||
"cp_ptt_hold",
|
||||
CONTROL_PLANE_PTT_HOLD_TASK_STACK,
|
||||
NULL,
|
||||
CONTROL_PLANE_PTT_HOLD_TASK_PRIORITY,
|
||||
&s_ptt_hold_task,
|
||||
CONTROL_PLANE_SYSTEM_EVENT_TASK_CORE);
|
||||
if (created != pdPASS) {
|
||||
s_ptt_hold_task = NULL;
|
||||
s_ptt_hold_active = false;
|
||||
return ESP_ERR_NO_MEM;
|
||||
}
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
static void control_plane_stop_ptt_hold_task(void)
|
||||
{
|
||||
s_ptt_hold_active = false;
|
||||
|
||||
for (int i = 0; i < 10 && s_ptt_hold_task != NULL; ++i) {
|
||||
vTaskDelay(pdMS_TO_TICKS(20));
|
||||
}
|
||||
if (s_ptt_hold_task != NULL) {
|
||||
vTaskDelete(s_ptt_hold_task);
|
||||
s_ptt_hold_task = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static void control_plane_dispatch_key_event(const control_plane_key_event_t *event)
|
||||
{
|
||||
if (event == NULL) {
|
||||
@@ -120,6 +200,32 @@ static void control_plane_dispatch_key_event(const control_plane_key_event_t *ev
|
||||
event->level,
|
||||
event->press_duration_ms,
|
||||
event->click_count);
|
||||
|
||||
if (event->key_id != CONTROL_PLANE_KEY_ID_PTT) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch (event->type) {
|
||||
case CONTROL_PLANE_KEY_EVENT_PRESSED: {
|
||||
esp_err_t start_err = control_plane_start_ptt_hold_task();
|
||||
if (start_err != ESP_OK) {
|
||||
ESP_LOGW(TAG, "PTT hold task start failed: %s", esp_err_to_name(start_err));
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case CONTROL_PLANE_KEY_EVENT_RELEASED: {
|
||||
control_plane_stop_ptt_hold_task();
|
||||
esp_err_t release_err = control_plane_multimodal_handle_ptt_release();
|
||||
if (release_err != ESP_OK && release_err != ESP_ERR_INVALID_STATE) {
|
||||
ESP_LOGW(TAG, "PTT release failed: %s", esp_err_to_name(release_err));
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void control_plane_dispatch_system_event(const control_plane_system_event_t *event)
|
||||
@@ -225,6 +331,7 @@ void control_plane_stop_system_event_task(void)
|
||||
{
|
||||
#if CONFIG_TQ_SYSTEM_EVENT_ENABLE
|
||||
s_stop_requested = true;
|
||||
control_plane_stop_ptt_hold_task();
|
||||
|
||||
for (int i = 0; i < 20 && s_system_event_task != NULL; ++i) {
|
||||
vTaskDelay(pdMS_TO_TICKS(50));
|
||||
|
||||
Reference in New Issue
Block a user