From 73c9ab56a65789aa1bd974f943e12f55f1f38ee1 Mon Sep 17 00:00:00 2001 From: Federico Amedeo Izzo Date: Sun, 10 Jan 2021 10:18:29 +0100 Subject: [PATCH] UI: Channel mode: load channel from cps and do basic validation --- openrtx/include/state.h | 1 + openrtx/src/ui/ui.c | 20 ++++++++++++++++++-- openrtx/src/ui/ui_main.c | 5 ++++- platform/drivers/NVM/nvmem_linux.c | 8 +++++--- 4 files changed, 28 insertions(+), 6 deletions(-) diff --git a/openrtx/include/state.h b/openrtx/include/state.h index b183ee20..080ad6b3 100644 --- a/openrtx/include/state.h +++ b/openrtx/include/state.h @@ -48,6 +48,7 @@ typedef struct //bool tx_status; bool channelInfoUpdated; + uint16_t channel_index; channel_t channel; uint8_t rtxStatus; uint8_t sqlLevel; diff --git a/openrtx/src/ui/ui.c b/openrtx/src/ui/ui.c index 90d1e54c..abe365dd 100644 --- a/openrtx/src/ui/ui.c +++ b/openrtx/src/ui/ui.c @@ -366,6 +366,12 @@ bool _ui_freq_check_limits(freq_t freq) return valid; } +bool _ui_channel_valid(channel_t* channel) +{ +return _ui_freq_check_limits(channel->rx_frequency) && + _ui_freq_check_limits(channel->tx_frequency); +} + bool _ui_drawDarkOverlay() { // TODO: Make this 245 alpha and fix alpha frame swap color_t alpha_grey = {0, 0, 0, 255}; @@ -428,8 +434,18 @@ void ui_updateFSM(event_t event, bool *sync_rtx) } else if(msg.keys & KEY_ESC) { - // Switch to MEM screen - state.ui_screen = MAIN_MEM; + // Try to load selected channel + channel_t channel; + int result = nvm_readChannelData(&channel, state.channel_index); + // Read successful and channel is valid + if(result != -1 && _ui_channel_valid(&channel)) + { + // Copy channel read to state + state.channel = channel; + *sync_rtx = true; + // Switch to MEM screen + state.ui_screen = MAIN_MEM; + } } else if(input_isNumberPressed(msg)) { diff --git a/openrtx/src/ui/ui_main.c b/openrtx/src/ui/ui_main.c index 1037c114..756400d0 100644 --- a/openrtx/src/ui/ui_main.c +++ b/openrtx/src/ui/ui_main.c @@ -89,7 +89,10 @@ void _ui_drawVFOMiddle(state_t* last_state) void _ui_drawMEMMiddle(state_t* last_state) { - // Print VFO frequencies + // Print Channel name + gfx_print(layout.line1_left, last_state->channel.name, layout.line1_font, TEXT_ALIGN_CENTER, + color_white); + // Print Channel frequencies char freq_buf[20] = ""; snprintf(freq_buf, sizeof(freq_buf), " Rx:%03u.%05u", last_state->channel.rx_frequency/1000000, diff --git a/platform/drivers/NVM/nvmem_linux.c b/platform/drivers/NVM/nvmem_linux.c index ffac0078..768fe302 100644 --- a/platform/drivers/NVM/nvmem_linux.c +++ b/platform/drivers/NVM/nvmem_linux.c @@ -22,6 +22,7 @@ // Simulate CPS with 8 channels const uint32_t maxNumChannels = 8; +const freq_t dummy_base_freq = 145500000; void nvm_init() { @@ -35,10 +36,11 @@ int nvm_readChannelData(channel_t *channel, uint16_t pos) { if(pos > maxNumChannels) return -1; - /* - * Generate dummy channel name - */ + /* Generate dummy channel name */ snprintf(channel->name, 16, "Channel %d", pos); + /* Generate dummy frequency values */ + channel->rx_frequency = dummy_base_freq + pos * 100000; + channel->tx_frequency = dummy_base_freq + pos * 100000; return 0; }