修复了WS连接稳定性问题

This commit is contained in:
CSBOOK\44744
2026-06-27 20:29:09 +08:00
parent b829cd8ebc
commit caa4a7eded
16 changed files with 2197 additions and 248 deletions
@@ -48,6 +48,10 @@
#define CONFIG_TQ_KEY_INPUT_POLL_MS 20
#endif
#ifndef CONTROL_PLANE_PTT_INITIAL_INACTIVE_STABLE_MS
#define CONTROL_PLANE_PTT_INITIAL_INACTIVE_STABLE_MS 120
#endif
#ifndef CONFIG_TQ_LOCAL_TASK_CORE
#define CONFIG_TQ_LOCAL_TASK_CORE 1
#endif
@@ -98,6 +102,7 @@ typedef struct {
bool long_press_sent;
bool click_pending;
int64_t debounce_deadline_ms;
int64_t inactive_since_ms;
int64_t press_start_ms;
int64_t click_deadline_ms;
} control_plane_key_state_t;
@@ -113,9 +118,9 @@ static const control_plane_key_config_t s_key_configs[] = {
.long_press_ms = CONFIG_TQ_KEY_LONG_PRESS_MS,
.double_click_ms = CONFIG_TQ_KEY_DOUBLE_CLICK_MS,
.emit_press_release = true,
.enable_short_press = true,
.enable_short_press = false,
.enable_long_press = false,
.enable_double_click = true,
.enable_double_click = false,
},
{
.key_id = CONTROL_PLANE_KEY_ID_SW2,
@@ -256,9 +261,14 @@ static void control_plane_handle_debounced_transition(const control_plane_key_co
if (state->wait_inactive_before_press) {
if (pressed) {
state->debounced_pressed = false;
state->inactive_since_ms = 0;
return;
}
state->wait_inactive_before_press = false;
state->inactive_since_ms = 0;
ESP_LOGI(TAG,
"key=%s initial active gate cleared by debounced inactive level",
control_plane_key_id_name(config->key_id));
}
if (pressed == state->debounced_pressed) {
@@ -334,6 +344,33 @@ static void control_plane_process_key_timers(void)
continue;
}
if (state->wait_inactive_before_press) {
const int level = gpio_get_level(config->gpio_num);
const bool pressed = control_plane_key_level_is_pressed(config, level);
if (!pressed) {
if (state->inactive_since_ms == 0) {
state->inactive_since_ms = now_ms;
}
uint32_t stable_ms = config->debounce_ms;
if (stable_ms < CONTROL_PLANE_PTT_INITIAL_INACTIVE_STABLE_MS) {
stable_ms = CONTROL_PLANE_PTT_INITIAL_INACTIVE_STABLE_MS;
}
if ((now_ms - state->inactive_since_ms) >= stable_ms) {
state->wait_inactive_before_press = false;
state->debounced_pressed = false;
state->debounce_pending = false;
state->press_start_ms = 0;
state->long_press_sent = false;
ESP_LOGI(TAG,
"key=%s initial active gate cleared by stable inactive poll (%" PRId64 "ms)",
control_plane_key_id_name(config->key_id),
now_ms - state->inactive_since_ms);
}
} else {
state->inactive_since_ms = 0;
}
}
if (state->debounce_pending && now_ms >= state->debounce_deadline_ms) {
state->debounce_pending = false;
const int level = gpio_get_level(config->gpio_num);
@@ -390,6 +427,7 @@ static void control_plane_key_input_task(void *arg)
"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;
s_key_states[i].inactive_since_ms = 0;
}
setup_err = control_plane_configure_key_gpio(config);