From 405df5a7576fdef579d1a56fac9656421762f65b Mon Sep 17 00:00:00 2001 From: Reed Nightingale Date: Tue, 11 Feb 2020 23:09:18 -0800 Subject: [PATCH] Add method to update band buttons --- menu_main_buttons.cpp | 37 ++++++++++++++++++++++++++++++++++++- menu_main_buttons.h | 1 + 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/menu_main_buttons.cpp b/menu_main_buttons.cpp index bf78694..8d7113b 100644 --- a/menu_main_buttons.cpp +++ b/menu_main_buttons.cpp @@ -296,6 +296,20 @@ const Button* const buttons[] PROGMEM = { const Button* const* mainMenuButtons = buttons; const uint8_t MAIN_MENU_NUM_BUTTONS = sizeof(buttons) / sizeof(buttons[0]); +void updateBandButtons(const uint32_t old_freq) +{ + const Button* band_buttons[] = {&b80,&b40,&b30,&b20,&b17,&b15,&b10}; + const uint8_t bands [] = { 80, 40, 30, 20, 17, 15, 10}; + const uint32_t curr_freq = GetActiveVfoFreq(); + + Button button; + for(uint8_t i = 0; i < sizeof(bands)/sizeof(bands[0]); ++i){ + if(isFreqInBand(old_freq,bands[i]) != isFreqInBand(curr_freq,bands[i])){ + memcpy_P(&button,band_buttons[i],sizeof(button)); + drawButton(&button); + } + } +} void toVfo(char* text_out, const uint16_t max_text_size, const Vfo_e vfo) { @@ -348,8 +362,16 @@ ButtonStatus_e bsVfo(const Vfo_e vfo){ } void osVfo(const Vfo_e vfo){ + const uint32_t old_freq = GetActiveVfoFreq(); globalSettings.activeVfo = vfo; SaveSettingsToEeprom(); + + Button button; + memcpy_P(&button,&bVfoA,sizeof(button)); + drawButton(&button); + memcpy_P(&button,&bVfoB,sizeof(button)); + drawButton(&button); + updateBandButtons(old_freq); } void toVfoA(char* text_out, const uint16_t max_text_size){ @@ -474,7 +496,20 @@ ButtonStatus_e bsBand(const uint8_t band){ } void osBand(const uint8_t band){ - SetActiveVfoFreq(getFreqInBand(GetActiveVfoFreq(),band)); + const uint32_t old_freq = GetActiveVfoFreq(); + SetActiveVfoFreq(getFreqInBand(old_freq,band)); + + Button button; + if(Vfo_e::VFO_A == globalSettings.activeVfo){ + memcpy_P(&button,&bVfoA,sizeof(button)); + drawButton(&button); + } + else if(Vfo_e::VFO_B == globalSettings.activeVfo){ + memcpy_P(&button,&bVfoB,sizeof(button)); + drawButton(&button); + } + + updateBandButtons(old_freq); } ButtonStatus_e bs80(){ diff --git a/menu_main_buttons.h b/menu_main_buttons.h index 7efb414..9bb7319 100644 --- a/menu_main_buttons.h +++ b/menu_main_buttons.h @@ -9,3 +9,4 @@ extern const uint8_t MAIN_MENU_NUM_BUTTONS; extern const Button bVfoA; extern const Button bVfoB; +void updateBandButtons(const uint32_t old_freq);