Reduce nesting

This commit is contained in:
Juan Antonio
2023-12-25 14:21:43 +01:00
committed by Krzysiek Egzmont
parent ea733115de
commit 289418f1c7
2 changed files with 52 additions and 77 deletions

View File

@@ -103,7 +103,7 @@ void MENU_CssScanFound(void)
void MENU_StopCssScan(void) void MENU_StopCssScan(void)
{ {
gCssBackgroundScan = false; gCssBackgroundScan = false;
#ifdef ENABLE_VOICE #ifdef ENABLE_VOICE
gAnotherVoiceID = VOICE_ID_SCANNING_STOP; gAnotherVoiceID = VOICE_ID_SCANNING_STOP;
#endif #endif
@@ -133,12 +133,12 @@ int MENU_GetLimits(uint8_t menu_id, int32_t *pMin, int32_t *pMax)
case MENU_ABR_MIN: case MENU_ABR_MIN:
*pMin = 0; *pMin = 0;
*pMax = 9; *pMax = 9;
break; break;
case MENU_ABR_MAX: case MENU_ABR_MAX:
*pMin = 1; *pMin = 1;
*pMax = 10; *pMax = 10;
break; break;
case MENU_F_LOCK: case MENU_F_LOCK:
*pMin = 0; *pMin = 0;
@@ -303,7 +303,7 @@ int MENU_GetLimits(uint8_t menu_id, int32_t *pMin, int32_t *pMax)
*pMin = 0; *pMin = 0;
*pMax = 2; *pMax = 2;
break; break;
#ifdef ENABLE_DTMF_CALLING #ifdef ENABLE_DTMF_CALLING
case MENU_D_RSP: case MENU_D_RSP:
*pMin = 0; *pMin = 0;
@@ -500,7 +500,7 @@ void MENU_AcceptSetting(void)
break; break;
edit[i] = ' '; edit[i] = ' ';
} }
SETTINGS_SaveChannelName(gSubMenuSelection, edit); SETTINGS_SaveChannelName(gSubMenuSelection, edit);
return; return;
@@ -531,7 +531,7 @@ void MENU_AcceptSetting(void)
case MENU_ABR_MAX: case MENU_ABR_MAX:
gEeprom.BACKLIGHT_MAX = gSubMenuSelection; gEeprom.BACKLIGHT_MAX = gSubMenuSelection;
gEeprom.BACKLIGHT_MIN = MIN(gSubMenuSelection - 1, gEeprom.BACKLIGHT_MIN); gEeprom.BACKLIGHT_MIN = MIN(gSubMenuSelection - 1, gEeprom.BACKLIGHT_MIN);
break; break;
case MENU_ABR_ON_TX_RX: case MENU_ABR_ON_TX_RX:
gSetting_backlight_on_tx_rx = gSubMenuSelection; gSetting_backlight_on_tx_rx = gSubMenuSelection;
@@ -835,9 +835,9 @@ void MENU_ShowCurrentSetting(void)
case MENU_RESET: case MENU_RESET:
gSubMenuSelection = 0; gSubMenuSelection = 0;
break; break;
case MENU_R_DCS: case MENU_R_DCS:
case MENU_R_CTCS: case MENU_R_CTCS:
{ {
DCS_CodeType_t type = gTxVfo->freq_config_RX.CodeType; DCS_CodeType_t type = gTxVfo->freq_config_RX.CodeType;
@@ -940,7 +940,7 @@ void MENU_ShowCurrentSetting(void)
case MENU_ABR_MAX: case MENU_ABR_MAX:
gSubMenuSelection = gEeprom.BACKLIGHT_MAX; gSubMenuSelection = gEeprom.BACKLIGHT_MAX;
break; break;
case MENU_ABR_ON_TX_RX: case MENU_ABR_ON_TX_RX:
gSubMenuSelection = gSetting_backlight_on_tx_rx; gSubMenuSelection = gSetting_backlight_on_tx_rx;
@@ -1133,7 +1133,7 @@ void MENU_ShowCurrentSetting(void)
case MENU_BATTYP: case MENU_BATTYP:
gSubMenuSelection = gEeprom.BATTERY_TYPE; gSubMenuSelection = gEeprom.BATTERY_TYPE;
break; break;
case MENU_F1SHRT: case MENU_F1SHRT:
case MENU_F1LONG: case MENU_F1LONG:
@@ -1154,7 +1154,7 @@ void MENU_ShowCurrentSetting(void)
gSubMenuSelection = i; gSubMenuSelection = i;
break; break;
} }
} }
break; break;
} }
@@ -1256,17 +1256,17 @@ static void MENU_Key_0_to_9(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld)
#ifdef ENABLE_VOICE #ifdef ENABLE_VOICE
gAnotherVoiceID = (VOICE_ID_t)Key; gAnotherVoiceID = (VOICE_ID_t)Key;
#endif #endif
Frequency = StrToUL(INPUTBOX_GetAscii())*100; Frequency = StrToUL(INPUTBOX_GetAscii())*100;
gSubMenuSelection = FREQUENCY_RoundToStep(Frequency, gTxVfo->StepFrequency); gSubMenuSelection = FREQUENCY_RoundToStep(Frequency, gTxVfo->StepFrequency);
gInputBoxIndex = 0; gInputBoxIndex = 0;
return; return;
} }
if (UI_MENU_GetCurrentMenuId() == MENU_MEM_CH || if (UI_MENU_GetCurrentMenuId() == MENU_MEM_CH ||
UI_MENU_GetCurrentMenuId() == MENU_DEL_CH || UI_MENU_GetCurrentMenuId() == MENU_DEL_CH ||
UI_MENU_GetCurrentMenuId() == MENU_1_CALL || UI_MENU_GetCurrentMenuId() == MENU_1_CALL ||
UI_MENU_GetCurrentMenuId() == MENU_MEM_NAME) UI_MENU_GetCurrentMenuId() == MENU_MEM_NAME)
{ // enter 3-digit channel number { // enter 3-digit channel number
@@ -1452,16 +1452,11 @@ static void MENU_Key_MENU(const bool bKeyPressed, const bool bKeyHeld)
return; // next char return; // next char
// exit // exit
if (memcmp(edit_original, edit, sizeof(edit_original)) == 0) gFlagAcceptSetting = false;
{ // no change - drop it gAskForConfirmation = 0;
gFlagAcceptSetting = false; if (memcmp(edit_original, edit, sizeof(edit_original)) == 0) {
gIsInSubMenu = false; // no change - drop it
gAskForConfirmation = 0; gIsInSubMenu = false;
}
else
{
gFlagAcceptSetting = false;
gAskForConfirmation = 0;
} }
} }
} }

