Skip to content

Commit

Permalink
Deduplicate code
Browse files Browse the repository at this point in the history
* Reuse INPUTBOX_GetAscii
  • Loading branch information
JuantAldea committed Dec 26, 2023
1 parent 6b4b9a1 commit bc1fe87
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 59 deletions.
68 changes: 36 additions & 32 deletions app/action.c
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,8 @@ void ACTION_Scan(bool bRestart)

GUI_SelectNextDisplay(DISPLAY_MAIN);

gUpdateStatus = true;

if (gScanStateDir != SCAN_OFF) {
// already scanning

Expand Down Expand Up @@ -227,7 +229,6 @@ void ACTION_Scan(bool bRestart)
gDualWatchActive = false;
}

gUpdateStatus = true;
}


Expand Down Expand Up @@ -291,22 +292,26 @@ void ACTION_Handle(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld)
break;
}

if (!bKeyHeld && bKeyPressed) // button pushed
{
if (bKeyPressed && !bKeyHeld) {
// button pushed
return;
}

if (!bKeyPressed && bKeyHeld) {
//ignore release if held
return;
}

// held or released beyond this point

if(!(bKeyHeld && !bKeyPressed)) // don't beep on released after hold
if(bKeyPressed || !bKeyHeld) {
// don't beep on released after hold
gBeepToPlay = BEEP_1KHZ_60MS_OPTIONAL;
}

if (bKeyHeld || bKeyPressed) // held
{
if (bKeyPressed || bKeyHeld) {
// held
funcShort = funcLong;

if (!bKeyPressed) //ignore release if held
return;
}

// held or released after short press beyond this point
Expand All @@ -318,32 +323,34 @@ void ACTION_Handle(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld)
#ifdef ENABLE_FMRADIO
void ACTION_FM(void)
{
if (gCurrentFunction != FUNCTION_TRANSMIT && gCurrentFunction != FUNCTION_MONITOR)
{
gInputBoxIndex = 0;
if (gCurrentFunction == FUNCTION_TRANSMIT || gCurrentFunction == FUNCTION_MONITOR) {
return;
}

if (gFmRadioMode) {
FM_TurnOff();
gFlagReconfigureVfos = true;
gRequestDisplayScreen = DISPLAY_MAIN;
gInputBoxIndex = 0;

if (gFmRadioMode) {
FM_TurnOff();
gFlagReconfigureVfos = true;
gRequestDisplayScreen = DISPLAY_MAIN;

#ifdef ENABLE_VOX
gVoxResumeCountdown = 80;
gVoxResumeCountdown = 80;
#endif
return;
}
return;
}

gMonitor = false;
gMonitor = false;

RADIO_SelectVfos();
RADIO_SetupRegisters(true);
RADIO_SelectVfos();
RADIO_SetupRegisters(true);

FM_Start();
FM_Start();

gRequestDisplayScreen = DISPLAY_FM;
}
gRequestDisplayScreen = DISPLAY_FM;
}


static void ACTION_Scan_FM(bool bRestart)
{
if (FUNCTION_IsRx()) {
Expand All @@ -363,17 +370,14 @@ static void ACTION_Scan_FM(bool bRestart)
return;
}

gFM_ChannelPosition = 0;
gFM_AutoScan = bRestart;
uint16_t Frequency;

if (bRestart) {
gFM_AutoScan = true;
gFM_ChannelPosition = 0;
FM_EraseChannels();
Frequency = gEeprom.FM_LowerLimit;
Frequency = gEeprom.FM_LowerLimit;
} else {
gFM_AutoScan = false;
gFM_ChannelPosition = 0;
Frequency = gEeprom.FM_FrequencyPlaying;
Frequency = gEeprom.FM_FrequencyPlaying;
}

BK1080_GetFrequencyDeviation(Frequency);
Expand Down
4 changes: 1 addition & 3 deletions app/app.c
Original file line number Diff line number Diff line change
Expand Up @@ -1113,9 +1113,7 @@ void APP_TimeSlice10ms(void)
#endif
}

if (gUpdateDisplay)
{
gUpdateDisplay = false;
if (gUpdateDisplay) {
GUI_DisplayScreen();
}

Expand Down
12 changes: 2 additions & 10 deletions app/fm.c
Original file line number Diff line number Diff line change
Expand Up @@ -392,16 +392,8 @@ static void Key_EXIT(uint8_t state)
{
gInputBox[--gInputBoxIndex] = 10;

if (gInputBoxIndex)
{
if (gInputBoxIndex != 1)
{
gRequestDisplayScreen = DISPLAY_FM;
return;
}

if (gInputBox[0] != 0)
{
if (gInputBoxIndex) {
if (gInputBoxIndex != 1 || gInputBox[0] != 0) {
gRequestDisplayScreen = DISPLAY_FM;
return;
}
Expand Down
17 changes: 3 additions & 14 deletions ui/helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,29 +29,18 @@

void UI_GenerateChannelString(char *pString, const uint8_t Channel)
{
unsigned int i;

if (gInputBoxIndex == 0)
{
if (gInputBoxIndex == 0) {
sprintf(pString, "CH-%02u", Channel + 1);
return;
}

pString[0] = 'C';
pString[1] = 'H';
pString[2] = '-';
for (i = 0; i < 2; i++)
pString[i + 3] = (gInputBox[i] == 10) ? '-' : gInputBox[i] + '0';
sprintf(pString, "CH-%2s", INPUTBOX_GetAscii());
}

void UI_GenerateChannelStringEx(char *pString, const bool bShowPrefix, const uint8_t ChannelNumber)
{
if (gInputBoxIndex > 0) {
for (unsigned int i = 0; i < 3; i++) {
pString[i] = (gInputBox[i] == 10) ? '-' : gInputBox[i] + '0';
}

pString[3] = 0;
sprintf(pString, "%3s", INPUTBOX_GetAscii());
return;
}

Expand Down
1 change: 1 addition & 0 deletions ui/ui.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ static_assert(ARRAY_SIZE(UI_DisplayFunctions) == DISPLAY_N_ELEM);

void GUI_DisplayScreen(void)
{
gUpdateDisplay = false;
if (gScreenToDisplay != DISPLAY_INVALID) {
UI_DisplayFunctions[gScreenToDisplay]();
}
Expand Down

0 comments on commit bc1fe87

Please sign in to comment.