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);
}
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;
};
void drawButton(Button* button);
void extractAndDrawButton(Button* button_out, const Button* button_P);

View File

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

View File

@ -350,8 +350,7 @@ void updateBandButtons(const uint32_t old_freq)
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);
extractAndDrawButton(&button,band_buttons[i]);
morseBool(ButtonStatus_e::Active == button.status());
}
}
@ -421,10 +420,8 @@ void osVfo(const Vfo_e vfo){
morseText(b);
Button button;
memcpy_P(&button,&bVfoA,sizeof(button));
drawButton(&button);
memcpy_P(&button,&bVfoB,sizeof(button));
drawButton(&button);
extractAndDrawButton(&button,&bVfoA);
extractAndDrawButton(&button,&bVfoB);
updateBandButtons(old_freq);
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);
if(Vfo_e::VFO_A == globalSettings.activeVfo){
memcpy_P(&button,&bVfoA,sizeof(button));
drawButton(&button);
extractAndDrawButton(&button,&bVfoA);
}
else{
memcpy_P(&button,&bVfoB,sizeof(button));
drawButton(&button);
extractAndDrawButton(&button,&bVfoB);
}
}
memcpy_P(&button,&bRit,sizeof(button));
drawButton(&button);
extractAndDrawButton(&button,&bRit);
}
void osSidebandMode(VfoMode_e mode){
@ -492,10 +486,8 @@ void osSidebandMode(VfoMode_e mode){
SaveSettingsToEeprom();
Button button;
memcpy_P(&button,&bUsb,sizeof(button));
drawButton(&button);
memcpy_P(&button,&bLsb,sizeof(button));
drawButton(&button);
extractAndDrawButton(&button,&bUsb);
extractAndDrawButton(&button,&bLsb);
}
void updateSidebandButtons()
@ -534,8 +526,7 @@ void osCw(){
setFrequency(GetActiveVfoFreq());
Button button;
memcpy_P(&button,&bCw,sizeof(button));
drawButton(&button);
extractAndDrawButton(&button,&bCw);
}
ButtonStatus_e bsSpl(){
@ -546,12 +537,9 @@ void osSpl(){
globalSettings.splitOn = !globalSettings.splitOn;
Button button;
memcpy_P(&button,&bSpl,sizeof(button));
drawButton(&button);
memcpy_P(&button,&bVfoA,sizeof(button));
drawButton(&button);
memcpy_P(&button,&bVfoB,sizeof(button));
drawButton(&button);
extractAndDrawButton(&button,&bSpl);
extractAndDrawButton(&button,&bVfoA);
extractAndDrawButton(&button,&bVfoB);
}
ButtonStatus_e bsBand(const uint8_t band){
@ -567,12 +555,10 @@ void osBand(const uint8_t band){
Button button;
if(Vfo_e::VFO_A == globalSettings.activeVfo){
memcpy_P(&button,&bVfoA,sizeof(button));
drawButton(&button);
extractAndDrawButton(&button,&bVfoA);
}
else if(Vfo_e::VFO_B == globalSettings.activeVfo){
memcpy_P(&button,&bVfoB,sizeof(button));
drawButton(&button);
extractAndDrawButton(&button,&bVfoB);
}
updateBandButtons(old_freq);

View File

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

View File

@ -31,8 +31,7 @@ void drawQuickList(void)
Button* bp;
for(uint8_t i = 0; i < QUICKLIST_MENU_NUM_BUTTONS; ++i){
memcpy_P(&bp, &(quickListMenuButtons[i]), sizeof(bp));
memcpy_P(&button,bp,sizeof(button));
drawButton(&button);
extractAndDrawButton(&button,bp);
}
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);