Skip to content

Commit

Permalink
Reduce nesting
Browse files Browse the repository at this point in the history
  • Loading branch information
JuantAldea authored and egzumer committed Dec 28, 2023
1 parent ea73311 commit 289418f
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 71 deletions.
47 changes: 21 additions & 26 deletions app/menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ void MENU_CssScanFound(void)
void MENU_StopCssScan(void)
{
gCssBackgroundScan = false;

#ifdef ENABLE_VOICE
gAnotherVoiceID = VOICE_ID_SCANNING_STOP;
#endif
Expand Down Expand Up @@ -133,12 +133,12 @@ int MENU_GetLimits(uint8_t menu_id, int32_t *pMin, int32_t *pMax)
case MENU_ABR_MIN:
*pMin = 0;
*pMax = 9;
break;
break;

case MENU_ABR_MAX:
*pMin = 1;
*pMax = 10;
break;
break;

case MENU_F_LOCK:
*pMin = 0;
Expand Down Expand Up @@ -303,7 +303,7 @@ int MENU_GetLimits(uint8_t menu_id, int32_t *pMin, int32_t *pMax)
*pMin = 0;
*pMax = 2;
break;

#ifdef ENABLE_DTMF_CALLING
case MENU_D_RSP:
*pMin = 0;
Expand Down Expand Up @@ -500,7 +500,7 @@ void MENU_AcceptSetting(void)
break;
edit[i] = ' ';
}

SETTINGS_SaveChannelName(gSubMenuSelection, edit);
return;

Expand Down Expand Up @@ -531,7 +531,7 @@ void MENU_AcceptSetting(void)
case MENU_ABR_MAX:
gEeprom.BACKLIGHT_MAX = gSubMenuSelection;
gEeprom.BACKLIGHT_MIN = MIN(gSubMenuSelection - 1, gEeprom.BACKLIGHT_MIN);
break;
break;

case MENU_ABR_ON_TX_RX:
gSetting_backlight_on_tx_rx = gSubMenuSelection;
Expand Down Expand Up @@ -835,9 +835,9 @@ void MENU_ShowCurrentSetting(void)

case MENU_RESET:
gSubMenuSelection = 0;
break;
break;

case MENU_R_DCS:
case MENU_R_DCS:
case MENU_R_CTCS:
{
DCS_CodeType_t type = gTxVfo->freq_config_RX.CodeType;
Expand Down Expand Up @@ -940,7 +940,7 @@ void MENU_ShowCurrentSetting(void)

case MENU_ABR_MAX:
gSubMenuSelection = gEeprom.BACKLIGHT_MAX;
break;
break;

case MENU_ABR_ON_TX_RX:
gSubMenuSelection = gSetting_backlight_on_tx_rx;
Expand Down Expand Up @@ -1133,7 +1133,7 @@ void MENU_ShowCurrentSetting(void)

case MENU_BATTYP:
gSubMenuSelection = gEeprom.BATTERY_TYPE;
break;
break;

case MENU_F1SHRT:
case MENU_F1LONG:
Expand All @@ -1154,7 +1154,7 @@ void MENU_ShowCurrentSetting(void)
gSubMenuSelection = i;
break;
}

}
break;
}
Expand Down Expand Up @@ -1256,17 +1256,17 @@ static void MENU_Key_0_to_9(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld)
#ifdef ENABLE_VOICE
gAnotherVoiceID = (VOICE_ID_t)Key;
#endif

Frequency = StrToUL(INPUTBOX_GetAscii())*100;
gSubMenuSelection = FREQUENCY_RoundToStep(Frequency, gTxVfo->StepFrequency);

gInputBoxIndex = 0;
return;
}
if (UI_MENU_GetCurrentMenuId() == MENU_MEM_CH ||
UI_MENU_GetCurrentMenuId() == MENU_DEL_CH ||
UI_MENU_GetCurrentMenuId() == MENU_1_CALL ||

if (UI_MENU_GetCurrentMenuId() == MENU_MEM_CH ||
UI_MENU_GetCurrentMenuId() == MENU_DEL_CH ||
UI_MENU_GetCurrentMenuId() == MENU_1_CALL ||
UI_MENU_GetCurrentMenuId() == MENU_MEM_NAME)
{ // enter 3-digit channel number

Expand Down Expand Up @@ -1452,16 +1452,11 @@ static void MENU_Key_MENU(const bool bKeyPressed, const bool bKeyHeld)
return; // next char

// exit
if (memcmp(edit_original, edit, sizeof(edit_original)) == 0)
{ // no change - drop it
gFlagAcceptSetting = false;
gIsInSubMenu = false;
gAskForConfirmation = 0;
}
else
{
gFlagAcceptSetting = false;
gAskForConfirmation = 0;
gFlagAcceptSetting = false;
gAskForConfirmation = 0;
if (memcmp(edit_original, edit, sizeof(edit_original)) == 0) {
// no change - drop it
gIsInSubMenu = false;
}
}
}
Expand Down
70 changes: 25 additions & 45 deletions radio.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,68 +57,48 @@ const char gModulationStr[MODULATION_UKNOWN][4] = {


bool RADIO_CheckValidChannel(uint16_t Channel, bool bCheckScanList, uint8_t VFO)
{ // return true if the channel appears valid

ChannelAttributes_t att;
uint8_t PriorityCh1;
uint8_t PriorityCh2;

if (!IS_MR_CHANNEL(Channel))
{
// return true if the channel appears valid
if (!IS_MR_CHANNEL(Channel)) {
return false;
}

att = gMR_ChannelAttributes[Channel];
const ChannelAttributes_t att = gMR_ChannelAttributes[Channel];

if (att.band > BAND7_470MHz)
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 (!bCheckScanList) {
return true;
}

if (PriorityCh1 == Channel)
return false;
if (VFO >= 2) {
return true;
}

if (PriorityCh2 == Channel)
return false;
if (!att.scanlist1) {
return false;
}

return true;
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)
{
unsigned int i;

for (i = 0; IS_MR_CHANNEL(i); i++)
{
if (Channel == 0xFF)
for (unsigned int i = 0; IS_MR_CHANNEL(i); i++, Channel += Direction) {
if (Channel == 0xFF) {
Channel = MR_CHANNEL_LAST;
else
if (!IS_MR_CHANNEL(Channel))
} else if (!IS_MR_CHANNEL(Channel)) {
Channel = MR_CHANNEL_FIRST;
}

if (RADIO_CheckValidChannel(Channel, bCheckScanList, VFO))
if (RADIO_CheckValidChannel(Channel, bCheckScanList, VFO)) {
return Channel;

Channel += Direction;
}
}

return 0xFF;
Expand Down

0 comments on commit 289418f

Please sign in to comment.