基本按键功能测试完成
This commit is contained in:
@@ -16,6 +16,14 @@
|
||||
#define CONFIG_MULTIMODAL_CONNECT_TIMEOUT_MS 10000
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_TQ_BOOT_SOUND_TIMEOUT_MS
|
||||
#define CONFIG_TQ_BOOT_SOUND_TIMEOUT_MS 3000
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_TQ_BOOT_SOUND_FILE
|
||||
#define CONFIG_TQ_BOOT_SOUND_FILE ""
|
||||
#endif
|
||||
|
||||
#define CONTROL_PLANE_STA_CONNECT_MAX_ATTEMPTS 3
|
||||
#define CONTROL_PLANE_STA_RETRY_BASE_DELAY_MS 300
|
||||
|
||||
@@ -208,6 +216,33 @@ bool control_plane_is_sta_connected(void)
|
||||
return domain_runtime_wifi_portal_sta_is_connected();
|
||||
}
|
||||
|
||||
esp_err_t control_plane_play_boot_sound(int timeout_ms)
|
||||
{
|
||||
int effective_timeout_ms = timeout_ms > 0 ? timeout_ms : CONFIG_TQ_BOOT_SOUND_TIMEOUT_MS;
|
||||
ESP_LOGI(TAG, "Boot sound policy start timeout=%dms", effective_timeout_ms);
|
||||
|
||||
if (CONFIG_TQ_BOOT_SOUND_FILE[0] == '\0') {
|
||||
ESP_LOGW(TAG, "Boot sound file is not configured");
|
||||
return ESP_ERR_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
esp_err_t audio_err = domain_runtime_multimodal_audio_init();
|
||||
if (audio_err != ESP_OK) {
|
||||
ESP_LOGW(TAG, "Boot sound audio init failed: %s", esp_err_to_name(audio_err));
|
||||
return audio_err;
|
||||
}
|
||||
|
||||
esp_err_t play_err = domain_runtime_behavior_play_prompt_file(CONFIG_TQ_BOOT_SOUND_FILE);
|
||||
|
||||
if (play_err != ESP_OK) {
|
||||
ESP_LOGW(TAG, "Boot sound playback failed: %s", esp_err_to_name(play_err));
|
||||
}
|
||||
|
||||
domain_runtime_multimodal_audio_deinit();
|
||||
ESP_LOGI(TAG, "Boot sound audio resources released");
|
||||
return play_err;
|
||||
}
|
||||
|
||||
esp_err_t control_plane_init_lcd_device(void)
|
||||
{
|
||||
return domain_runtime_init_lcd_device();
|
||||
@@ -218,6 +253,16 @@ void control_plane_start_lcd_render_loop(void)
|
||||
domain_runtime_start_lcd_render_loop();
|
||||
}
|
||||
|
||||
esp_err_t control_plane_request_boot_expression(void)
|
||||
{
|
||||
domain_expression_request_t request = {
|
||||
.id = DOMAIN_EXPRESSION_IDLE,
|
||||
.trigger = DOMAIN_EXPRESSION_TRIGGER_UNSPECIFIED,
|
||||
.direction_index = 0,
|
||||
};
|
||||
return domain_runtime_request_expression(&request);
|
||||
}
|
||||
|
||||
esp_err_t control_plane_stop_lcd_render_loop(int timeout_ms)
|
||||
{
|
||||
return domain_runtime_stop_lcd_render_loop(timeout_ms);
|
||||
|
||||
@@ -24,8 +24,6 @@
|
||||
#define CONTROL_PLANE_MODEL_CMD_TASK_STACK_SIZE (1024 * 4)
|
||||
#define CONTROL_PLANE_DIRECTION_TASK_STACK_SIZE (1024 * 4)
|
||||
#define CONTROL_PLANE_LCD_RENDER_LOOP_TASK_STACK_SIZE (1024 * 12)
|
||||
#define CONTROL_PLANE_PTT_TASK_STACK_SIZE (1024 * 4)
|
||||
#define CONTROL_PLANE_SLOT_SWITCH_TASK_STACK_SIZE (1024 * 4)
|
||||
#define CONTROL_PLANE_WIFI_STATE_TASK_STACK_SIZE (1024 * 6)
|
||||
#define CONTROL_PLANE_TASK_MONITOR_TASK_STACK_SIZE (1024 * 6)
|
||||
#define CONTROL_PLANE_MODEL_CMD_QUEUE_LEN 4
|
||||
@@ -33,10 +31,6 @@
|
||||
#define CONTROL_PLANE_TASK_STOP_WAIT_MS 1500
|
||||
#define CONTROL_PLANE_TASK_START_GATE_WAIT_MS 5000
|
||||
#define CONTROL_PLANE_INPUT_BUF_SIZE 64
|
||||
#define CONTROL_PLANE_PTT_POLL_INTERVAL_MS 20
|
||||
#define CONTROL_PLANE_PTT_DEBOUNCE_SAMPLES 2
|
||||
#define CONTROL_PLANE_SLOT_SWITCH_POLL_INTERVAL_MS 20
|
||||
#define CONTROL_PLANE_SLOT_SWITCH_DEBOUNCE_SAMPLES 2
|
||||
#define CONTROL_PLANE_WIFI_STATE_POLL_INTERVAL_MS 1000
|
||||
#define CONTROL_PLANE_WIFI_DISCONNECTED_REFRESH_MS 5000
|
||||
#define CONTROL_PLANE_WIFI_DISCONNECT_GRACE_MS 3000
|
||||
@@ -124,8 +118,6 @@ static TaskHandle_t s_ws_wait_task;
|
||||
static bool s_ws_wait_task_starting;
|
||||
static TaskHandle_t s_direction_console_task;
|
||||
static TaskHandle_t s_lcd_render_loop_task;
|
||||
static TaskHandle_t s_ptt_task;
|
||||
static TaskHandle_t s_slot_switch_task;
|
||||
static TaskHandle_t s_wifi_state_task;
|
||||
#if CONFIG_TQ_TASK_MONITOR_ENABLE
|
||||
static TaskHandle_t s_task_monitor_task;
|
||||
@@ -934,151 +926,6 @@ static void control_plane_lcd_render_loop_task(void *arg)
|
||||
}
|
||||
#endif
|
||||
|
||||
static void control_plane_ptt_task(void *arg)
|
||||
{
|
||||
(void)arg;
|
||||
|
||||
ESP_LOGI(TAG, "PTT task started");
|
||||
|
||||
esp_err_t init_err = domain_runtime_multimodal_ptt_button_init();
|
||||
if (init_err != ESP_OK) {
|
||||
ESP_LOGW(TAG, "PTT button init failed: %s", esp_err_to_name(init_err));
|
||||
control_plane_set_task_handle(&s_ptt_task, NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
bool debounced_pressed = domain_runtime_multimodal_ptt_button_is_pressed();
|
||||
bool sampled_pressed = debounced_pressed;
|
||||
int stable_samples = CONTROL_PLANE_PTT_DEBOUNCE_SAMPLES;
|
||||
bool ptt_press_armed = false;
|
||||
bool ptt_press_seen_connected = false;
|
||||
|
||||
while (!control_plane_runtime_stop_requested()) {
|
||||
bool raw_pressed = domain_runtime_multimodal_ptt_button_is_pressed();
|
||||
if (raw_pressed == sampled_pressed) {
|
||||
if (stable_samples < CONTROL_PLANE_PTT_DEBOUNCE_SAMPLES) {
|
||||
stable_samples++;
|
||||
}
|
||||
} else {
|
||||
sampled_pressed = raw_pressed;
|
||||
stable_samples = 1;
|
||||
}
|
||||
|
||||
if (sampled_pressed != debounced_pressed &&
|
||||
stable_samples >= CONTROL_PLANE_PTT_DEBOUNCE_SAMPLES) {
|
||||
debounced_pressed = sampled_pressed;
|
||||
if (debounced_pressed) {
|
||||
ESP_LOGI(TAG, "PTT button pressed");
|
||||
ptt_press_armed = true;
|
||||
ptt_press_seen_connected = control_plane_multimodal_is_connected();
|
||||
if (!ptt_press_seen_connected && control_plane_is_sta_connected()) {
|
||||
esp_err_t schedule_err = control_plane_schedule_websocket_wait_task();
|
||||
if (schedule_err == ESP_OK) {
|
||||
ESP_LOGI(TAG, "PTT requested multimodal client start");
|
||||
} else {
|
||||
ESP_LOGW(TAG, "PTT multimodal start schedule failed: %s",
|
||||
esp_err_to_name(schedule_err));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
ESP_LOGI(TAG, "PTT button released");
|
||||
if (ptt_press_armed &&
|
||||
ptt_press_seen_connected) {
|
||||
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));
|
||||
}
|
||||
}
|
||||
ptt_press_armed = false;
|
||||
ptt_press_seen_connected = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (debounced_pressed && ptt_press_armed) {
|
||||
bool connected = control_plane_multimodal_is_connected();
|
||||
if (!connected) {
|
||||
if (ptt_press_seen_connected) {
|
||||
(void)control_plane_multimodal_handle_ptt_release();
|
||||
ptt_press_armed = false;
|
||||
ptt_press_seen_connected = false;
|
||||
}
|
||||
} else {
|
||||
ptt_press_seen_connected = 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_POLL_INTERVAL_MS));
|
||||
}
|
||||
|
||||
if (ptt_press_armed && ptt_press_seen_connected) {
|
||||
(void)control_plane_multimodal_handle_ptt_release();
|
||||
}
|
||||
|
||||
control_plane_set_task_handle(&s_ptt_task, NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
#if CONFIG_TQ_SLOT_SWITCH_ENABLE
|
||||
static void control_plane_slot_switch_task(void *arg)
|
||||
{
|
||||
(void)arg;
|
||||
|
||||
ESP_LOGI(TAG, "Slot switch task started");
|
||||
|
||||
esp_err_t init_err = domain_runtime_slot_feature_switch_init();
|
||||
if (init_err != ESP_OK) {
|
||||
ESP_LOGW(TAG, "Slot feature switch init failed: %s", esp_err_to_name(init_err));
|
||||
control_plane_set_task_handle(&s_slot_switch_task, NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
bool debounced_active = domain_runtime_slot_feature_switch_is_active();
|
||||
bool sampled_active = debounced_active;
|
||||
int stable_samples = CONTROL_PLANE_SLOT_SWITCH_DEBOUNCE_SAMPLES;
|
||||
|
||||
while (!control_plane_runtime_stop_requested()) {
|
||||
bool raw_active = domain_runtime_slot_feature_switch_is_active();
|
||||
if (raw_active == sampled_active) {
|
||||
if (stable_samples < CONTROL_PLANE_SLOT_SWITCH_DEBOUNCE_SAMPLES) {
|
||||
stable_samples++;
|
||||
}
|
||||
} else {
|
||||
sampled_active = raw_active;
|
||||
stable_samples = 1;
|
||||
}
|
||||
|
||||
if (sampled_active != debounced_active &&
|
||||
stable_samples >= CONTROL_PLANE_SLOT_SWITCH_DEBOUNCE_SAMPLES) {
|
||||
debounced_active = sampled_active;
|
||||
if (debounced_active) {
|
||||
ESP_LOGI(TAG, "Slot feature switch triggered");
|
||||
const domain_expression_request_t request = {
|
||||
.id = DOMAIN_EXPRESSION_SLOT_REELS,
|
||||
.trigger = DOMAIN_EXPRESSION_TRIGGER_SLOT_SWITCH,
|
||||
};
|
||||
esp_err_t trigger_err = domain_runtime_request_expression(&request);
|
||||
if (trigger_err != ESP_OK && trigger_err != ESP_ERR_INVALID_STATE) {
|
||||
ESP_LOGW(TAG, "Slot animation trigger failed: %s", esp_err_to_name(trigger_err));
|
||||
}
|
||||
} else {
|
||||
ESP_LOGI(TAG, "Slot feature switch released");
|
||||
}
|
||||
}
|
||||
|
||||
vTaskDelay(pdMS_TO_TICKS(CONTROL_PLANE_SLOT_SWITCH_POLL_INTERVAL_MS));
|
||||
}
|
||||
|
||||
control_plane_set_task_handle(&s_slot_switch_task, NULL);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
static void control_plane_request_wifi_state_expression(domain_expression_id_t id,
|
||||
domain_expression_trigger_t trigger,
|
||||
const char *expression_name)
|
||||
@@ -1681,34 +1528,6 @@ esp_err_t control_plane_start_runtime_workers(void)
|
||||
return system_event_err;
|
||||
}
|
||||
|
||||
if (control_plane_get_task_handle(&s_ptt_task) == NULL) {
|
||||
esp_err_t task_err = control_plane_create_task(control_plane_ptt_task,
|
||||
"cp_ptt",
|
||||
CONTROL_PLANE_PTT_TASK_STACK_SIZE,
|
||||
5,
|
||||
&s_ptt_task);
|
||||
if (task_err != ESP_OK) {
|
||||
control_plane_stop_runtime_workers();
|
||||
return task_err;
|
||||
}
|
||||
}
|
||||
|
||||
#if CONFIG_TQ_SLOT_SWITCH_ENABLE
|
||||
if (control_plane_get_task_handle(&s_slot_switch_task) == NULL) {
|
||||
esp_err_t task_err = control_plane_create_task_psram_first(control_plane_slot_switch_task,
|
||||
"cp_slot_switch",
|
||||
CONTROL_PLANE_SLOT_SWITCH_TASK_STACK_SIZE,
|
||||
4,
|
||||
&s_slot_switch_task);
|
||||
if (task_err != ESP_OK) {
|
||||
control_plane_stop_runtime_workers();
|
||||
return task_err;
|
||||
}
|
||||
}
|
||||
#else
|
||||
ESP_LOGI(TAG, "Slot switch worker disabled by configuration");
|
||||
#endif
|
||||
|
||||
esp_err_t key_input_err = control_plane_start_key_input_task();
|
||||
if (key_input_err != ESP_OK) {
|
||||
control_plane_stop_runtime_workers();
|
||||
@@ -1817,12 +1636,6 @@ void control_plane_stop_runtime_workers(void)
|
||||
control_plane_force_delete_task(&s_task_monitor_task, "cp_task_monitor");
|
||||
}
|
||||
#endif
|
||||
if (!control_plane_wait_task_exit(&s_ptt_task, CONTROL_PLANE_TASK_STOP_WAIT_MS)) {
|
||||
control_plane_force_delete_task(&s_ptt_task, "cp_ptt");
|
||||
}
|
||||
if (!control_plane_wait_task_exit(&s_slot_switch_task, CONTROL_PLANE_TASK_STOP_WAIT_MS)) {
|
||||
control_plane_force_delete_task_with_caps(&s_slot_switch_task, "cp_slot_switch");
|
||||
}
|
||||
#if CONFIG_FORTUNE_ENABLE
|
||||
if (!control_plane_wait_task_exit(&s_daily_fortune_task, CONTROL_PLANE_TASK_STOP_WAIT_MS)) {
|
||||
control_plane_force_delete_task(&s_daily_fortune_task, "cp_fortune");
|
||||
|
||||
Reference in New Issue
Block a user