From 2164461449e049b4cbc28fc6d59d2350f80e5413 Mon Sep 17 00:00:00 2001 From: Juan Antonio Date: Thu, 7 Dec 2023 12:12:19 +0100 Subject: [PATCH] Use function to check if in RX mode --- app/action.c | 4 +--- app/app.c | 21 +++++---------------- audio.c | 12 +++--------- functions.c | 12 ++++++++++-- functions.h | 2 +- ui/main.c | 13 ++----------- ui/status.c | 4 +--- 7 files changed, 23 insertions(+), 45 deletions(-) diff --git a/app/action.c b/app/action.c index cad4786..5da5b8a 100644 --- a/app/action.c +++ b/app/action.c @@ -102,9 +102,7 @@ void ACTION_Scan(bool bRestart) #ifdef ENABLE_FMRADIO if (gFmRadioMode) { - if (gCurrentFunction != FUNCTION_RECEIVE && - gCurrentFunction != FUNCTION_MONITOR && - gCurrentFunction != FUNCTION_TRANSMIT) + if (FUNCTION_IsRx()) { GUI_SelectNextDisplay(DISPLAY_FM); diff --git a/app/app.c b/app/app.c index 20d0cbb..3e38955 100644 --- a/app/app.c +++ b/app/app.c @@ -897,12 +897,8 @@ void APP_Update(void) } #ifdef ENABLE_FMRADIO - if (gScheduleFM && - gFM_ScanState != FM_SCAN_OFF && - gCurrentFunction != FUNCTION_MONITOR && - gCurrentFunction != FUNCTION_RECEIVE && - gCurrentFunction != FUNCTION_TRANSMIT) - { // switch to FM radio mode + if (gScheduleFM && gFM_ScanState != FM_SCAN_OFF && !FUNCTION_IsRx()) { + // switch to FM radio mode FM_Play(); gScheduleFM = false; } @@ -1479,11 +1475,7 @@ void APP_TimeSlice500ms(void) GUI_DisplayType_t disp = DISPLAY_INVALID; #ifdef ENABLE_FMRADIO - if (gFmRadioMode && - gCurrentFunction != FUNCTION_RECEIVE && - gCurrentFunction != FUNCTION_MONITOR && - gCurrentFunction != FUNCTION_TRANSMIT) - { + if (gFmRadioMode && ! FUNCTION_IsRx()) { disp = DISPLAY_FM; } #endif @@ -1509,11 +1501,8 @@ void APP_TimeSlice500ms(void) { RADIO_SetVfoState(VFO_STATE_NORMAL); #ifdef ENABLE_FMRADIO - if (gCurrentFunction != FUNCTION_RECEIVE && - gCurrentFunction != FUNCTION_TRANSMIT && - gCurrentFunction != FUNCTION_MONITOR && - gFmRadioMode) - { // switch back to FM radio mode + if (gFmRadioMode && !FUNCTION_IsRx()) { + // switch back to FM radio mode FM_Start(); GUI_SelectNextDisplay(DISPLAY_FM); } diff --git a/audio.c b/audio.c index 07e3d48..9079517 100644 --- a/audio.c +++ b/audio.c @@ -255,9 +255,7 @@ void AUDIO_PlaySingleVoice(bool bFlag) VoiceID += VOICE_ID_ENG_BASE; } - if (gCurrentFunction == FUNCTION_RECEIVE || - gCurrentFunction == FUNCTION_MONITOR || - gCurrentFunction == FUNCTION_INCOMING) // 1of11 + if (FUNCTION_IsRx()) // 1of11 BK4819_SetAF(BK4819_AF_MUTE); #ifdef ENABLE_FMRADIO @@ -281,9 +279,7 @@ void AUDIO_PlaySingleVoice(bool bFlag) { SYSTEM_DelayMs(Delay * 10); - if (gCurrentFunction == FUNCTION_RECEIVE || - gCurrentFunction == FUNCTION_MONITOR || - gCurrentFunction == FUNCTION_INCOMING) // 1of11 + if (FUNCTION_IsRx()) // 1of11 RADIO_SetModulation(gRxVfo->Modulation); #ifdef ENABLE_FMRADIO @@ -422,9 +418,7 @@ void AUDIO_PlayQueuedVoice(void) } } - if (gCurrentFunction == FUNCTION_RECEIVE || - gCurrentFunction == FUNCTION_MONITOR || - gCurrentFunction == FUNCTION_INCOMING) + if (FUNCTION_IsRx()) { RADIO_SetModulation(gRxVfo->Modulation); // 1of11 } diff --git a/functions.c b/functions.c index 5d8107d..8ad703c 100644 --- a/functions.c +++ b/functions.c @@ -42,6 +42,14 @@ FUNCTION_Type_t gCurrentFunction; +inline bool FUNCTION_IsRx() +{ + return gCurrentFunction == FUNCTION_MONITOR || + gCurrentFunction == FUNCTION_INCOMING || + gCurrentFunction == FUNCTION_RECEIVE; +} + + void FUNCTION_Init(void) { #ifdef ENABLE_NOAA @@ -119,7 +127,7 @@ void FUNCTION_Select(FUNCTION_Type_t Function) if (gFmRadioMode) gFM_RestoreCountdown_10ms = fm_restore_countdown_10ms; #endif - + #ifdef ENABLE_DTMF_CALLING if (gDTMF_CallState == DTMF_CALL_STATE_CALL_OUT || gDTMF_CallState == DTMF_CALL_STATE_RECEIVED || @@ -147,7 +155,7 @@ void FUNCTION_Select(FUNCTION_Type_t Function) gMonitor = false; - BK4819_DisableVox(); + BK4819_DisableVox(); BK4819_Sleep(); BK4819_ToggleGpioOut(BK4819_GPIO0_PIN28_RX_ENABLE, false); diff --git a/functions.h b/functions.h index 4194d86..12c72cc 100644 --- a/functions.h +++ b/functions.h @@ -36,6 +36,6 @@ extern FUNCTION_Type_t gCurrentFunction; void FUNCTION_Init(void); void FUNCTION_Select(FUNCTION_Type_t Function); +bool FUNCTION_IsRx(); #endif - diff --git a/ui/main.c b/ui/main.c index 5cfbd12..c2daa06 100644 --- a/ui/main.c +++ b/ui/main.c @@ -247,11 +247,8 @@ void DisplayRSSIBar(const bool now) ST7565_BlitFullScreen(); #endif - } - - #ifdef ENABLE_AGC_SHOW_DATA static void PrintAGC(bool now) { @@ -444,11 +441,7 @@ void UI_DisplayMain(void) else { // receiving .. show the RX symbol mode = VFO_MODE_RX; - if ((gCurrentFunction == FUNCTION_RECEIVE || - gCurrentFunction == FUNCTION_MONITOR || - gCurrentFunction == FUNCTION_INCOMING) && - gEeprom.RX_VFO == vfo_num) - { + if (FUNCTION_IsRx() && gEeprom.RX_VFO == vfo_num) { #ifdef ENABLE_SMALL_BOLD UI_PrintStringSmallBold("RX", 14, 0, line); #else @@ -738,9 +731,7 @@ void UI_DisplayMain(void) if (center_line == CENTER_LINE_NONE) { // we're free to use the middle line - const bool rx = (gCurrentFunction == FUNCTION_RECEIVE || - gCurrentFunction == FUNCTION_MONITOR || - gCurrentFunction == FUNCTION_INCOMING); + const bool rx = FUNCTION_IsRx(); #ifdef ENABLE_AUDIO_BAR if (gSetting_mic_bar && gCurrentFunction == FUNCTION_TRANSMIT) { diff --git a/ui/status.c b/ui/status.c index fcce6c1..0125b44 100644 --- a/ui/status.c +++ b/ui/status.c @@ -53,9 +53,7 @@ void UI_DisplayStatus() x1 = x + sizeof(BITMAP_TX); } else - if (gCurrentFunction == FUNCTION_RECEIVE || - gCurrentFunction == FUNCTION_MONITOR || - gCurrentFunction == FUNCTION_INCOMING) + if (FUNCTION_IsRx()) { memmove(line + x, BITMAP_RX, sizeof(BITMAP_RX)); x1 = x + sizeof(BITMAP_RX);