From 73c7b74a3a47fc1ad952ccb0fbf98d510ecd1aad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niccol=C3=B2=20Izzo?= Date: Wed, 30 Dec 2020 15:46:43 +0100 Subject: [PATCH] Add input parsing functions Input parsing functions are moved into input.c/input.h, and currently contain functions to determine if a number is pressed and to extract the pressed number. --- meson.build | 1 + openrtx/include/input.h | 40 ++++++++++++++++++++++++++++++++++++++++ openrtx/include/ui.h | 3 ++- openrtx/src/input.c | 36 ++++++++++++++++++++++++++++++++++++ openrtx/src/ui.c | 19 ++++++++++++++----- 5 files changed, 93 insertions(+), 6 deletions(-) create mode 100644 openrtx/include/input.h create mode 100644 openrtx/src/input.c diff --git a/meson.build b/meson.build index 888ddd8f..88448b40 100644 --- a/meson.build +++ b/meson.build @@ -17,6 +17,7 @@ openrtx_src = ['openrtx/src/bootstrap.c', 'openrtx/src/threads.c', 'openrtx/src/battery.c', 'openrtx/src/graphics.c', + 'openrtx/src/input.c', 'openrtx/src/calibUtils.c'] diff --git a/openrtx/include/input.h b/openrtx/include/input.h new file mode 100644 index 00000000..585c56b3 --- /dev/null +++ b/openrtx/include/input.h @@ -0,0 +1,40 @@ +/*************************************************************************** + * Copyright (C) 2020 by Federico Amedeo Izzo IU2NUO, * + * Niccolò Izzo IU2KIN, * + * Silvano Seva IU2KWO * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 3 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, see * + ***************************************************************************/ + +#ifndef INPUT_H +#define INPUT_H + +#include +#include + +/* This function returns true if at least one number is pressed on the + * keyboard. + * @param msg: the keyboard queue message + * @return true if at least a number is pressed on the keyboard + */ +bool input_isNumberPressed(kbd_msg_t msg); + +/* This function returns the smallest number that is pressed on the keyboard, + * 0 if none is pressed. + * @param msg: the keyboard queue message + * @return the smalled pressed number on the keyboard + */ +uint8_t input_getPressedNumber(kbd_msg_t msg); + +#endif /* INPUT_H */ diff --git a/openrtx/include/ui.h b/openrtx/include/ui.h index b79d1850..e751b539 100644 --- a/openrtx/include/ui.h +++ b/openrtx/include/ui.h @@ -28,7 +28,8 @@ enum uiScreen { - MAIN_VFO = 0, + VFO_MAIN = 0, + VFO_INPUT, MAIN_MEM, MENU_TOP, MENU_ZONE, diff --git a/openrtx/src/input.c b/openrtx/src/input.c new file mode 100644 index 00000000..0bfbf388 --- /dev/null +++ b/openrtx/src/input.c @@ -0,0 +1,36 @@ +/*************************************************************************** + * Copyright (C) 2020 by Federico Amedeo Izzo IU2NUO, * + * Niccolò Izzo IU2KIN, * + * Silvano Seva IU2KWO * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 3 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, see * + ***************************************************************************/ + +#include +#include +#include +#include + +bool input_isNumberPressed(kbd_msg_t msg) +{ + return msg.keys & kbd_num_mask; +} + +uint8_t input_getPressedNumber(kbd_msg_t msg) +{ + uint32_t masked_input = msg.keys & kbd_num_mask; + if (masked_input == 0) + return 0; + return __builtin_ctz(msg.keys & kbd_num_mask); +} diff --git a/openrtx/src/ui.c b/openrtx/src/ui.c index b176620b..67f59875 100644 --- a/openrtx/src/ui.c +++ b/openrtx/src/ui.c @@ -464,7 +464,7 @@ void ui_updateFSM(event_t event, bool *sync_rtx) { state.ui_screen = LOW_BAT; if(event.type == EVENT_KBD && event.payload) { - state.ui_screen = MAIN_VFO; + state.ui_screen = VFO_MAIN; state.emergency = true; } return; @@ -478,7 +478,7 @@ void ui_updateFSM(event_t event, bool *sync_rtx) switch(state.ui_screen) { // VFO screen - case MAIN_VFO: + case VFO_MAIN: if(msg.keys & KEY_UP) { // Advance TX and RX frequency of 12.5KHz @@ -496,6 +496,9 @@ void ui_updateFSM(event_t event, bool *sync_rtx) else if(msg.keys & KEY_ENTER) // Open Menu state.ui_screen = MENU_TOP; + else if(input_isNumberPressed(msg)) + // Open Frequency input screen + state.ui_screen = VFO_INPUT; break; // Top menu screen case MENU_TOP: @@ -531,7 +534,7 @@ void ui_updateFSM(event_t event, bool *sync_rtx) else if(msg.keys & KEY_ESC) { // Close Menu - state.ui_screen = MAIN_VFO; + state.ui_screen = VFO_MAIN; // Reset menu selection menu_selected = 0; } @@ -587,10 +590,16 @@ bool ui_updateGUI(state_t last_state) // Draw current GUI page switch(last_state.ui_screen) { - // VFO screen - case MAIN_VFO: + // VFO main screen + case VFO_MAIN: screen_update = _ui_drawMainVFO(&last_state); break; + // VFO frequency input screen + case VFO_INPUT: + screen_update = _ui_drawMainVFO(&last_state); + gfx_print(layout.top_pos, "VFO INPUT", layout.top_font, TEXT_ALIGN_CENTER, + color_white); + break; // Top menu screen case MENU_TOP: _ui_drawMenuTop();