From d481ff9ee6722f2afe25c57def232b9aa33ffdf6 Mon Sep 17 00:00:00 2001 From: z4yx Date: Wed, 24 Apr 2024 21:53:12 +0800 Subject: [PATCH] optimize touch detection --- Src/device.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Src/device.c b/Src/device.c index 78b3953..4793945 100644 --- a/Src/device.c +++ b/Src/device.c @@ -14,7 +14,9 @@ const uint32_t UNTOUCHED_MAX_VAL = 40; /* Suitable for 56K pull-down resistor */ const uint32_t CALI_TIMES = 4; -const uint32_t TOUCH_GAP_TIME = 1500; /* Gap period (in ms) between two consecutive touch events */ +const uint32_t TOUCH_GAP_TIME = 800; /* Gap period (in ms) between two consecutive touch events */ +const uint32_t MIN_LONG_TOUCH_TIME = 500; +const uint32_t MIN_TOUCH_TIME = 20; extern TIM_HandleTypeDef htim6; extern SPI_HandleTypeDef FM_SPI; @@ -141,9 +143,9 @@ void device_periodic_task(void) { } break; case TOUCH_STATE_DOWN: - if(!GPIO_Touched() || tick - event_tick > 500) { - if (tick - event_tick > 50) { - set_touch_result(tick - event_tick > 500 ? TOUCH_LONG : TOUCH_SHORT); + if(!GPIO_Touched() || tick - event_tick > MIN_LONG_TOUCH_TIME) { + if (tick - event_tick > MIN_TOUCH_TIME) { + set_touch_result(tick - event_tick > MIN_LONG_TOUCH_TIME ? TOUCH_LONG : TOUCH_SHORT); fsm = TOUCH_STATE_ASSERT; event_tick = tick; } else