Save ~100 bytes by combining these two functions

This commit is contained in:
Reed Nightingale 2020-04-26 21:32:19 -07:00
parent aa7e6825b4
commit 77b1bd291e
6 changed files with 26 additions and 38 deletions

View File

@ -42,3 +42,9 @@ void drawButton(Button* button)
} }
displayText(b, button->x, button->y, button->w, button->h, tc, bgc, bdc); displayText(b, button->x, button->y, button->w, button->h, tc, bgc, bdc);
} }
void extractAndDrawButton(Button* button_out, const Button* button_P)
{
memcpy_P(button_out,button_P,sizeof(*button_out));
drawButton(button_out);
}

View File

@ -17,4 +17,4 @@ struct Button {
char morse; char morse;
}; };
void drawButton(Button* button); void extractAndDrawButton(Button* button_out, const Button* button_P);

View File

@ -37,8 +37,7 @@ void drawMainMenu(void)
Button* bp; Button* bp;
for(uint8_t i = 0; i < MAIN_MENU_NUM_BUTTONS; ++i){ for(uint8_t i = 0; i < MAIN_MENU_NUM_BUTTONS; ++i){
memcpy_P(&bp, &(mainMenuButtons[i]), sizeof(bp)); memcpy_P(&bp, &(mainMenuButtons[i]), sizeof(bp));
memcpy_P(&button,bp,sizeof(button)); extractAndDrawButton(&button,bp);
drawButton(&button);
} }
drawVersion(); drawVersion();
drawCallsign(); drawCallsign();
@ -70,12 +69,11 @@ void mainMenuTune(int16_t knob)
Button button; Button button;
if(Vfo_e::VFO_A == globalSettings.activeVfo){ if(Vfo_e::VFO_A == globalSettings.activeVfo){
memcpy_P(&button,&bVfoA,sizeof(button)); extractAndDrawButton(&button,&bVfoA);
} }
else{ else{
memcpy_P(&button,&bVfoB,sizeof(button)); extractAndDrawButton(&button,&bVfoB);
} }
drawButton(&button);
updateBandButtons(old_freq); updateBandButtons(old_freq);
} }

View File

