UI: Channel mode: load channel from cps and do basic validation

This commit is contained in:
Federico Amedeo Izzo 2021-01-10 10:18:29 +01:00
parent 3365fe4d2f
commit 73c9ab56a6
4 changed files with 28 additions and 6 deletions

View File

@ -48,6 +48,7 @@ typedef struct
//bool tx_status;
bool channelInfoUpdated;
uint16_t channel_index;
channel_t channel;
uint8_t rtxStatus;
uint8_t sqlLevel;

View File

@ -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))
{

View File

@ -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,

View File

@ -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;
}