diff --git a/openrtx/src/ui.c b/openrtx/src/ui.c index 31d438bb..aacaaa76 100644 --- a/openrtx/src/ui.c +++ b/openrtx/src/ui.c @@ -552,6 +552,20 @@ freq_t _ui_freq_add_digit(freq_t freq, uint8_t pos, uint8_t number) return freq += number * coefficient; } +bool _ui_freq_check_limits(freq_t freq) +{ + bool valid = false; +#ifdef BAND_VHF + if(freq >= FREQ_LIMIT_VHF_LO && freq <= FREQ_LIMIT_VHF_HI) + valid = true; +#endif +#ifdef BAND_UHF + if(freq >= FREQ_LIMIT_UHF_LO && freq <= FREQ_LIMIT_UHF_HI) + valid = true; +#endif + return valid; +} + void ui_updateFSM(event_t event, bool *sync_rtx) { // Check if battery has enough charge to operate @@ -577,17 +591,25 @@ void ui_updateFSM(event_t event, bool *sync_rtx) case VFO_MAIN: if(msg.keys & KEY_UP) { - // Advance TX and RX frequency of 12.5KHz - state.channel.rx_frequency += 12500; - state.channel.tx_frequency += 12500; - *sync_rtx = true; + // Increment TX and RX frequency of 12.5KHz + if(_ui_freq_check_limits(state.channel.rx_frequency + 12500) && + _ui_freq_check_limits(state.channel.tx_frequency + 12500)) + { + state.channel.rx_frequency += 12500; + state.channel.tx_frequency += 12500; + *sync_rtx = true; + } } else if(msg.keys & KEY_DOWN) { - // Advance TX and RX frequency of 12.5KHz - state.channel.rx_frequency -= 12500; - state.channel.tx_frequency -= 12500; - *sync_rtx = true; + // Decrement TX and RX frequency of 12.5KHz + if(_ui_freq_check_limits(state.channel.rx_frequency - 12500) && + _ui_freq_check_limits(state.channel.tx_frequency - 12500)) + { + state.channel.rx_frequency -= 12500; + state.channel.tx_frequency -= 12500; + *sync_rtx = true; + } } else if(msg.keys & KEY_ENTER) // Open Menu @@ -623,14 +645,21 @@ void ui_updateFSM(event_t event, bool *sync_rtx) // If TX frequency was not set, TX = RX if(new_tx_frequency == 0) { - state.channel.rx_frequency = new_rx_frequency; - state.channel.tx_frequency = new_rx_frequency; + if(_ui_freq_check_limits(new_rx_frequency)) + { + state.channel.rx_frequency = new_rx_frequency; + state.channel.tx_frequency = new_rx_frequency; + } } // Otherwise set both frequencies else { - state.channel.rx_frequency = new_rx_frequency; - state.channel.tx_frequency = new_tx_frequency; + if(_ui_freq_check_limits(new_rx_frequency) && + _ui_freq_check_limits(new_tx_frequency)) + { + state.channel.rx_frequency = new_rx_frequency; + state.channel.tx_frequency = new_tx_frequency; + } } state.ui_screen = VFO_MAIN; } @@ -679,8 +708,12 @@ void ui_updateFSM(event_t event, bool *sync_rtx) if(input_position >= (FREQ_DIGITS)) { // Save both inserted frequencies - state.channel.rx_frequency = new_rx_frequency; - state.channel.tx_frequency = new_tx_frequency; + if(_ui_freq_check_limits(new_rx_frequency) && + _ui_freq_check_limits(new_tx_frequency)) + { + state.channel.rx_frequency = new_rx_frequency; + state.channel.tx_frequency = new_tx_frequency; + } state.ui_screen = VFO_MAIN; } } diff --git a/platform/targets/DM-1801/hwconfig.h b/platform/targets/DM-1801/hwconfig.h index 371fc2b7..94c28de3 100644 --- a/platform/targets/DM-1801/hwconfig.h +++ b/platform/targets/DM-1801/hwconfig.h @@ -23,6 +23,16 @@ #include "MK22F51212.h" +/* Supported radio bands */ +#define BAND_VHF +#define BAND_UHF + +/* Band limits in Hz */ +#define FREQ_LIMIT_VHF_LO 136000000 +#define FREQ_LIMIT_VHF_HI 136000000 +#define FREQ_LIMIT_UHF_LO 400000000 +#define FREQ_LIMIT_UHF_HI 470000000 + /* Screen dimensions */ #define SCREEN_WIDTH 128 #define SCREEN_HEIGHT 64 diff --git a/platform/targets/GD77/hwconfig.h b/platform/targets/GD77/hwconfig.h index 981ffd1f..22feb67c 100644 --- a/platform/targets/GD77/hwconfig.h +++ b/platform/targets/GD77/hwconfig.h @@ -23,6 +23,16 @@ #include "MK22F51212.h" +/* Supported radio bands */ +#define BAND_VHF +#define BAND_UHF + +/* Band limits in Hz */ +#define FREQ_LIMIT_VHF_LO 136000000 +#define FREQ_LIMIT_VHF_HI 136000000 +#define FREQ_LIMIT_UHF_LO 400000000 +#define FREQ_LIMIT_UHF_HI 470000000 + /* Screen dimensions */ #define SCREEN_WIDTH 128 #define SCREEN_HEIGHT 64 diff --git a/platform/targets/MD-380/hwconfig.h b/platform/targets/MD-380/hwconfig.h index 950bbb96..2d84409a 100644 --- a/platform/targets/MD-380/hwconfig.h +++ b/platform/targets/MD-380/hwconfig.h @@ -22,6 +22,16 @@ #include +/* Supported radio bands */ +#define BAND_VHF +#define BAND_UHF + +/* Band limits in Hz */ +#define FREQ_LIMIT_VHF_LO 136000000 +#define FREQ_LIMIT_VHF_HI 136000000 +#define FREQ_LIMIT_UHF_LO 400000000 +#define FREQ_LIMIT_UHF_HI 480000000 + /* Screen dimensions */ #define SCREEN_WIDTH 160 #define SCREEN_HEIGHT 128 diff --git a/platform/targets/MD-390/hwconfig.h b/platform/targets/MD-390/hwconfig.h index dd3554d5..e33af9e9 100644 --- a/platform/targets/MD-390/hwconfig.h +++ b/platform/targets/MD-390/hwconfig.h @@ -22,6 +22,16 @@ #include +/* Supported radio bands */ +#define BAND_VHF +#define BAND_UHF + +/* Band limits in Hz */ +#define FREQ_LIMIT_VHF_LO 136000000 +#define FREQ_LIMIT_VHF_HI 136000000 +#define FREQ_LIMIT_UHF_LO 400000000 +#define FREQ_LIMIT_UHF_HI 480000000 + /* Screen dimensions */ #define SCREEN_WIDTH 160 #define SCREEN_HEIGHT 128 diff --git a/platform/targets/MD-UV380/hwconfig.h b/platform/targets/MD-UV380/hwconfig.h index cbc4b6ff..971c98c3 100644 --- a/platform/targets/MD-UV380/hwconfig.h +++ b/platform/targets/MD-UV380/hwconfig.h @@ -22,6 +22,16 @@ #include +/* Supported radio bands */ +#define BAND_VHF +#define BAND_UHF + +/* Band limits in Hz */ +#define FREQ_LIMIT_VHF_LO 136000000 +#define FREQ_LIMIT_VHF_HI 136000000 +#define FREQ_LIMIT_UHF_LO 400000000 +#define FREQ_LIMIT_UHF_HI 480000000 + /* Screen dimensions */ #define SCREEN_WIDTH 160 #define SCREEN_HEIGHT 128 diff --git a/platform/targets/linux/hwconfig.h b/platform/targets/linux/hwconfig.h index 623dc462..cc8954d1 100644 --- a/platform/targets/linux/hwconfig.h +++ b/platform/targets/linux/hwconfig.h @@ -18,6 +18,16 @@ #define PLATFORM_LINUX +/* Supported radio bands */ +#define BAND_VHF +#define BAND_UHF + +/* Band limits in Hz */ +#define FREQ_LIMIT_VHF_LO 136000000 +#define FREQ_LIMIT_VHF_HI 136000000 +#define FREQ_LIMIT_UHF_LO 400000000 +#define FREQ_LIMIT_UHF_HI 480000000 + /* Battery type */ #define BAT_LIPO_2S