82
radio.c
View File

@@ -57,68 +57,48 @@ const char gModulationStr[MODULATION_UKNOWN][4] = {
bool RADIO_CheckValidChannel(uint16_t Channel, bool bCheckScanList, uint8_t VFO) bool RADIO_CheckValidChannel(uint16_t Channel, bool bCheckScanList, uint8_t VFO)
{ // return true if the channel appears valid {
// return true if the channel appears valid
ChannelAttributes_t att; if (!IS_MR_CHANNEL(Channel)) {
uint8_t PriorityCh1;
uint8_t PriorityCh2;
if (!IS_MR_CHANNEL(Channel))
return false; return false;
att = gMR_ChannelAttributes[Channel];
if (att.band > BAND7_470MHz)
return false;
if (bCheckScanList) {
switch (VFO) {
case 0:
if (!att.scanlist1)
return false;
PriorityCh1 = gEeprom.SCANLIST_PRIORITY_CH1[0];
PriorityCh2 = gEeprom.SCANLIST_PRIORITY_CH2[0];
break;
case 1:
if (!att.scanlist2)
return false;
PriorityCh1 = gEeprom.SCANLIST_PRIORITY_CH1[1];
PriorityCh2 = gEeprom.SCANLIST_PRIORITY_CH2[1];
break;
default:
return true;
}
if (PriorityCh1 == Channel)
return false;
if (PriorityCh2 == Channel)
return false;
} }
return true; const ChannelAttributes_t att = gMR_ChannelAttributes[Channel];
if (att.band > BAND7_470MHz) {
return false;
}
if (!bCheckScanList) {
return true;
}
if (VFO >= 2) {
return true;
}
if (!att.scanlist1) {
return false;
}
const uint8_t PriorityCh1 = gEeprom.SCANLIST_PRIORITY_CH1[VFO];
const uint8_t PriorityCh2 = gEeprom.SCANLIST_PRIORITY_CH2[VFO];
return PriorityCh1 != Channel && PriorityCh2 != Channel;
} }
uint8_t RADIO_FindNextChannel(uint8_t Channel, int8_t Direction, bool bCheckScanList, uint8_t VFO) uint8_t RADIO_FindNextChannel(uint8_t Channel, int8_t Direction, bool bCheckScanList, uint8_t VFO)
{ {
unsigned int i; for (unsigned int i = 0; IS_MR_CHANNEL(i); i++, Channel += Direction) {
if (Channel == 0xFF) {
for (i = 0; IS_MR_CHANNEL(i); i++)
{
if (Channel == 0xFF)
Channel = MR_CHANNEL_LAST; Channel = MR_CHANNEL_LAST;
else } else if (!IS_MR_CHANNEL(Channel)) {
if (!IS_MR_CHANNEL(Channel))
Channel = MR_CHANNEL_FIRST; Channel = MR_CHANNEL_FIRST;
}
if (RADIO_CheckValidChannel(Channel, bCheckScanList, VFO)) if (RADIO_CheckValidChannel(Channel, bCheckScanList, VFO)) {
return Channel; return Channel;
}
Channel += Direction;
} }
return 0xFF; return 0xFF;