UI: Add initial menu support

replace/6602a19d85af0b3e0645d62f55c68695bf97522d
Federico Amedeo Izzo 2020-12-06 20:31:06 +01:00
rodzic 2f05bbc6ff
commit 8b1d688935
4 zmienionych plików z 98 dodań i 41 usunięć

Wyświetl plik

@ -37,7 +37,7 @@ typedef struct
curTime_t time;
float v_bat;
//enum ui_screen;
uint8_t ui_screen;
//enum tuner_mode;
//enum radio_mode;

Wyświetl plik

@ -26,19 +26,37 @@
#include <stdint.h>
#include <event.h>
enum uiScreen
{
MAIN_VFO = 0,
MAIN_MEM,
MENU_TOP,
MENU_ZONE,
MENU_CHANNEL,
MENU_CONTACTS,
MENU_SMS,
MENU_GPS,
MENU_SETTINGS
};
/**
* This function initialises the User Interface, starting the
* Finite State Machine describing the user interaction.
*/
void ui_init();
/**
* This function writes the OpenRTX splash screen image into the framebuffer.
*/
void ui_drawSplashScreen();
/**
* This function advances the User Interface FSM, basing on the
* current radio state and the keys pressed.
* @param last_state: A local copy of the previous radio state
* @param event: An event from other threads
*/
void ui_updateFSM(state_t last_state, event_t event);
void ui_updateFSM(event_t event);
/**
* This function redraws the GUI based on the last radio state.
@ -47,11 +65,6 @@ void ui_updateFSM(state_t last_state, event_t event);
*/
bool ui_updateGUI(state_t last_state);
/**
* This function writes the OpenRTX splash screen image into the framebuffer.
*/
void ui_drawSplashScreen();
/**
* This function terminates the User Interface.
*/

Wyświetl plik

@ -117,7 +117,7 @@ static void ui_task(void *arg)
// Lock mutex, read and write state
OSMutexPend(&state_mutex, 0u, OS_OPT_PEND_BLOCKING, 0u, &os_err);
// React to keypresses and update FSM inside state
ui_updateFSM(last_state, event);
ui_updateFSM(event);
// Update state local copy
last_state = state;
// Unlock mutex

Wyświetl plik

