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.
replace/842f6307048759926d7f52e332071adb0f376079
Niccolò Izzo 2020-12-30 15:46:43 +01:00
rodzic d4bc1bbd9c
commit 73c7b74a3a
5 zmienionych plików z 93 dodań i 6 usunięć

Wyświetl plik

@ -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']

Wyświetl plik

@ -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 <http://www.gnu.org/licenses/> *
***************************************************************************/
#ifndef INPUT_H
#define INPUT_H
#include <inttypes.h>
#include <stdbool.h>
/* 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 */

Wyświetl plik

@ -28,7 +28,8 @@
enum uiScreen
{
MAIN_VFO = 0,
VFO_MAIN = 0,
VFO_INPUT,
MAIN_MEM,
MENU_TOP,
MENU_ZONE,

Wyświetl plik

@ -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 <http://www.gnu.org/licenses/> *
***************************************************************************/
#include <interfaces/keyboard.h>
#include <inttypes.h>
#include <stdbool.h>
#include <input.h>
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);
}

Wyświetl plik

@ -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();