diff --git a/menu_main.cpp b/menu_main.cpp index 7860050..8eb010b 100644 --- a/menu_main.cpp +++ b/menu_main.cpp @@ -56,19 +56,12 @@ void mainMenuTune(int16_t knob) current_freq = GetActiveVfoFreq(); const uint32_t new_freq = current_freq + (50 * knob); - //Transition from below to above the traditional threshold for USB - if(current_freq < THRESHOLD_USB_LSB && new_freq >= THRESHOLD_USB_LSB){ - SetActiveVfoMode(VfoMode_e::VFO_MODE_USB); - updateSidebandButtons(); - } - - //Transition from above to below the traditional threshold for USB - if(current_freq >= THRESHOLD_USB_LSB && new_freq < THRESHOLD_USB_LSB){ - SetActiveVfoMode(VfoMode_e::VFO_MODE_LSB); + setFrequency(new_freq); + + if(autoSelectSidebandChanged(current_freq)){ updateSidebandButtons(); } - setFrequency(new_freq); const uint32_t old_freq = current_freq; current_freq = new_freq; diff --git a/menu_main_buttons.cpp b/menu_main_buttons.cpp index 0ea15a6..75fcd89 100644 --- a/menu_main_buttons.cpp +++ b/menu_main_buttons.cpp @@ -514,6 +514,9 @@ ButtonStatus_e bsBand(const uint8_t band){ void osBand(const uint8_t band){ const uint32_t old_freq = GetActiveVfoFreq(); SetActiveVfoFreq(getFreqInBand(old_freq,band)); + if(autoSelectSidebandChanged(old_freq)){ + updateSidebandButtons(); + } Button button; if(Vfo_e::VFO_A == globalSettings.activeVfo){ diff --git a/tuner.cpp b/tuner.cpp index 0bebb98..c9e7a11 100644 --- a/tuner.cpp +++ b/tuner.cpp @@ -5,10 +5,7 @@ #include "nano_gui.h" #include "pin_definitions.h" -/** - * Below are the basic functions that control the uBitx. Understanding the functions before - * you start hacking around - */ +static const uint32_t THRESHOLD_USB_LSB = 10000000L; void saveVFOs() { @@ -198,4 +195,24 @@ void ritDisable(){ setFrequency(globalSettings.ritFrequency); updateDisplay(); } -} \ No newline at end of file +} + +bool autoSelectSidebandChanged(const uint32_t old_frequency) +{ + const uint32_t new_freq = GetActiveVfoFreq(); + //Transition from below to above the traditional threshold for USB + if(old_frequency < THRESHOLD_USB_LSB && new_freq >= THRESHOLD_USB_LSB){ + SetActiveVfoMode(VfoMode_e::VFO_MODE_USB); + setFrequency(new_freq);//Refresh tuning to activate the new sideband mode + return true; + } + + //Transition from above to below the traditional threshold for USB + if(old_frequency >= THRESHOLD_USB_LSB && new_freq < THRESHOLD_USB_LSB){ + SetActiveVfoMode(VfoMode_e::VFO_MODE_LSB); + setFrequency(new_freq);//Refresh tuning to activate the new sideband mode + return true; + } + + return false; +} diff --git a/tuner.h b/tuner.h index dc4cf27..2414aaf 100644 --- a/tuner.h +++ b/tuner.h @@ -18,5 +18,4 @@ void si5351bx_setfreq(uint8_t clknum, uint32_t fout); void initOscillators(); void si5351_set_calibration(int32_t cal); //calibration is a small value that is nudged to make up for the inaccuracies of the reference 25 MHz crystal frequency -// limits the tuning and working range of the ubitx between 3 MHz and 30 MHz -static const uint32_t THRESHOLD_USB_LSB = 10000000L; +bool autoSelectSidebandChanged(const uint32_t old_frequency); //if the current frequency defaults to a different sideband mode, updates to that sideband mode and returns true. Else, returns false