Skip to content

Commit

Permalink
optimize touch detection
Browse files Browse the repository at this point in the history
  • Loading branch information
z4yx committed Apr 24, 2024
1 parent 026bd49 commit d481ff9
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions Src/device.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit d481ff9

Please sign in to comment.