mirror of
https://github.com/OpenRTX/OpenRTX
synced 2026-08-08 12:29:06 -04:00
core: input: format to new coding style
Signed-off-by: Joshua Murphy <hello@joshmurphy.ca>
This commit is contained in:
parent
b01a995f3e
commit
df9700a62f
3 changed files with 24 additions and 33 deletions
|
|
@ -26,19 +26,15 @@ static const uint16_t input_longPressTimeout = 700;
|
|||
* For a keyboard event we use 1 bit to signal a short or long press
|
||||
* And the remaining 29 bits to communicate currently pressed keys.
|
||||
*/
|
||||
typedef union
|
||||
{
|
||||
struct
|
||||
{
|
||||
uint32_t long_press : 1,
|
||||
keys : 29,
|
||||
_padding : 2;
|
||||
typedef union {
|
||||
struct {
|
||||
uint32_t long_press : 1;
|
||||
uint32_t keys : 29;
|
||||
uint32_t _padding : 2;
|
||||
};
|
||||
|
||||
uint32_t value;
|
||||
}
|
||||
kbd_msg_t;
|
||||
|
||||
} kbd_msg_t;
|
||||
|
||||
/**
|
||||
* Scan all the keyboard buttons to detect possible keypresses filling a
|
||||
|
|
|
|||
|
|
@ -9,31 +9,28 @@
|
|||
#include <stdbool.h>
|
||||
#include "core/input.h"
|
||||
|
||||
static long long keyTs[KBD_NUM_KEYS]; // Timestamp of each keypress
|
||||
static uint32_t longPressSent; // Flags to manage long-press events
|
||||
static keyboard_t prevKeys = 0; // Previous keyboard status
|
||||
static long long keyTs[KBD_NUM_KEYS]; // Timestamp of each keypress
|
||||
static uint32_t longPressSent; // Flags to manage long-press events
|
||||
static keyboard_t prevKeys = 0; // Previous keyboard status
|
||||
|
||||
bool input_scanKeyboard(kbd_msg_t *msg)
|
||||
{
|
||||
msg->value = 0;
|
||||
msg->value = 0;
|
||||
bool kbd_event = false;
|
||||
|
||||
keyboard_t keys = kbd_getKeys();
|
||||
long long now = getTick();
|
||||
long long now = getTick();
|
||||
|
||||
// The key status has changed
|
||||
if(keys != prevKeys)
|
||||
{
|
||||
if (keys != prevKeys) {
|
||||
// Find newly pressed keys
|
||||
keyboard_t newKeys = (keys ^ prevKeys) & keys;
|
||||
|
||||
// Save timestamp
|
||||
for(uint8_t k = 0; k < KBD_NUM_KEYS; k++)
|
||||
{
|
||||
for (uint8_t k = 0; k < KBD_NUM_KEYS; k++) {
|
||||
keyboard_t mask = 1 << k;
|
||||
if((newKeys & mask) != 0)
|
||||
{
|
||||
keyTs[k] = now;
|
||||
if ((newKeys & mask) != 0) {
|
||||
keyTs[k] = now;
|
||||
longPressSent &= ~mask;
|
||||
}
|
||||
}
|
||||
|
|
@ -43,22 +40,18 @@ bool input_scanKeyboard(kbd_msg_t *msg)
|
|||
kbd_event = true;
|
||||
}
|
||||
// Some key is kept pressed
|
||||
else if(keys != 0)
|
||||
{
|
||||
else if (keys != 0) {
|
||||
// Check for saved timestamp to trigger long-presses
|
||||
for(uint8_t k = 0; k < KBD_NUM_KEYS; k++)
|
||||
{
|
||||
for (uint8_t k = 0; k < KBD_NUM_KEYS; k++) {
|
||||
keyboard_t mask = 1 << k;
|
||||
|
||||
// The key is pressed and its long-press timer is over
|
||||
if(((keys & mask) != 0) &&
|
||||
((longPressSent & mask) == 0) &&
|
||||
((now - keyTs[k]) >= input_longPressTimeout))
|
||||
{
|
||||
if (((keys & mask) != 0) && ((longPressSent & mask) == 0)
|
||||
&& ((now - keyTs[k]) >= input_longPressTimeout)) {
|
||||
msg->long_press = 1;
|
||||
msg->keys = keys;
|
||||
kbd_event = true;
|
||||
longPressSent |= mask;
|
||||
msg->keys = keys;
|
||||
kbd_event = true;
|
||||
longPressSent |= mask;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -44,6 +44,7 @@ openrtx/include/core/crc.h
|
|||
openrtx/include/core/dsp.h
|
||||
openrtx/include/core/data_conversion.h
|
||||
openrtx/include/core/datatypes.h
|
||||
openrtx/include/core/input.h
|
||||
openrtx/include/core/memory_profiling.h
|
||||
openrtx/include/core/nvmem_access.h
|
||||
openrtx/include/core/nvmem_device.h
|
||||
|
|
@ -68,6 +69,7 @@ openrtx/include/ui/utils.h
|
|||
openrtx/src/core/crc.c
|
||||
openrtx/src/core/dsp.cpp
|
||||
openrtx/src/core/audio_codec.c
|
||||
openrtx/src/core/input.c
|
||||
openrtx/src/core/nvmem_access.c
|
||||
openrtx/src/core/memory_profiling.cpp
|
||||
openrtx/src/protocols/M17/Callsign.cpp
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue