From 74360b584ff891e7dd67acc03d32a05ad0a3ec5c Mon Sep 17 00:00:00 2001 From: Armel FAUVEAU Date: Sat, 17 Feb 2024 06:03:09 +0100 Subject: [PATCH] Optimize memory --- ui/main.c | 79 +++++++++++++++++++++++++------------------------------ 1 file changed, 36 insertions(+), 43 deletions(-) diff --git a/ui/main.c b/ui/main.c index 1a3c2e8..f74d57c 100644 --- a/ui/main.c +++ b/ui/main.c @@ -50,6 +50,14 @@ center_line_t center_line = CENTER_LINE_NONE; static int8_t RxBlinkLedCounter; static int8_t RxLine; bool isMainOnlyInputDTMF = false; + + static bool isMainOnly(void) + { + if((gEeprom.DUAL_WATCH != DUAL_WATCH_OFF) + (gEeprom.CROSS_BAND_RX_TX != CROSS_BAND_OFF) * 2 == 0) + return true; + else + return false; + } #endif const int8_t dBmCorrTable[7] = { @@ -188,7 +196,7 @@ void UI_DisplayAudioBar(void) RxBlinkLedCounter = 0; BK4819_ToggleGpioOut(BK4819_GPIO6_PIN2_GREEN, false); unsigned int line; - if ((gEeprom.DUAL_WATCH != DUAL_WATCH_OFF) + (gEeprom.CROSS_BAND_RX_TX != CROSS_BAND_OFF) * 2 == 0) + if (isMainOnly()) { line = 5; } @@ -257,7 +265,7 @@ void DisplayRSSIBar(const bool now) }; unsigned int line; - if ((gEeprom.DUAL_WATCH != DUAL_WATCH_OFF) + (gEeprom.CROSS_BAND_RX_TX != CROSS_BAND_OFF) * 2 == 0) + if (isMainOnly()) { line = 5; } @@ -363,7 +371,7 @@ void DisplayRSSIBar(const bool now) #endif #ifdef ENABLE_FEAT_F4HWN - if ((gEeprom.DUAL_WATCH != DUAL_WATCH_OFF) + (gEeprom.CROSS_BAND_RX_TX != CROSS_BAND_OFF) * 2 == 0) + if (isMainOnly()) { sprintf(str, "%3d", -rssi_dBm); UI_PrintStringSmallNormal(str, LCD_WIDTH + 8, 0, line - 1); @@ -567,7 +575,7 @@ void UI_DisplayMain(void) const unsigned int line0 = 0; // text screen line const unsigned int line1 = 4; unsigned int line; - if ((gEeprom.DUAL_WATCH != DUAL_WATCH_OFF) + (gEeprom.CROSS_BAND_RX_TX != CROSS_BAND_OFF) * 2 == 0) + if (isMainOnly()) { line = 0; } @@ -590,7 +598,7 @@ void UI_DisplayMain(void) #endif #ifdef ENABLE_FEAT_F4HWN - if ((gEeprom.DUAL_WATCH != DUAL_WATCH_OFF) + (gEeprom.CROSS_BAND_RX_TX != CROSS_BAND_OFF) * 2 == 0) + if (isMainOnly()) { if (activeTxVFO != vfo_num) { @@ -600,7 +608,7 @@ void UI_DisplayMain(void) #endif #ifdef ENABLE_FEAT_F4HWN - if (activeTxVFO != vfo_num || ((gEeprom.DUAL_WATCH != DUAL_WATCH_OFF) + (gEeprom.CROSS_BAND_RX_TX != CROSS_BAND_OFF) * 2 == 0)) + if (activeTxVFO != vfo_num || isMainOnly()) #else if (activeTxVFO != vfo_num) // this is not active TX VFO #endif @@ -657,7 +665,7 @@ void UI_DisplayMain(void) } #ifdef ENABLE_FEAT_F4HWN - if ((gEeprom.DUAL_WATCH != DUAL_WATCH_OFF) + (gEeprom.CROSS_BAND_RX_TX != CROSS_BAND_OFF) * 2 == 0) + if (isMainOnly()) { UI_PrintString(pPrintStr, 2, 0, 5, 8); isMainOnlyInputDTMF = true; @@ -871,7 +879,7 @@ void UI_DisplayMain(void) } else { #ifdef ENABLE_FEAT_F4HWN - if ((gEeprom.DUAL_WATCH != DUAL_WATCH_OFF) + (gEeprom.CROSS_BAND_RX_TX != CROSS_BAND_OFF) * 2 == 0) + if (isMainOnly()) { UI_PrintString(String, 32, 0, line, 8); } @@ -890,7 +898,7 @@ void UI_DisplayMain(void) #endif #ifdef ENABLE_FEAT_F4HWN - if ((gEeprom.DUAL_WATCH != DUAL_WATCH_OFF) + (gEeprom.CROSS_BAND_RX_TX != CROSS_BAND_OFF) * 2 == 0) + if (isMainOnly()) { sprintf(String, "%3u.%05u", frequency / 100000, frequency % 100000); if(frequency < _1GHz_in_KHz) { @@ -1000,7 +1008,7 @@ void UI_DisplayMain(void) } #if ENABLE_FEAT_F4HWN - if ((gEeprom.DUAL_WATCH != DUAL_WATCH_OFF) + (gEeprom.CROSS_BAND_RX_TX != CROSS_BAND_OFF) * 2 == 0) + if (isMainOnly()) { UI_PrintStringSmallNormal(s, LCD_WIDTH + 24, 0, line + 1); } @@ -1016,15 +1024,15 @@ void UI_DisplayMain(void) { // show the TX power int i = vfoInfo->OUTPUT_POWER % 3; #if ENABLE_FEAT_F4HWN - if ((gEeprom.DUAL_WATCH != DUAL_WATCH_OFF) + (gEeprom.CROSS_BAND_RX_TX != CROSS_BAND_OFF) * 2 == 0) + if (isMainOnly()) { const char pwr_list[][2] = {"L","M","H"}; UI_PrintStringSmallNormal(pwr_list[i], LCD_WIDTH + 46, 0, line + 1); } else { - const char *powerNames[] = {"LOW", "MID", "HIGH"}; - GUI_DisplaySmallest(powerNames[i], 37, line == 0 ? 17 : 49, false, true); + const char pwr_names[][5] = {"LOW", "MID", "HIGH"}; + GUI_DisplaySmallest(pwr_names[i], 37, line == 0 ? 17 : 49, false, true); } #else const char pwr_list[][2] = {"L","M","H"}; @@ -1037,7 +1045,7 @@ void UI_DisplayMain(void) const char dir_list[][2] = {"", "+", "-"}; int i = vfoInfo->TX_OFFSET_FREQUENCY_DIRECTION % 3; #if ENABLE_FEAT_F4HWN - if ((gEeprom.DUAL_WATCH != DUAL_WATCH_OFF) + (gEeprom.CROSS_BAND_RX_TX != CROSS_BAND_OFF) * 2 == 0) + if (isMainOnly()) { UI_PrintStringSmallNormal(dir_list[i], LCD_WIDTH + 54, 0, line + 1); } @@ -1054,7 +1062,7 @@ void UI_DisplayMain(void) if (vfoInfo->FrequencyReverse) #if ENABLE_FEAT_F4HWN { - if ((gEeprom.DUAL_WATCH != DUAL_WATCH_OFF) + (gEeprom.CROSS_BAND_RX_TX != CROSS_BAND_OFF) * 2 == 0) + if (isMainOnly()) { UI_PrintStringSmallNormal("R", LCD_WIDTH + 62, 0, line + 1); } @@ -1068,7 +1076,7 @@ void UI_DisplayMain(void) #endif #if ENABLE_FEAT_F4HWN - if ((gEeprom.DUAL_WATCH != DUAL_WATCH_OFF) + (gEeprom.CROSS_BAND_RX_TX != CROSS_BAND_OFF) * 2 == 0) + if (isMainOnly()) { if (vfoInfo->CHANNEL_BANDWIDTH == BANDWIDTH_NARROW) UI_PrintStringSmallNormal("N", LCD_WIDTH + 70, 0, line + 1); @@ -1076,10 +1084,7 @@ void UI_DisplayMain(void) else { const char *bandWidthNames[] = {"WIDE", "NARROW"}; - if (vfoInfo->CHANNEL_BANDWIDTH == BANDWIDTH_NARROW) - GUI_DisplaySmallest(bandWidthNames[1], 76, line == 0 ? 17 : 49, false, true); - else - GUI_DisplaySmallest(bandWidthNames[0], 76, line == 0 ? 17 : 49, false, true); + GUI_DisplaySmallest(bandWidthNames[vfoInfo->CHANNEL_BANDWIDTH], 76, line == 0 ? 17 : 49, false, true); } #else if (vfoInfo->CHANNEL_BANDWIDTH == BANDWIDTH_NARROW) @@ -1101,14 +1106,14 @@ void UI_DisplayMain(void) #ifdef ENABLE_FEAT_F4HWN if(isMainVFO) { - - if ((gEeprom.DUAL_WATCH != DUAL_WATCH_OFF) + (gEeprom.CROSS_BAND_RX_TX != CROSS_BAND_OFF) * 2 == 0) + if(gMonitor) { - if(gMonitor) - { - sprintf(String, "%s", "MON"); - } - else + sprintf(String, "%s", "MONIT"); + } + + if (isMainOnly()) + { + if(!gMonitor) { sprintf(String, "SQL %d", gEeprom.SQUELCH_LEVEL); } @@ -1116,11 +1121,7 @@ void UI_DisplayMain(void) } else { - if(gMonitor) - { - sprintf(String, "%s", "MONIT"); - } - else + if(!gMonitor) { sprintf(String, "SQL %d", gEeprom.SQUELCH_LEVEL); } @@ -1191,7 +1192,7 @@ void UI_DisplayMain(void) sprintf(String, "DTMF %s", gDTMF_RX_live + idx); #ifdef ENABLE_FEAT_F4HWN - if ((gEeprom.DUAL_WATCH != DUAL_WATCH_OFF) + (gEeprom.CROSS_BAND_RX_TX != CROSS_BAND_OFF) * 2 == 0) + if (isMainOnly()) { UI_PrintStringSmallNormal(String, 2, 0, 5); } @@ -1243,17 +1244,9 @@ void UI_DisplayMain(void) } #ifdef ENABLE_FEAT_F4HWN - if ((gEeprom.DUAL_WATCH != DUAL_WATCH_OFF) + (gEeprom.CROSS_BAND_RX_TX != CROSS_BAND_OFF) * 2 == 0) + if (isMainOnly()) { - switch(activeTxVFO) - { - case 0: - sprintf(String, "%s %s", "VFO", "A"); - break; - case 1: - sprintf(String, "%s %s", "VFO", "B"); - break; - } + sprintf(String, "VFO %s", activeTxVFO ? "B" : "A"); UI_PrintStringSmallBold(String, 49, 0, 6); } #endif