基本按键功能测试完成
This commit is contained in:
@@ -10,10 +10,16 @@
|
||||
|
||||
#include "control_plane.h"
|
||||
#include "esp_log.h"
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "sdkconfig.h"
|
||||
|
||||
#ifndef CONFIG_TQ_BOOT_SEQUENCE_DRY_RUN
|
||||
#define CONFIG_TQ_BOOT_SEQUENCE_DRY_RUN 1
|
||||
#define CONFIG_TQ_BOOT_SEQUENCE_DRY_RUN 0
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_TQ_BOOT_SOUND_TIMEOUT_MS
|
||||
#define CONFIG_TQ_BOOT_SOUND_TIMEOUT_MS 3000
|
||||
#endif
|
||||
|
||||
static const char *TAG = "app_comp_boot";
|
||||
@@ -41,36 +47,82 @@ static void app_composition_log_stage(app_composition_boot_stage_t stage,
|
||||
ESP_LOGI(TAG, "boot stage %02d %-24s event=%s", (int)stage, name, event);
|
||||
}
|
||||
|
||||
static void app_composition_log_stage_dry_run(app_composition_boot_stage_t stage,
|
||||
const char *name,
|
||||
const char *event)
|
||||
static void app_composition_log_stage_result(app_composition_boot_stage_t stage,
|
||||
const char *name,
|
||||
esp_err_t result)
|
||||
{
|
||||
ESP_LOGI(TAG, "boot stage %02d %-24s would_trigger=%s", (int)stage, name, event);
|
||||
ESP_LOGI(TAG,
|
||||
"boot stage %02d %-24s result=%s",
|
||||
(int)stage,
|
||||
name,
|
||||
esp_err_to_name(result));
|
||||
}
|
||||
|
||||
static void app_composition_log_stage_skipped(app_composition_boot_stage_t stage,
|
||||
const char *name,
|
||||
const char *reason)
|
||||
{
|
||||
ESP_LOGI(TAG, "boot stage %02d %-24s skipped=%s", (int)stage, name, reason);
|
||||
}
|
||||
|
||||
static esp_err_t app_composition_run_plan_a_boot_sequence(void)
|
||||
{
|
||||
app_composition_log_stage_dry_run(APP_COMPOSITION_BOOT_STAGE_POWER_HOLD,
|
||||
"power_hold",
|
||||
"assert_power_hold_gpio");
|
||||
app_composition_log_stage_dry_run(APP_COMPOSITION_BOOT_STAGE_AUDIO_INIT,
|
||||
"audio_init",
|
||||
"initialize_audio_path_with_timeout");
|
||||
app_composition_log_stage_dry_run(APP_COMPOSITION_BOOT_STAGE_BOOT_SOUND,
|
||||
"boot_sound",
|
||||
"play_boot_sound_with_timeout");
|
||||
app_composition_log_stage_dry_run(APP_COMPOSITION_BOOT_STAGE_AUDIO_RELEASE,
|
||||
"audio_release",
|
||||
"release_idle_audio_resources");
|
||||
app_composition_log_stage_dry_run(APP_COMPOSITION_BOOT_STAGE_LCD_DEVICE,
|
||||
app_composition_log_stage(APP_COMPOSITION_BOOT_STAGE_POWER_HOLD,
|
||||
"power_hold",
|
||||
"already_asserted_by_platform_core");
|
||||
|
||||
app_composition_log_stage(APP_COMPOSITION_BOOT_STAGE_AUDIO_INIT,
|
||||
"audio_init",
|
||||
"boot_sound_policy_begin");
|
||||
app_composition_log_stage(APP_COMPOSITION_BOOT_STAGE_BOOT_SOUND,
|
||||
"boot_sound",
|
||||
"play_boot_sound_with_timeout");
|
||||
esp_err_t boot_sound_err =
|
||||
control_plane_play_boot_sound(CONFIG_TQ_BOOT_SOUND_TIMEOUT_MS);
|
||||
if (boot_sound_err != ESP_OK) {
|
||||
ESP_LOGW(TAG,
|
||||
"Boot sound unavailable, continue boot: %s",
|
||||
esp_err_to_name(boot_sound_err));
|
||||
}
|
||||
app_composition_log_stage(APP_COMPOSITION_BOOT_STAGE_AUDIO_RELEASE,
|
||||
"audio_release",
|
||||
"boot_sound_policy_end");
|
||||
|
||||
#if CONFIG_TQ_SCREEN_ENABLE
|
||||
app_composition_log_stage(APP_COMPOSITION_BOOT_STAGE_LCD_DEVICE,
|
||||
"lcd_device",
|
||||
"control_plane_init_lcd_device");
|
||||
esp_err_t lcd_err = control_plane_init_lcd_device();
|
||||
app_composition_log_stage_result(APP_COMPOSITION_BOOT_STAGE_LCD_DEVICE,
|
||||
"lcd_device",
|
||||
lcd_err);
|
||||
bool lcd_ready = (lcd_err == ESP_OK);
|
||||
if (lcd_ready) {
|
||||
app_composition_log_stage(APP_COMPOSITION_BOOT_STAGE_LCD_RENDER_LOOP,
|
||||
"lcd_render_loop",
|
||||
"deferred_to_runtime_worker_task");
|
||||
app_composition_log_stage(APP_COMPOSITION_BOOT_STAGE_BOOT_EXPRESSION,
|
||||
"boot_expression",
|
||||
"deferred_until_runtime_worker_started");
|
||||
} else {
|
||||
app_composition_log_stage_skipped(APP_COMPOSITION_BOOT_STAGE_LCD_RENDER_LOOP,
|
||||
"lcd_render_loop",
|
||||
"lcd_device_unavailable");
|
||||
app_composition_log_stage_skipped(APP_COMPOSITION_BOOT_STAGE_BOOT_EXPRESSION,
|
||||
"boot_expression",
|
||||
"lcd_device_unavailable");
|
||||
}
|
||||
#else
|
||||
app_composition_log_stage_skipped(APP_COMPOSITION_BOOT_STAGE_LCD_DEVICE,
|
||||
"lcd_device",
|
||||
"initialize_lcd_device");
|
||||
app_composition_log_stage_dry_run(APP_COMPOSITION_BOOT_STAGE_LCD_RENDER_LOOP,
|
||||
"disabled_by_config");
|
||||
app_composition_log_stage_skipped(APP_COMPOSITION_BOOT_STAGE_LCD_RENDER_LOOP,
|
||||
"lcd_render_loop",
|
||||
"start_lcd_render_loop");
|
||||
app_composition_log_stage_dry_run(APP_COMPOSITION_BOOT_STAGE_BOOT_EXPRESSION,
|
||||
"disabled_by_config");
|
||||
app_composition_log_stage_skipped(APP_COMPOSITION_BOOT_STAGE_BOOT_EXPRESSION,
|
||||
"boot_expression",
|
||||
"request_boot_default_expression");
|
||||
"disabled_by_config");
|
||||
#endif
|
||||
|
||||
app_composition_log_stage(APP_COMPOSITION_BOOT_STAGE_PLATFORM_DOMAIN,
|
||||
"platform_domain",
|
||||
@@ -81,28 +133,67 @@ static esp_err_t app_composition_run_plan_a_boot_sequence(void)
|
||||
return err;
|
||||
}
|
||||
|
||||
app_composition_log_stage_dry_run(APP_COMPOSITION_BOOT_STAGE_TURNTABLE_CALIBRATION,
|
||||
#if CONFIG_TQ_BOOT_TURNTABLE_CALIBRATION_ENABLE
|
||||
app_composition_log_stage(APP_COMPOSITION_BOOT_STAGE_TURNTABLE_CALIBRATION,
|
||||
"turntable_calibration",
|
||||
"control_plane_calibrate");
|
||||
esp_err_t calibration_err = control_plane_calibrate();
|
||||
if (calibration_err != ESP_OK) {
|
||||
ESP_LOGW(TAG,
|
||||
"Boot turntable calibration failed, continue degraded: %s",
|
||||
esp_err_to_name(calibration_err));
|
||||
}
|
||||
#else
|
||||
app_composition_log_stage_skipped(APP_COMPOSITION_BOOT_STAGE_TURNTABLE_CALIBRATION,
|
||||
"turntable_calibration",
|
||||
"run_turntable_calibration_with_timeout");
|
||||
app_composition_log_stage_dry_run(APP_COMPOSITION_BOOT_STAGE_STORAGE_PREPARE,
|
||||
"storage_prepare",
|
||||
"prepare_runtime_storage");
|
||||
app_composition_log_stage_dry_run(APP_COMPOSITION_BOOT_STAGE_WIFI_BOOTSTRAP,
|
||||
"wifi_bootstrap",
|
||||
"start_wifi_sta_or_config_ap");
|
||||
"disabled_by_config");
|
||||
#endif
|
||||
|
||||
app_composition_log_stage(APP_COMPOSITION_BOOT_STAGE_RUNTIME_WORKERS,
|
||||
"runtime_workers",
|
||||
"start_event_observer_runtime");
|
||||
err = control_plane_start_event_observer_runtime();
|
||||
app_composition_log_stage(APP_COMPOSITION_BOOT_STAGE_STORAGE_PREPARE,
|
||||
"storage_prepare",
|
||||
"control_plane_prepare_runtime_storage");
|
||||
err = control_plane_prepare_runtime_storage();
|
||||
if (err != ESP_OK) {
|
||||
ESP_LOGE(TAG, "event observer runtime failed: %s", esp_err_to_name(err));
|
||||
ESP_LOGE(TAG, "Runtime storage prepare failed: %s", esp_err_to_name(err));
|
||||
return err;
|
||||
}
|
||||
|
||||
app_composition_log_stage_dry_run(APP_COMPOSITION_BOOT_STAGE_NETWORK_SERVICES,
|
||||
"network_services",
|
||||
"start_websocket_fortune_lan_http_after_network_ready");
|
||||
app_composition_log_stage(APP_COMPOSITION_BOOT_STAGE_WIFI_BOOTSTRAP,
|
||||
"wifi_bootstrap",
|
||||
"control_plane_bootstrap_connectivity");
|
||||
esp_err_t wifi_err = control_plane_bootstrap_connectivity(CONFIG_MULTIMODAL_WIFI_SSID,
|
||||
CONFIG_MULTIMODAL_WIFI_PASSWORD,
|
||||
CONFIG_MULTIMODAL_CONNECT_TIMEOUT_MS,
|
||||
"TQ-CAT");
|
||||
if (wifi_err != ESP_OK) {
|
||||
ESP_LOGW(TAG, "Connectivity bootstrap failed: %s", esp_err_to_name(wifi_err));
|
||||
}
|
||||
|
||||
app_composition_log_stage(APP_COMPOSITION_BOOT_STAGE_RUNTIME_WORKERS,
|
||||
"runtime_workers",
|
||||
"control_plane_start_runtime_workers");
|
||||
err = control_plane_start_runtime_workers();
|
||||
if (err != ESP_OK) {
|
||||
ESP_LOGE(TAG, "Runtime worker start failed: %s", esp_err_to_name(err));
|
||||
return err;
|
||||
}
|
||||
|
||||
#if CONFIG_TQ_SCREEN_ENABLE
|
||||
if (lcd_ready) {
|
||||
vTaskDelay(pdMS_TO_TICKS(200));
|
||||
app_composition_log_stage(APP_COMPOSITION_BOOT_STAGE_BOOT_EXPRESSION,
|
||||
"boot_expression",
|
||||
"control_plane_request_boot_expression");
|
||||
esp_err_t expression_err = control_plane_request_boot_expression();
|
||||
if (expression_err != ESP_OK) {
|
||||
ESP_LOGW(TAG, "Boot expression request failed: %s", esp_err_to_name(expression_err));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
app_composition_log_stage(APP_COMPOSITION_BOOT_STAGE_NETWORK_SERVICES,
|
||||
"network_services",
|
||||
"started_by_runtime_workers_after_readiness");
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
@@ -119,10 +210,9 @@ esp_err_t app_composition_start_default_runtime(void)
|
||||
ESP_LOGI(TAG, "========================================");
|
||||
|
||||
#if CONFIG_TQ_BOOT_SEQUENCE_DRY_RUN
|
||||
return app_composition_run_plan_a_boot_sequence();
|
||||
#else
|
||||
ESP_LOGE(TAG, "Non-dry-run Plan A boot is not enabled in this refactor phase");
|
||||
ESP_LOGE(TAG, "Plan A dry-run is enabled; disable CONFIG_TQ_BOOT_SEQUENCE_DRY_RUN");
|
||||
return ESP_ERR_NOT_SUPPORTED;
|
||||
#else
|
||||
return app_composition_run_plan_a_boot_sequence();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -126,6 +126,14 @@ esp_err_t control_plane_bootstrap_connectivity(const char *seed_ssid,
|
||||
const char *config_ap_ssid_prefix);
|
||||
bool control_plane_is_sta_connected(void);
|
||||
|
||||
/**
|
||||
* @brief Execute the Plan A boot sound policy with bounded caller semantics.
|
||||
*
|
||||
* The current platform voice-prompt backend may return ESP_ERR_NOT_SUPPORTED;
|
||||
* callers should log and continue boot in that case.
|
||||
*/
|
||||
esp_err_t control_plane_play_boot_sound(int timeout_ms);
|
||||
|
||||
/**
|
||||
* @brief Start multimodal client runtime.
|
||||
*
|
||||
@@ -210,6 +218,7 @@ esp_err_t control_plane_fortune_refresh_now(void);
|
||||
|
||||
esp_err_t control_plane_init_lcd_device(void);
|
||||
void control_plane_start_lcd_render_loop(void);
|
||||
esp_err_t control_plane_request_boot_expression(void);
|
||||
/**
|
||||
* @brief Stop LCD render loop with bounded teardown.
|
||||
*
|
||||
|
||||
@@ -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