优化了不必要的任务,待测
This commit is contained in:
@@ -31,9 +31,6 @@
|
||||
#endif
|
||||
|
||||
#define CONTROL_PLANE_PTT_HOLD_STEP_MS 80
|
||||
#define CONTROL_PLANE_PTT_HOLD_START_DELAY_MS 320
|
||||
#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
|
||||
@@ -49,9 +46,7 @@ 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)
|
||||
{
|
||||
@@ -113,88 +108,6 @@ 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;
|
||||
uint32_t waited_ms = 0;
|
||||
|
||||
while (s_ptt_hold_active &&
|
||||
!s_stop_requested &&
|
||||
waited_ms < CONTROL_PLANE_PTT_HOLD_START_DELAY_MS) {
|
||||
vTaskDelay(pdMS_TO_TICKS(CONTROL_PLANE_PTT_HOLD_STEP_MS));
|
||||
waited_ms += CONTROL_PLANE_PTT_HOLD_STEP_MS;
|
||||
}
|
||||
|
||||
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) {
|
||||
@@ -216,15 +129,12 @@ static void control_plane_dispatch_key_event(const control_plane_key_event_t *ev
|
||||
|
||||
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));
|
||||
}
|
||||
control_plane_set_ptt_active(true);
|
||||
break;
|
||||
}
|
||||
|
||||
case CONTROL_PLANE_KEY_EVENT_RELEASED: {
|
||||
control_plane_stop_ptt_hold_task();
|
||||
control_plane_set_ptt_active(false);
|
||||
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));
|
||||
@@ -352,7 +262,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();
|
||||
control_plane_set_ptt_active(false);
|
||||
|
||||
for (int i = 0; i < 20 && s_system_event_task != NULL; ++i) {
|
||||
vTaskDelay(pdMS_TO_TICKS(50));
|
||||
|
||||
Reference in New Issue
Block a user