@ -350,8 +350,7 @@ void updateBandButtons(const uint32_t old_freq)
Button button; Button button;
for(uint8_t i = 0; i < sizeof(bands)/sizeof(bands[0]); ++i){ for(uint8_t i = 0; i < sizeof(bands)/sizeof(bands[0]); ++i){
if(isFreqInBand(old_freq,bands[i]) != isFreqInBand(curr_freq,bands[i])){ if(isFreqInBand(old_freq,bands[i]) != isFreqInBand(curr_freq,bands[i])){
memcpy_P(&button,band_buttons[i],sizeof(button)); extractAndDrawButton(&button,band_buttons[i]);
drawButton(&button);
morseBool(ButtonStatus_e::Active == button.status()); morseBool(ButtonStatus_e::Active == button.status());
} }
} }
@ -421,10 +420,8 @@ void osVfo(const Vfo_e vfo){
morseText(b); morseText(b);
Button button; Button button;
memcpy_P(&button,&bVfoA,sizeof(button)); extractAndDrawButton(&button,&bVfoA);
drawButton(&button); extractAndDrawButton(&button,&bVfoB);
memcpy_P(&button,&bVfoB,sizeof(button));
drawButton(&button);
updateBandButtons(old_freq); updateBandButtons(old_freq);
updateSidebandButtons(); updateSidebandButtons();
} }
@ -473,17 +470,14 @@ void osRit(){
displayFillrect(LAYOUT_MODE_TEXT_X,LAYOUT_MODE_TEXT_Y,LAYOUT_MODE_TEXT_WIDTH,LAYOUT_MODE_TEXT_HEIGHT, COLOR_BACKGROUND); displayFillrect(LAYOUT_MODE_TEXT_X,LAYOUT_MODE_TEXT_Y,LAYOUT_MODE_TEXT_WIDTH,LAYOUT_MODE_TEXT_HEIGHT, COLOR_BACKGROUND);
if(Vfo_e::VFO_A == globalSettings.activeVfo){ if(Vfo_e::VFO_A == globalSettings.activeVfo){
memcpy_P(&button,&bVfoA,sizeof(button)); extractAndDrawButton(&button,&bVfoA);
drawButton(&button);
} }
else{ else{
memcpy_P(&button,&bVfoB,sizeof(button)); extractAndDrawButton(&button,&bVfoB);
drawButton(&button);
} }
} }
memcpy_P(&button,&bRit,sizeof(button)); extractAndDrawButton(&button,&bRit);
drawButton(&button);
} }
void osSidebandMode(VfoMode_e mode){ void osSidebandMode(VfoMode_e mode){
@ -492,10 +486,8 @@ void osSidebandMode(VfoMode_e mode){
SaveSettingsToEeprom(); SaveSettingsToEeprom();
Button button; Button button;
memcpy_P(&button,&bUsb,sizeof(button)); extractAndDrawButton(&button,&bUsb);
drawButton(&button); extractAndDrawButton(&button,&bLsb);
memcpy_P(&button,&bLsb,sizeof(button));
drawButton(&button);
} }
void updateSidebandButtons() void updateSidebandButtons()
@ -534,8 +526,7 @@ void osCw(){
setFrequency(GetActiveVfoFreq()); setFrequency(GetActiveVfoFreq());
Button button; Button button;
memcpy_P(&button,&bCw,sizeof(button)); extractAndDrawButton(&button,&bCw);
drawButton(&button);
} }
ButtonStatus_e bsSpl(){ ButtonStatus_e bsSpl(){
@ -546,12 +537,9 @@ void osSpl(){
globalSettings.splitOn = !globalSettings.splitOn; globalSettings.splitOn = !globalSettings.splitOn;
Button button; Button button;
memcpy_P(&button,&bSpl,sizeof(button)); extractAndDrawButton(&button,&bSpl);
drawButton(&button); extractAndDrawButton(&button,&bVfoA);
memcpy_P(&button,&bVfoA,sizeof(button)); extractAndDrawButton(&button,&bVfoB);
drawButton(&button);
memcpy_P(&button,&bVfoB,sizeof(button));
drawButton(&button);
} }
ButtonStatus_e bsBand(const uint8_t band){ ButtonStatus_e bsBand(const uint8_t band){
@ -567,12 +555,10 @@ void osBand(const uint8_t band){
Button button; Button button;
if(Vfo_e::VFO_A == globalSettings.activeVfo){ if(Vfo_e::VFO_A == globalSettings.activeVfo){
memcpy_P(&button,&bVfoA,sizeof(button)); extractAndDrawButton(&button,&bVfoA);
drawButton(&button);
} }
else if(Vfo_e::VFO_B == globalSettings.activeVfo){ else if(Vfo_e::VFO_B == globalSettings.activeVfo){
memcpy_P(&button,&bVfoB,sizeof(button)); extractAndDrawButton(&button,&bVfoB);
drawButton(&button);
} }
updateBandButtons(old_freq); updateBandButtons(old_freq);

View File

@ -29,8 +29,7 @@ void drawNumpad(void)
Button* bp; Button* bp;
for(uint8_t i = 0; i < NUMPAD_MENU_NUM_BUTTONS; ++i){ for(uint8_t i = 0; i < NUMPAD_MENU_NUM_BUTTONS; ++i){
memcpy_P(&bp, &(numpadMenuButtons[i]), sizeof(bp)); memcpy_P(&bp, &(numpadMenuButtons[i]), sizeof(bp));
memcpy_P(&button,bp,sizeof(button)); extractAndDrawButton(&button,bp);
drawButton(&button);
} }
} }

View File

@ -31,8 +31,7 @@ void drawQuickList(void)
Button* bp; Button* bp;
for(uint8_t i = 0; i < QUICKLIST_MENU_NUM_BUTTONS; ++i){ for(uint8_t i = 0; i < QUICKLIST_MENU_NUM_BUTTONS; ++i){
memcpy_P(&bp, &(quickListMenuButtons[i]), sizeof(bp)); memcpy_P(&bp, &(quickListMenuButtons[i]), sizeof(bp));
memcpy_P(&button,bp,sizeof(button)); extractAndDrawButton(&button,bp);
drawButton(&button);
} }
strncpy_P(b,(const char*)F("Short press = load\nLong press = save"),sizeof(b)); strncpy_P(b,(const char*)F("Short press = load\nLong press = save"),sizeof(b));
displayText(b,10,47,170,200,COLOR_TEXT,COLOR_BACKGROUND,COLOR_BACKGROUND); displayText(b,10,47,170,200,COLOR_TEXT,COLOR_BACKGROUND,COLOR_BACKGROUND);