From 685ecb062b68b71943bca5f34a9829e54d123c14 Mon Sep 17 00:00:00 2001 From: Krzysiek Egzmont Date: Fri, 12 Jan 2024 14:42:03 +0100 Subject: [PATCH] Refactor --- app/main.c | 41 +++++++++++++++++------------------------ functions.c | 6 ++---- misc.h | 3 --- scheduler.c | 45 ++++++++++++++++++++++----------------------- 4 files changed, 41 insertions(+), 54 deletions(-) diff --git a/app/main.c b/app/main.c index ee5e11c..7c2faab 100644 --- a/app/main.c +++ b/app/main.c @@ -459,9 +459,7 @@ static void MAIN_Key_DIGITS(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld) static void MAIN_Key_EXIT(bool bKeyPressed, bool bKeyHeld) { - if (!bKeyHeld && bKeyPressed) - { // exit key pressed - + if (!bKeyHeld && bKeyPressed) { // exit key pressed gBeepToPlay = BEEP_1KHZ_60MS_OPTIONAL; #ifdef ENABLE_DTMF_CALLING @@ -473,47 +471,42 @@ static void MAIN_Key_EXIT(bool bKeyPressed, bool bKeyHeld) } #endif - #ifdef ENABLE_FMRADIO - if (!gFmRadioMode) - #endif +#ifdef ENABLE_FMRADIO + if (!gFmRadioMode) +#endif { - if (gScanStateDir == SCAN_OFF) - { + if (gScanStateDir == SCAN_OFF) { if (gInputBoxIndex == 0) return; gInputBox[--gInputBoxIndex] = 10; gKeyInputCountdown = key_input_timeout_500ms; - #ifdef ENABLE_VOICE - if (gInputBoxIndex == 0) - gAnotherVoiceID = VOICE_ID_CANCEL; - #endif +#ifdef ENABLE_VOICE + if (gInputBoxIndex == 0) + gAnotherVoiceID = VOICE_ID_CANCEL; +#endif } - else - { + else { gScanKeepResult = false; CHFRSCANNER_Stop(); - #ifdef ENABLE_VOICE - gAnotherVoiceID = VOICE_ID_SCANNING_STOP; - #endif +#ifdef ENABLE_VOICE + gAnotherVoiceID = VOICE_ID_SCANNING_STOP; +#endif } gRequestDisplayScreen = DISPLAY_MAIN; return; } - #ifdef ENABLE_FMRADIO - ACTION_FM(); - #endif - +#ifdef ENABLE_FMRADIO + ACTION_FM(); +#endif return; } - if (bKeyHeld && bKeyPressed) - { // exit key held down - + if (bKeyHeld && bKeyPressed) { // exit key held down if (gInputBoxIndex > 0 || gDTMF_InputBox_Index > 0 || gDTMF_InputMode) { // cancel key input mode (channel/frequency entry) gDTMF_InputMode = false; diff --git a/functions.c b/functions.c index 54875f1..aed2cbf 100644 --- a/functions.c +++ b/functions.c @@ -233,15 +233,13 @@ void FUNCTION_Select(FUNCTION_Type_t Function) gCurrentFunction = Function; - if (bWasPowerSave && Function != FUNCTION_POWER_SAVE) - { + if (bWasPowerSave && Function != FUNCTION_POWER_SAVE) { BK4819_Conditional_RX_TurnOn_and_GPIO6_Enable(); gRxIdleMode = false; UI_DisplayStatus(); } - switch (Function) - { + switch (Function) { case FUNCTION_FOREGROUND: FUNCTION_Foreground(PreviousFunction); return; diff --git a/misc.h b/misc.h index 7384c31..62247ba 100644 --- a/misc.h +++ b/misc.h @@ -207,9 +207,6 @@ extern volatile bool gTxTimeoutReached; extern volatile uint16_t gTailNoteEliminationCountdown_10ms; -#ifdef ENABLE_FMRADIO - extern volatile uint16_t gFmPlayCountdown_10ms; -#endif #ifdef ENABLE_NOAA extern volatile uint16_t gNOAA_Countdown_10ms; #endif diff --git a/scheduler.c b/scheduler.c index faa16cd..f76b4a6 100644 --- a/scheduler.c +++ b/scheduler.c @@ -53,8 +53,7 @@ void SystickHandler(void) gNextTimeslice = true; - if ((gGlobalSysTickCounter % 50) == 0) - { + if ((gGlobalSysTickCounter % 50) == 0) { gNextTimeslice_500ms = true; DECREMENT_AND_TRIGGER(gTxTimerCountdown_500ms, gTxTimeoutReached); @@ -64,9 +63,9 @@ void SystickHandler(void) if ((gGlobalSysTickCounter & 3) == 0) gNextTimeslice40ms = true; - #ifdef ENABLE_NOAA - DECREMENT(gNOAACountdown_10ms); - #endif +#ifdef ENABLE_NOAA + DECREMENT(gNOAACountdown_10ms); +#endif DECREMENT(gFoundCDCSSCountdown_10ms); @@ -82,12 +81,12 @@ void SystickHandler(void) if (gCurrentFunction != FUNCTION_MONITOR && gCurrentFunction != FUNCTION_TRANSMIT && gCurrentFunction != FUNCTION_RECEIVE) DECREMENT_AND_TRIGGER(gDualWatchCountdown_10ms, gScheduleDualWatch); - #ifdef ENABLE_NOAA - if (gScanStateDir == SCAN_OFF && !gCssBackgroundScan && gEeprom.DUAL_WATCH == DUAL_WATCH_OFF) - if (gIsNoaaMode && gCurrentFunction != FUNCTION_MONITOR && gCurrentFunction != FUNCTION_TRANSMIT) - if (gCurrentFunction != FUNCTION_RECEIVE) - DECREMENT_AND_TRIGGER(gNOAA_Countdown_10ms, gScheduleNOAA); - #endif +#ifdef ENABLE_NOAA + if (gScanStateDir == SCAN_OFF && !gCssBackgroundScan && gEeprom.DUAL_WATCH == DUAL_WATCH_OFF) + if (gIsNoaaMode && gCurrentFunction != FUNCTION_MONITOR && gCurrentFunction != FUNCTION_TRANSMIT) + if (gCurrentFunction != FUNCTION_RECEIVE) + DECREMENT_AND_TRIGGER(gNOAA_Countdown_10ms, gScheduleNOAA); +#endif if (gScanStateDir != SCAN_OFF) if (gCurrentFunction != FUNCTION_MONITOR && gCurrentFunction != FUNCTION_TRANSMIT) @@ -95,19 +94,19 @@ void SystickHandler(void) DECREMENT_AND_TRIGGER(gTailNoteEliminationCountdown_10ms, gFlagTailNoteEliminationComplete); - #ifdef ENABLE_VOICE - DECREMENT_AND_TRIGGER(gCountdownToPlayNextVoice_10ms, gFlagPlayQueuedVoice); - #endif - - #ifdef ENABLE_FMRADIO - if (gFM_ScanState != FM_SCAN_OFF && gCurrentFunction != FUNCTION_MONITOR) - if (gCurrentFunction != FUNCTION_TRANSMIT && gCurrentFunction != FUNCTION_RECEIVE) - DECREMENT_AND_TRIGGER(gFmPlayCountdown_10ms, gScheduleFM); - #endif +#ifdef ENABLE_VOICE + DECREMENT_AND_TRIGGER(gCountdownToPlayNextVoice_10ms, gFlagPlayQueuedVoice); +#endif - #ifdef ENABLE_VOX - DECREMENT(gVoxStopCountdown_10ms); - #endif +#ifdef ENABLE_FMRADIO + if (gFM_ScanState != FM_SCAN_OFF && gCurrentFunction != FUNCTION_MONITOR) + if (gCurrentFunction != FUNCTION_TRANSMIT && gCurrentFunction != FUNCTION_RECEIVE) + DECREMENT_AND_TRIGGER(gFmPlayCountdown_10ms, gScheduleFM); +#endif + +#ifdef ENABLE_VOX + DECREMENT(gVoxStopCountdown_10ms); +#endif DECREMENT(boot_counter_10ms); }