fix: input delay workaround
This commit is contained in:
@@ -37,11 +37,8 @@ static void launcher_handle_input(input_action_t action)
|
||||
if (action == INPUT_ACTION_CLICK) {
|
||||
s_launcher_selected = (s_launcher_selected + 1) % s_app_count;
|
||||
} else if (action == INPUT_ACTION_DOUBLE_CLICK) {
|
||||
if (s_launcher_selected == 0) {
|
||||
s_launcher_selected = s_app_count - 1;
|
||||
} else {
|
||||
s_launcher_selected--;
|
||||
}
|
||||
/* Tap 1 already stepped +1; stepping -2 results in a net -1 (previous entry) */
|
||||
s_launcher_selected = (s_launcher_selected + s_app_count - 2) % s_app_count;
|
||||
} else if (action == INPUT_ACTION_LONG_PRESS) {
|
||||
sys_app_launch_by_index(s_launcher_selected);
|
||||
}
|
||||
|
||||
@@ -7,11 +7,10 @@
|
||||
|
||||
static const char *TAG = "SYS_INPUT";
|
||||
|
||||
#define DEBOUNCE_TIME_MS 25
|
||||
#define CLICK_TIME_MAX_MS 350
|
||||
#define DOUBLE_CLICK_GAP_MS 280
|
||||
#define LONG_PRESS_TIME_MS 450
|
||||
#define HOME_PRESS_TIME_MS 1500
|
||||
#define DEBOUNCE_TIME_MS 12
|
||||
#define DOUBLE_CLICK_GAP_MS 260
|
||||
#define LONG_PRESS_TIME_MS 380
|
||||
#define HOME_PRESS_TIME_MS 1400
|
||||
|
||||
typedef struct {
|
||||
sys_input_handler_t handler;
|
||||
@@ -69,48 +68,43 @@ esp_err_t sys_input_register_handler(sys_input_handler_t handler, void *user_arg
|
||||
|
||||
static void button_scanner_task(void *pvParameters)
|
||||
{
|
||||
bool last_state = true;
|
||||
bool last_state = false;
|
||||
uint32_t press_start_ms = 0;
|
||||
uint32_t release_time_ms = 0;
|
||||
uint8_t click_count = 0;
|
||||
uint32_t last_click_time_ms = 0;
|
||||
bool long_press_fired = false;
|
||||
bool home_press_fired = false;
|
||||
|
||||
while (1) {
|
||||
vTaskDelay(pdMS_TO_TICKS(10));
|
||||
vTaskDelay(pdMS_TO_TICKS(5)); // High-rate 200 Hz scan loop for zero input lag
|
||||
uint32_t now_ms = (uint32_t)(esp_timer_get_time() / 1000ULL);
|
||||
bool current_state = (gpio_get_level(s_button_pin) == 0);
|
||||
|
||||
if (current_state && !last_state) {
|
||||
// Button pressed down
|
||||
press_start_ms = now_ms;
|
||||
long_press_fired = false;
|
||||
home_press_fired = false;
|
||||
} else if (current_state && last_state) {
|
||||
// Button held down
|
||||
uint32_t held_duration = now_ms - press_start_ms;
|
||||
if (!home_press_fired && held_duration >= HOME_PRESS_TIME_MS) {
|
||||
home_press_fired = true;
|
||||
click_count = 0;
|
||||
dispatch_action(INPUT_ACTION_HOLD_HOME);
|
||||
} else if (!long_press_fired && !home_press_fired && held_duration >= LONG_PRESS_TIME_MS) {
|
||||
long_press_fired = true;
|
||||
click_count = 0;
|
||||
dispatch_action(INPUT_ACTION_LONG_PRESS);
|
||||
}
|
||||
} else if (!current_state && last_state) {
|
||||
// Button released
|
||||
uint32_t press_duration = now_ms - press_start_ms;
|
||||
if (press_duration >= DEBOUNCE_TIME_MS && !long_press_fired && !home_press_fired) {
|
||||
click_count++;
|
||||
release_time_ms = now_ms;
|
||||
}
|
||||
} else if (!current_state && !last_state) {
|
||||
if (click_count > 0) {
|
||||
uint32_t idle_time = now_ms - release_time_ms;
|
||||
if (click_count >= 2) {
|
||||
if ((now_ms - last_click_time_ms) <= DOUBLE_CLICK_GAP_MS) {
|
||||
dispatch_action(INPUT_ACTION_DOUBLE_CLICK);
|
||||
click_count = 0;
|
||||
} else if (idle_time >= DOUBLE_CLICK_GAP_MS) {
|
||||
last_click_time_ms = 0;
|
||||
} else {
|
||||
// Instant click dispatch upon tap release (no 280ms lag penalty!)
|
||||
dispatch_action(INPUT_ACTION_CLICK);
|
||||
click_count = 0;
|
||||
last_click_time_ms = now_ms;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -142,6 +136,6 @@ esp_err_t sys_input_init(gpio_num_t button_gpio)
|
||||
return ESP_FAIL;
|
||||
}
|
||||
|
||||
ESP_LOGI(TAG, "Input gesture engine started on GPIO %d", (int)s_button_pin);
|
||||
ESP_LOGI(TAG, "Input gesture engine started on GPIO %d (Instant-Response Mode)", (int)s_button_pin);
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user