feat(control_plane): play prompt before light standby
This commit is contained in:
@@ -41,6 +41,14 @@
|
||||
#define CONFIG_TQ_LIGHT_STANDBY_BACKLIGHT_PERCENT 10
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_TQ_LIGHT_STANDBY_PROMPT_ENABLE
|
||||
#define CONFIG_TQ_LIGHT_STANDBY_PROMPT_ENABLE 0
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_TQ_LIGHT_STANDBY_PROMPT_FILE
|
||||
#define CONFIG_TQ_LIGHT_STANDBY_PROMPT_FILE "standby_5min.opus"
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_TQ_LIGHT_STANDBY_DISABLE_SPEAKER_OUTPUT
|
||||
#define CONFIG_TQ_LIGHT_STANDBY_DISABLE_SPEAKER_OUTPUT 0
|
||||
#endif
|
||||
@@ -317,6 +325,44 @@ static esp_err_t control_plane_light_standby_apply_entry_policy(void)
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
static esp_err_t control_plane_light_standby_play_entry_prompt(void)
|
||||
{
|
||||
#if CONFIG_TQ_LIGHT_STANDBY_PROMPT_ENABLE
|
||||
TickType_t started_tick = xTaskGetTickCount();
|
||||
ESP_LOGI(TAG,
|
||||
"Entry prompt started file=%s",
|
||||
CONFIG_TQ_LIGHT_STANDBY_PROMPT_FILE);
|
||||
esp_err_t prompt_err = domain_runtime_behavior_play_prompt_file(
|
||||
CONFIG_TQ_LIGHT_STANDBY_PROMPT_FILE);
|
||||
uint32_t elapsed_ms = (uint32_t)pdTICKS_TO_MS(
|
||||
xTaskGetTickCount() - started_tick);
|
||||
if (prompt_err != ESP_OK) {
|
||||
ESP_LOGE(TAG,
|
||||
"Entry prompt failed elapsed_ms=%u err=%s",
|
||||
(unsigned)elapsed_ms,
|
||||
esp_err_to_name(prompt_err));
|
||||
return prompt_err;
|
||||
}
|
||||
ESP_LOGI(TAG,
|
||||
"Entry prompt completed elapsed_ms=%u",
|
||||
(unsigned)elapsed_ms);
|
||||
#endif
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
static bool control_plane_light_standby_entry_is_current(
|
||||
uint64_t entry_activity_ms)
|
||||
{
|
||||
bool current;
|
||||
portENTER_CRITICAL(&s_standby_lock);
|
||||
current = s_standby.running &&
|
||||
!s_standby.stop_requested &&
|
||||
s_standby.state == CONTROL_PLANE_LIGHT_STANDBY_STATE_ENTERING &&
|
||||
s_standby.last_activity_ms == entry_activity_ms;
|
||||
portEXIT_CRITICAL(&s_standby_lock);
|
||||
return current;
|
||||
}
|
||||
|
||||
static void control_plane_light_standby_enter(uint64_t now_ms)
|
||||
{
|
||||
if (!control_plane_light_standby_lock_transition()) {
|
||||
@@ -349,27 +395,41 @@ static void control_plane_light_standby_enter(uint64_t now_ms)
|
||||
CONTROL_PLANE_LIGHT_STANDBY_STATE_ENTERING,
|
||||
"idle_timeout");
|
||||
|
||||
esp_err_t policy_err = control_plane_light_standby_apply_entry_policy();
|
||||
esp_err_t policy_err = control_plane_light_standby_play_entry_prompt();
|
||||
bool policy_applied = false;
|
||||
bool entry_current = policy_err == ESP_OK &&
|
||||
control_plane_light_standby_entry_is_current(entry_activity_ms);
|
||||
bool runtime_eligible = entry_current &&
|
||||
control_plane_light_standby_runtime_is_eligible();
|
||||
if (runtime_eligible) {
|
||||
policy_applied = true;
|
||||
policy_err = control_plane_light_standby_apply_entry_policy();
|
||||
}
|
||||
bool entered = false;
|
||||
bool restore_required = false;
|
||||
const char *completion_reason = "hardware_policy";
|
||||
uint64_t completion_ms = control_plane_light_standby_now_ms();
|
||||
portENTER_CRITICAL(&s_standby_lock);
|
||||
if (s_standby.state == CONTROL_PLANE_LIGHT_STANDBY_STATE_ENTERING &&
|
||||
!s_standby.stop_requested &&
|
||||
s_standby.last_activity_ms == entry_activity_ms &&
|
||||
policy_applied &&
|
||||
policy_err == ESP_OK) {
|
||||
s_standby.state = CONTROL_PLANE_LIGHT_STANDBY_STATE_STANDBY;
|
||||
s_standby.standby_since_ms = now_ms;
|
||||
s_standby.standby_since_ms = completion_ms;
|
||||
s_standby.transition_count++;
|
||||
entered = true;
|
||||
} else if (s_standby.state == CONTROL_PLANE_LIGHT_STANDBY_STATE_ENTERING) {
|
||||
s_standby.state = CONTROL_PLANE_LIGHT_STANDBY_STATE_WAKING;
|
||||
s_standby.transition_count++;
|
||||
restore_required = true;
|
||||
restore_required = policy_applied;
|
||||
if (policy_err != ESP_OK) {
|
||||
completion_reason = "hardware_policy_failed";
|
||||
completion_reason = policy_applied ?
|
||||
"hardware_policy_failed" : "entry_prompt_failed";
|
||||
} else if (s_standby.stop_requested) {
|
||||
completion_reason = "stop_requested";
|
||||
} else if (entry_current && !runtime_eligible) {
|
||||
completion_reason = "runtime_ineligible";
|
||||
} else {
|
||||
completion_reason = "activity_during_entry";
|
||||
}
|
||||
@@ -399,7 +459,7 @@ static void control_plane_light_standby_enter(uint64_t now_ms)
|
||||
s_standby.state = CONTROL_PLANE_LIGHT_STANDBY_STATE_ACTIVE;
|
||||
s_standby.standby_since_ms = 0U;
|
||||
if (policy_err != ESP_OK) {
|
||||
s_standby.last_activity_ms = now_ms;
|
||||
s_standby.last_activity_ms = completion_ms;
|
||||
}
|
||||
s_standby.transition_count++;
|
||||
activated = true;
|
||||
@@ -631,8 +691,7 @@ esp_err_t control_plane_light_standby_record_activity(
|
||||
s_standby.last_activity = activity;
|
||||
s_standby.last_activity_ms = now_ms;
|
||||
task = s_standby.task;
|
||||
if (s_standby.state == CONTROL_PLANE_LIGHT_STANDBY_STATE_STANDBY ||
|
||||
s_standby.state == CONTROL_PLANE_LIGHT_STANDBY_STATE_ENTERING) {
|
||||
if (s_standby.state == CONTROL_PLANE_LIGHT_STANDBY_STATE_STANDBY) {
|
||||
wake_required = true;
|
||||
}
|
||||
portEXIT_CRITICAL(&s_standby_lock);
|
||||
|
||||
Reference in New Issue
Block a user