From d102fcd6b0e35e3a9aef59c82238d27b214835fc Mon Sep 17 00:00:00 2001 From: z4yx Date: Mon, 22 Apr 2024 13:24:33 +0800 Subject: [PATCH] support long touch --- Src/device.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/Src/device.c b/Src/device.c index d224bc1..78b3953 100644 --- a/Src/device.c +++ b/Src/device.c @@ -127,25 +127,27 @@ void device_periodic_task(void) { if (LL_USART_IsActiveFlag_RXNE(DBG_UART.Instance)) { int data = LL_USART_ReceiveData8(DBG_UART.Instance); DBG_MSG("UART: %x\n", data); - if ('T' == data) { - set_touch_result(TOUCH_SHORT); + if ('T' == data || 'L' == data) { + set_touch_result('T' == data ? TOUCH_SHORT : TOUCH_LONG); fsm = TOUCH_STATE_ASSERT; event_tick = tick; } } #endif if(GPIO_Touched()) { + measure_touch = 0; fsm = TOUCH_STATE_DOWN; event_tick = tick; } break; case TOUCH_STATE_DOWN: - if(!GPIO_Touched()) { - fsm = TOUCH_STATE_IDLE; - } else if (tick - event_tick > 50) { - set_touch_result(TOUCH_SHORT); - fsm = TOUCH_STATE_ASSERT; - event_tick = tick; + if(!GPIO_Touched() || tick - event_tick > 500) { + if (tick - event_tick > 50) { + set_touch_result(tick - event_tick > 500 ? TOUCH_LONG : TOUCH_SHORT); + fsm = TOUCH_STATE_ASSERT; + event_tick = tick; + } else + fsm = TOUCH_STATE_IDLE; } break; case TOUCH_STATE_ASSERT: