From a153e63be1ab3bb1d00f2d02dea04dbdfbdee275 Mon Sep 17 00:00:00 2001 From: Juan Antonio Date: Sat, 9 Dec 2023 12:23:03 +0100 Subject: [PATCH] Add function to test if serial configuration is in progress This was formely tested all over using testing for the state of gSerialConfigCountDown_500ms in a couple of ways. This logic have been extracted into a function to make the code more readable. Also testing it with > 0 was a bit misleading as the variable is unsigned so tesing with == and != is enough. --- app/app.c | 15 ++++++--------- app/generic.c | 2 +- app/uart.c | 4 +++- misc.h | 2 ++ radio.c | 24 ++++++++++++------------ 5 files changed, 24 insertions(+), 23 deletions(-) diff --git a/app/app.c b/app/app.c index 6c66483..2dd3f3b 100644 --- a/app/app.c +++ b/app/app.c @@ -59,6 +59,7 @@ #include "misc.h" #include "radio.h" #include "settings.h" + #if defined(ENABLE_OVERLAY) #include "sram-overlay.h" #endif @@ -810,7 +811,7 @@ static void HandleVox(void) if (gCurrentFunction == FUNCTION_POWER_SAVE) FUNCTION_Select(FUNCTION_FOREGROUND); - if (gCurrentFunction != FUNCTION_TRANSMIT && gSerialConfigCountDown_500ms == 0) + if (gCurrentFunction != FUNCTION_TRANSMIT && !SerialConfigInProgress()) { #ifdef ENABLE_DTMF_CALLING gDTMF_ReplyState = DTMF_REPLY_NONE; @@ -831,7 +832,7 @@ void APP_Update(void) } #endif - if (gCurrentFunction == FUNCTION_TRANSMIT && (gTxTimeoutReached || gSerialConfigCountDown_500ms > 0)) + if (gCurrentFunction == FUNCTION_TRANSMIT && (gTxTimeoutReached || SerialConfigInProgress())) { // transmitter timed out or must de-key gTxTimeoutReached = false; @@ -1037,9 +1038,9 @@ static void CheckKeys(void) // -------------------- PTT ------------------------ if (gPttIsPressed) { - if (GPIO_CheckBit(&GPIOC->DATA, GPIOC_PIN_PTT) || gSerialConfigCountDown_500ms > 0) + if (GPIO_CheckBit(&GPIOC->DATA, GPIOC_PIN_PTT) || SerialConfigInProgress()) { // PTT released or serial comms config in progress - if (++gPttDebounceCounter >= 3 || gSerialConfigCountDown_500ms > 0) // 30ms + if (++gPttDebounceCounter >= 3 || SerialConfigInProgress()) // 30ms { // stop transmitting ProcessKey(KEY_PTT, false, false); gPttIsPressed = false; @@ -1050,7 +1051,7 @@ static void CheckKeys(void) else gPttDebounceCounter = 0; } - else if (!GPIO_CheckBit(&GPIOC->DATA, GPIOC_PIN_PTT) && gSerialConfigCountDown_500ms == 0) + else if (!GPIO_CheckBit(&GPIOC->DATA, GPIOC_PIN_PTT) && !SerialConfigInProgress()) { // PTT pressed if (++gPttDebounceCounter >= 3) // 30ms { // start transmitting @@ -1391,10 +1392,6 @@ void APP_TimeSlice500ms(void) } } - if (gSerialConfigCountDown_500ms > 0) - { - } - if (gReducedService) { BOARD_ADC_GetBatteryInfo(&gBatteryCurrentVoltage, &gBatteryCurrent); diff --git a/app/generic.c b/app/generic.c index 7fd6fae..d0b883f 100644 --- a/app/generic.c +++ b/app/generic.c @@ -107,7 +107,7 @@ void GENERIC_Key_PTT(bool bKeyPressed) { gInputBoxIndex = 0; - if (!bKeyPressed || gSerialConfigCountDown_500ms > 0) + if (!bKeyPressed || SerialConfigInProgress()) { // PTT released if (gCurrentFunction == FUNCTION_TRANSMIT) { // we are transmitting .. stop diff --git a/app/uart.c b/app/uart.c index 14db250..980a2b7 100644 --- a/app/uart.c +++ b/app/uart.c @@ -36,10 +36,12 @@ #include "functions.h" #include "misc.h" #include "settings.h" +#include "version.h" + #if defined(ENABLE_OVERLAY) #include "sram-overlay.h" #endif -#include "version.h" + #define DMA_INDEX(x, y) (((x) + (y)) % sizeof(UART_DMA_Buffer)) diff --git a/misc.h b/misc.h index e230b9d..b544d76 100644 --- a/misc.h +++ b/misc.h @@ -333,4 +333,6 @@ unsigned long StrToUL(const char * str); void FUNCTION_NOP(); +inline bool SerialConfigInProgress() { return gSerialConfigCountDown_500ms != 0; } + #endif diff --git a/radio.c b/radio.c index 7a6b774..f05f2c6 100644 --- a/radio.c +++ b/radio.c @@ -996,13 +996,13 @@ void RADIO_PrepareTX(void) RADIO_SelectCurrentVfo(); if(TX_freq_check(gCurrentVfo->pTX->Frequency) != 0 - #if defined(ENABLE_ALARM) || defined(ENABLE_TX1750) +#if defined(ENABLE_ALARM) || defined(ENABLE_TX1750) && gAlarmState != ALARM_STATE_SITE_ALARM - #endif - ) { +#endif + ){ // TX frequency not allowed State = VFO_STATE_TX_DISABLE; - } else if (gSerialConfigCountDown_500ms > 0) { + } else if (SerialConfigInProgress()) { // TX is disabled or config upload/download in progress State = VFO_STATE_TX_DISABLE; } else if (gCurrentVfo->BUSY_CHANNEL_LOCK && gCurrentFunction == FUNCTION_RECEIVE) { @@ -1015,31 +1015,31 @@ void RADIO_PrepareTX(void) // over voltage .. this is being a pain State = VFO_STATE_VOLTAGE_HIGH; } - #ifndef ENABLE_TX_WHEN_AM +#ifndef ENABLE_TX_WHEN_AM else if (gCurrentVfo->Modulation != MODULATION_FM) { // not allowed to TX if in AM mode State = VFO_STATE_TX_DISABLE; } - #endif +#endif if (State != VFO_STATE_NORMAL) { // TX not allowed RADIO_SetVfoState(State); - #if defined(ENABLE_ALARM) || defined(ENABLE_TX1750) +#if defined(ENABLE_ALARM) || defined(ENABLE_TX1750) gAlarmState = ALARM_STATE_OFF; - #endif +#endif - #ifdef ENABLE_DTMF_CALLING +#ifdef ENABLE_DTMF_CALLING gDTMF_ReplyState = DTMF_REPLY_NONE; - #endif +#endif AUDIO_PlayBeep(BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL); return; } // TX is allowed - #ifdef ENABLE_DTMF_CALLING +#ifdef ENABLE_DTMF_CALLING if (gDTMF_ReplyState == DTMF_REPLY_ANI) { if (gDTMF_CallMode == DTMF_CALL_MODE_DTMF) @@ -1054,7 +1054,7 @@ void RADIO_PrepareTX(void) gDTMF_CallState = DTMF_CALL_STATE_CALL_OUT; } } - #endif +#endif FUNCTION_Select(FUNCTION_TRANSMIT);