From 04a8e2025ef6352b69818e55ba9e4c33f5fb2ed6 Mon Sep 17 00:00:00 2001 From: Federico Amedeo Izzo Date: Mon, 4 Jan 2021 13:45:27 +0100 Subject: [PATCH] Keyboard: Do not send event bursts after long press --- openrtx/src/threads.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/openrtx/src/threads.c b/openrtx/src/threads.c index 2db9e644..a64efc89 100644 --- a/openrtx/src/threads.c +++ b/openrtx/src/threads.c @@ -155,6 +155,9 @@ static void kbd_task(void *arg) OS_TICK key_ts[kbd_num_keys]; OS_TICK now; + // Allocate bool array to send only one long-press event + bool long_press_sent[kbd_num_keys]; + // Variable for saving previous and current keyboard status keyboard_t prev_keys = 0; keyboard_t keys = 0; @@ -182,6 +185,7 @@ static void kbd_task(void *arg) // Save timestamp key_ts[k] = now; send_event = true; + long_press_sent[k] = false; } // Key has been released else if((prev_keys & (1 << k)) && !(keys & (1 << k))) @@ -197,10 +201,11 @@ static void kbd_task(void *arg) for(uint8_t k=0; k < kbd_num_keys; k++) { // The key is pressed and its long-press timer is over - if(keys & (1 << k) && (now - key_ts[k]) >= kbd_long_interval) + if(keys & (1 << k) && !long_press_sent[k] && (now - key_ts[k]) >= kbd_long_interval) { long_press = true; send_event = true; + long_press_sent[k] = true; } } }