diff --git a/openrtx/include/core/input.h b/openrtx/include/core/input.h index 65fc5b8d..dbcb50f0 100644 --- a/openrtx/include/core/input.h +++ b/openrtx/include/core/input.h @@ -68,6 +68,15 @@ bool input_scanKeyboard(kbd_msg_t *msg); */ bool input_isNumberPressed(kbd_msg_t msg); +/** + * This function returns true if at least one character is pressed on the + * keyboard. + * + * @param msg: the keyboard queue message + * @return true if at least a char is pressed on the keyboard + */ +bool input_isCharPressed(kbd_msg_t msg); + /** * This function returns the smallest number that is pressed on the keyboard, * 0 if none is pressed. @@ -77,4 +86,13 @@ bool input_isNumberPressed(kbd_msg_t msg); */ uint8_t input_getPressedNumber(kbd_msg_t msg); +/** + * This function returns the smallest number pressed on the keyboard and + * associated to character. If no button is pressed, zero is returned. + * + * @param msg: the keyboard queue message + * @return the smallest number associated to a char. + */ +uint8_t input_getPressedChar(kbd_msg_t msg); + #endif /* INPUT_H */ diff --git a/openrtx/include/interfaces/keyboard.h b/openrtx/include/interfaces/keyboard.h index 47adb7b5..23bf6ae3 100644 --- a/openrtx/include/interfaces/keyboard.h +++ b/openrtx/include/interfaces/keyboard.h @@ -67,10 +67,15 @@ enum key /** * Mask for the numeric keys in a key map - * Numeric keys: bit0->bit11 = 0xFFF + * Numeric keys: bit0->bit9 = 0x3FF */ -#define KBD_NUM_MASK 0x0FFF +#define KBD_NUM_MASK 0x03FF +/** + * Mask for the chars keys in a key map + * Char keys: bit0->bit11 = 0xFFF + */ +#define KBD_CHAR_MASK 0x0FFF /** * We encode the status of all the keys with a uint32_t value * To check which buttons are pressed one can bit-mask the diff --git a/openrtx/src/core/input.c b/openrtx/src/core/input.c index 30148d99..7ce5e8cb 100644 --- a/openrtx/src/core/input.c +++ b/openrtx/src/core/input.c @@ -86,6 +86,11 @@ bool input_isNumberPressed(kbd_msg_t msg) return msg.keys & KBD_NUM_MASK; } +bool input_isCharPressed(kbd_msg_t msg) +{ + return msg.keys & KBD_CHAR_MASK; +} + uint8_t input_getPressedNumber(kbd_msg_t msg) { uint32_t masked_input = msg.keys & KBD_NUM_MASK; @@ -94,3 +99,12 @@ uint8_t input_getPressedNumber(kbd_msg_t msg) return __builtin_ctz(msg.keys & KBD_NUM_MASK); } + +uint8_t input_getPressedChar(kbd_msg_t msg) +{ + uint32_t masked_input = msg.keys & KBD_CHAR_MASK; + if (masked_input == 0) + return 0; + + return __builtin_ctz(msg.keys & KBD_CHAR_MASK); +} diff --git a/openrtx/src/ui/default/ui.c b/openrtx/src/ui/default/ui.c index 8b8afecf..1c36e7a9 100644 --- a/openrtx/src/ui/default/ui.c +++ b/openrtx/src/ui/default/ui.c @@ -1095,7 +1095,7 @@ static void _ui_textInputKeypad(char *buf, uint8_t max_len, kbd_msg_t msg, { long long now = getTick(); // Get currently pressed number key - uint8_t num_key = input_getPressedNumber(msg); + uint8_t num_key = input_getPressedChar(msg); bool key_timeout = ((now - ui_state.last_keypress) >= input_longPressTimeout); bool same_key = ui_state.input_number == num_key; @@ -1476,7 +1476,7 @@ void ui_updateFSM(bool *sync_rtx) else if(msg.keys & KEY_UP || msg.keys & KEY_DOWN || msg.keys & KEY_LEFT || msg.keys & KEY_RIGHT) _ui_textInputDel(ui_state.new_callsign); - else if(input_isNumberPressed(msg)) + else if(input_isCharPressed(msg)) _ui_textInputKeypad(ui_state.new_callsign, 9, msg, true); break; } @@ -1682,7 +1682,7 @@ void ui_updateFSM(bool *sync_rtx) else if(msg.keys & KEY_UP || msg.keys & KEY_DOWN || msg.keys & KEY_LEFT || msg.keys & KEY_RIGHT) _ui_textInputDel(ui_state.new_callsign); - else if(input_isNumberPressed(msg)) + else if(input_isCharPressed(msg)) _ui_textInputKeypad(ui_state.new_callsign, 9, msg, true); break; } @@ -2263,7 +2263,7 @@ void ui_updateFSM(bool *sync_rtx) { _ui_textInputDel(ui_state.new_callsign); } - else if(input_isNumberPressed(msg)) + else if(input_isCharPressed(msg)) { _ui_textInputKeypad(ui_state.new_callsign, 9, msg, true); }