Keyboard: Do not send event bursts after long press

replace/98a7545b79d8aead4ec989fc6bc868a38567e74a
Federico Amedeo Izzo 2021-01-04 13:45:27 +01:00 zatwierdzone przez Niccolò Izzo
rodzic 2dcefb7c0e
commit 04a8e2025e
1 zmienionych plików z 6 dodań i 1 usunięć

Wyświetl plik

@ -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;
}
}
}