From 438540290bea0a24b3a04ca9c81fec6ea2b66625 Mon Sep 17 00:00:00 2001 From: Federico Amedeo Izzo Date: Sun, 31 Jan 2021 14:14:54 +0100 Subject: [PATCH] UI: Add MEM channel filtering per zone --- openrtx/include/state.h | 2 ++ openrtx/src/state.c | 6 ++++-- openrtx/src/ui/ui.c | 39 +++++++++++++++++++++++++++++++++++++-- openrtx/src/ui/ui_main.c | 18 +++++++++--------- openrtx/src/ui/ui_menu.c | 17 +++++++++++++---- 5 files changed, 65 insertions(+), 17 deletions(-) diff --git a/openrtx/include/state.h b/openrtx/include/state.h index 4cd03fd3..47a28055 100644 --- a/openrtx/include/state.h +++ b/openrtx/include/state.h @@ -52,6 +52,8 @@ typedef struct uint16_t channel_index; channel_t channel; channel_t vfo_channel; + bool zone_enabled; + zone_t zone; uint8_t rtxStatus; // Squelch steps from 0 to 15 uint8_t sqlLevel; diff --git a/openrtx/src/state.c b/openrtx/src/state.c index 036e8b8c..882973bd 100644 --- a/openrtx/src/state.c +++ b/openrtx/src/state.c @@ -19,6 +19,7 @@ ***************************************************************************/ #include +#include #include #include #include @@ -39,7 +40,8 @@ void state_init() state.v_bat = platform_getVbat(); state.charge = battery_getCharge(state.v_bat); state.rssi = rtx_getRssi(); - + + // Set VFO channel default settings state.channelInfoUpdated = true; state.channel.mode = FM; state.channel.bandwidth = BW_25; @@ -50,7 +52,7 @@ void state_init() state.channel.fm.rxTone = 2; // 71.9Hz state.channel.fm.txToneEn = 1; state.channel.fm.txTone = 2; // 71.9Hz - + state.zone_enabled = false; state.rtxStatus = RTX_OFF; #ifdef HAS_ABSOLUTE_KNOB // If the radio has an absolute position knob state.sqlLevel = platform_getChSelector() - 1; diff --git a/openrtx/src/ui/ui.c b/openrtx/src/ui/ui.c index ac321383..9e6b782b 100644 --- a/openrtx/src/ui/ui.c +++ b/openrtx/src/ui/ui.c @@ -436,8 +436,17 @@ bool _ui_drawDarkOverlay() { } int _ui_fsm_loadChannel(uint16_t index, bool *sync_rtx) { - // Try to load selected channel channel_t channel; + // If a zone is active, get index from current zone + if(state.zone_enabled) + { + // Calculate zone size + const uint8_t zone_size = sizeof(state.zone.member)/sizeof(state.zone.member[0]); + if(index >= zone_size) + return -1; + else + index = state.zone.member[index]; + } int result = nvm_readChannelData(&channel, index); // Read successful and channel is valid if(result != -1 && _ui_channel_valid(&channel)) @@ -830,7 +839,8 @@ void ui_updateFSM(event_t event, bool *sync_rtx) if(state.ui_screen == MENU_ZONE) { zone_t zone; - if(nvm_readZoneData(&zone, ui_state.menu_selected + 1) != -1) + // The index is -1 because the first zone "All channels" is not read from flash + if(nvm_readZoneData(&zone, ui_state.menu_selected) != -1) ui_state.menu_selected += 1; } else if(state.ui_screen == MENU_CHANNEL) @@ -848,6 +858,31 @@ void ui_updateFSM(event_t event, bool *sync_rtx) } else if(msg.keys & KEY_ENTER) { + if(state.ui_screen == MENU_ZONE) + { + zone_t newzone; + int result = 0; + // If "All channels" is selected, load default zone + if(ui_state.menu_selected == 0) + state.zone_enabled = false; + else + { + state.zone_enabled = true; + // The index is -1 because the first zone "All channels" is not read from flash + result = nvm_readZoneData(&newzone, ui_state.menu_selected - 1); + } + if(result != -1) + { + state.zone = newzone; + // If we were in VFO mode, save VFO channel + if(ui_state.last_main_state == MAIN_VFO) + state.vfo_channel = state.channel; + // Load zone first channel + _ui_fsm_loadChannel(0, sync_rtx); + // Switch to MEM screen + state.ui_screen = MAIN_MEM; + } + } if(state.ui_screen == MENU_CHANNEL) { // If we were in VFO mode, save VFO channel diff --git a/openrtx/src/ui/ui_main.c b/openrtx/src/ui/ui_main.c index 3b132271..63bb509c 100644 --- a/openrtx/src/ui/ui_main.c +++ b/openrtx/src/ui/ui_main.c @@ -64,18 +64,18 @@ void _ui_drawMainTop() color_white); } -void _ui_drawZoneChannel(bool print_zone) +void _ui_drawZoneChannel() { - if(print_zone) - { - char zone_buf[20] = ""; - snprintf(zone_buf, sizeof(zone_buf), "zone: %.13s", "Test Zone"); - // Print Zone name - gfx_print(layout.line1_pos, zone_buf, layout.line1_font, TEXT_ALIGN_LEFT, color_white); - } + char zone_buf[20] = ""; char channel_buf[20] = ""; + if(!last_state.zone_enabled) + snprintf(zone_buf, sizeof(zone_buf), "zone: %.13s", "All channels"); + else + snprintf(zone_buf, sizeof(zone_buf), "zone: %.13s", last_state.zone.name); snprintf(channel_buf, sizeof(channel_buf), " %03d: %.12s", last_state.channel_index, last_state.channel.name); + // Print Zone name + gfx_print(layout.line1_pos, zone_buf, layout.line1_font, TEXT_ALIGN_LEFT, color_white); // Print Channel name gfx_print(layout.line2_pos, channel_buf, layout.line2_font, TEXT_ALIGN_LEFT, color_white); } @@ -183,7 +183,7 @@ void _ui_drawMainMEM() { gfx_clearScreen(); _ui_drawMainTop(); - _ui_drawZoneChannel(false); + _ui_drawZoneChannel(); _ui_drawFrequency(); _ui_drawBottom(); } diff --git a/openrtx/src/ui/ui_menu.c b/openrtx/src/ui/ui_menu.c index e1e097c6..9e64d81a 100644 --- a/openrtx/src/ui/ui_menu.c +++ b/openrtx/src/ui/ui_menu.c @@ -147,10 +147,19 @@ int _ui_getInfoValueName(char *buf, uint8_t max_len, uint8_t index) } int _ui_getZoneName(char *buf, uint8_t max_len, uint8_t index) { - zone_t zone; - int result = nvm_readZoneData(&zone, index); - if(result != -1) - snprintf(buf, max_len, "%s", zone.name); + int result = 0; + // First zone "All channels" is not read from flash + if(index == 0) + { + snprintf(buf, max_len, "All channels"); + } + else + { + zone_t zone; + int result = nvm_readZoneData(&zone, index - 1); + if(result != -1) + snprintf(buf, max_len, "%s", zone.name); + } return result; }