@ -204,17 +204,17 @@ void _ui_drawBackground()
gfx_drawHLine(SCREEN_HEIGHT - layout.bottom_h - 1, 1, color_grey);
}
void _ui_drawTopBar(state_t* state)
void _ui_drawTopBar(state_t* last_state)
{
// Print clock on top bar
char clock_buf[9] = "";
snprintf(clock_buf, sizeof(clock_buf), "%02d:%02d:%02d", state->time.hour,
state->time.minute, state->time.second);
snprintf(clock_buf, sizeof(clock_buf), "%02d:%02d:%02d", last_state->time.hour,
last_state->time.minute, last_state->time.second);
gfx_print(layout.top_pos, clock_buf, layout.top_font, TEXT_ALIGN_CENTER,
color_white);
// Print battery icon on top bar, use 4 px padding
float percentage = state->v_bat / MAX_VBAT;
float percentage = last_state->v_bat / MAX_VBAT;
uint16_t bat_width = SCREEN_WIDTH / 9;
uint16_t bat_height = layout.top_h - layout.vertical_pad;
point_t bat_pos = {SCREEN_WIDTH - bat_width - layout.horizontal_pad,
@ -222,20 +222,20 @@ void _ui_drawTopBar(state_t* state)
gfx_drawBattery(bat_pos, bat_width, bat_height, percentage);
}
void _ui_drawVFO(state_t* state)
void _ui_drawMiddleVFO(state_t* last_state)
{
// Print VFO frequencies
char freq_buf[20] = "";
snprintf(freq_buf, sizeof(freq_buf), "Rx: %03ld.%05ld",
state->channel.rx_frequency/1000000,
state->channel.rx_frequency%1000000/10);
snprintf(freq_buf, sizeof(freq_buf), "Rx: %03d.%05d",
last_state->channel.rx_frequency/1000000,
last_state->channel.rx_frequency%1000000/10);
gfx_print(layout.line2_pos, freq_buf, layout.line1_font, TEXT_ALIGN_CENTER,
color_white);
snprintf(freq_buf, sizeof(freq_buf), "Tx: %03ld.%05ld",
state->channel.tx_frequency/1000000,
state->channel.tx_frequency%1000000/10);
snprintf(freq_buf, sizeof(freq_buf), "Tx: %03d.%05d",
last_state->channel.tx_frequency/1000000,
last_state->channel.tx_frequency%1000000/10);
gfx_print(layout.line3_pos, freq_buf, layout.line2_font, TEXT_ALIGN_CENTER,
color_white);
@ -247,7 +247,7 @@ void _ui_drawBottomBar()
TEXT_ALIGN_CENTER, color_white);
}
bool ui_drawMainScreen(state_t last_state)
bool _ui_drawMainVFO(state_t* last_state)
{
bool screen_update = false;
// Total GUI redraw
@ -255,25 +255,39 @@ bool ui_drawMainScreen(state_t last_state)
{
gfx_clearScreen();
_ui_drawBackground();
_ui_drawTopBar(&last_state);
_ui_drawVFO(&last_state);
_ui_drawTopBar(last_state);
_ui_drawMiddleVFO(last_state);
_ui_drawBottomBar();
screen_update = true;
}
// Partial GUI redraw
// Partial GUI page redraw
// TODO: until gfx_clearRows() is implemented, we need to redraw everything
else
{
gfx_clearScreen();
_ui_drawBackground();
_ui_drawTopBar(&last_state);
_ui_drawVFO(&last_state);
_ui_drawTopBar(last_state);
_ui_drawMiddleVFO(last_state);
_ui_drawBottomBar();
screen_update = true;
}
return screen_update;
}
bool _ui_drawMenuTop()
{
bool screen_update = false;
// Total GUI page redraw
if(redraw_needed)
{
gfx_clearScreen();
gfx_print(layout.top_pos, "Menu", layout.top_font,
TEXT_ALIGN_CENTER, color_white);
screen_update = true;
}
return screen_update;
}
void ui_init()
{
redraw_needed = true;
@ -296,27 +310,45 @@ void ui_drawSplashScreen()
#endif
}
void ui_updateFSM(state_t last_state, event_t event)
void ui_updateFSM(event_t event)
{
(void) last_state;
// Process pressed keys
if(event.type == EVENT_KBD)
{
keyboard_t keys = event.payload;
// Temporary VFO controls
if(keys & KEY_UP)
switch(state.ui_screen)
{
// Advance TX and RX frequency of 12.5KHz
state.channel.rx_frequency += 12500;
state.channel.tx_frequency += 12500;
}
if(keys & KEY_DOWN)
{
// Advance TX and RX frequency of 12.5KHz
state.channel.rx_frequency -= 12500;
state.channel.tx_frequency -= 12500;
// VFO screen
case MAIN_VFO:
// Temporary VFO controls
if(keys & KEY_UP)
{
// Advance TX and RX frequency of 12.5KHz
state.channel.rx_frequency += 12500;
state.channel.tx_frequency += 12500;
}
else if(keys & KEY_DOWN)
{
// Advance TX and RX frequency of 12.5KHz
state.channel.rx_frequency -= 12500;
state.channel.tx_frequency -= 12500;
}
else if(keys & KEY_ENTER)
// Open Menu
state.ui_screen = MENU_TOP;
break;
// Top menu screen
case MENU_TOP:
if(keys & KEY_UP)
{
}
else if(keys & KEY_DOWN)
{
}
else if(keys & KEY_ESC)
// Close Menu
state.ui_screen = MAIN_VFO;
break;
}
}
}
@ -328,7 +360,19 @@ bool ui_updateGUI(state_t last_state)
layout = _ui_calculateLayout();
layout_ready = true;
}
bool screen_update = ui_drawMainScreen(last_state);
bool screen_update = false;
// Draw current GUI page
switch(last_state.ui_screen)
{
// VFO screen
case MAIN_VFO:
screen_update = _ui_drawMainVFO(&last_state);
break;
// Top menu screen
case MENU_TOP:
screen_update = _ui_drawMenuTop();
break;
}
return screen_update;
}