Refactoring

This commit is contained in:
Krzysiek Egzmont
2023-10-17 01:31:08 +02:00
parent 298ff29cf4
commit 0c0cbb232c
5 changed files with 156 additions and 157 deletions

View File

@@ -22,7 +22,7 @@
//static void ACTION_FlashLight(void) //static void ACTION_FlashLight(void)
void ACTION_Power(void); void ACTION_Power(void);
void ACTION_Monitor(void); void ACTION_Monitor(void);
void ACTION_Scan(bool bFlag); void ACTION_Scan(bool bRestart);
#ifdef ENABLE_VOX #ifdef ENABLE_VOX
void ACTION_Vox(void); void ACTION_Vox(void);
#endif #endif

200
app/app.c
View File

@@ -943,38 +943,38 @@ void APP_Update(void)
if (gCurrentFunction != FUNCTION_TRANSMIT) if (gCurrentFunction != FUNCTION_TRANSMIT)
APP_HandleFunction(); APP_HandleFunction();
#ifdef ENABLE_FMRADIO #ifdef ENABLE_FMRADIO
// if (gFmRadioCountdown_500ms > 0) // if (gFmRadioCountdown_500ms > 0)
if (gFmRadioMode && gFmRadioCountdown_500ms > 0) // 1of11 if (gFmRadioMode && gFmRadioCountdown_500ms > 0) // 1of11
return; return;
#endif #endif
#ifdef ENABLE_VOICE #ifdef ENABLE_VOICE
if (gScreenToDisplay != DISPLAY_SCANNER && gScanStateDir != SCAN_OFF && gScheduleScanListen && !gPttIsPressed && gVoiceWriteIndex == 0) if (gScreenToDisplay != DISPLAY_SCANNER && gScanStateDir != SCAN_OFF && gScheduleScanListen && !gPttIsPressed && gVoiceWriteIndex == 0)
#else #else
if (gScreenToDisplay != DISPLAY_SCANNER && gScanStateDir != SCAN_OFF && gScheduleScanListen && !gPttIsPressed) if (gScreenToDisplay != DISPLAY_SCANNER && gScanStateDir != SCAN_OFF && gScheduleScanListen && !gPttIsPressed)
#endif #endif
{ // scanning { // scanning
SCANNER_ContinueScanning(); SCANNER_ContinueScanning();
} }
#ifdef ENABLE_VOICE #ifdef ENABLE_VOICE
if (gCssScanMode == CSS_SCAN_MODE_SCANNING && gScheduleScanListen && gVoiceWriteIndex == 0) if (gCssScanMode == CSS_SCAN_MODE_SCANNING && gScheduleScanListen && gVoiceWriteIndex == 0)
#else #else
if (gCssScanMode == CSS_SCAN_MODE_SCANNING && gScheduleScanListen) if (gCssScanMode == CSS_SCAN_MODE_SCANNING && gScheduleScanListen)
#endif #endif
{ {
MENU_SelectNextCode(); MENU_SelectNextCode();
gScheduleScanListen = false; gScheduleScanListen = false;
} }
#ifdef ENABLE_NOAA #ifdef ENABLE_NOAA
#ifdef ENABLE_VOICE #ifdef ENABLE_VOICE
if (gEeprom.DUAL_WATCH == DUAL_WATCH_OFF && gIsNoaaMode && gScheduleNOAA && gVoiceWriteIndex == 0) if (gEeprom.DUAL_WATCH == DUAL_WATCH_OFF && gIsNoaaMode && gScheduleNOAA && gVoiceWriteIndex == 0)
#else #else
if (gEeprom.DUAL_WATCH == DUAL_WATCH_OFF && gIsNoaaMode && gScheduleNOAA) if (gEeprom.DUAL_WATCH == DUAL_WATCH_OFF && gIsNoaaMode && gScheduleNOAA)
#endif #endif
{ {
NOAA_IncreaseChannel(); NOAA_IncreaseChannel();
RADIO_SetupRegisters(false); RADIO_SetupRegisters(false);
@@ -982,23 +982,23 @@ void APP_Update(void)
gNOAA_Countdown_10ms = 7; // 70ms gNOAA_Countdown_10ms = 7; // 70ms
gScheduleNOAA = false; gScheduleNOAA = false;
} }
#endif #endif
// toggle between the VFO's if dual watch is enabled // toggle between the VFO's if dual watch is enabled
if (gScreenToDisplay != DISPLAY_SCANNER && gEeprom.DUAL_WATCH != DUAL_WATCH_OFF) if (gScreenToDisplay != DISPLAY_SCANNER && gEeprom.DUAL_WATCH != DUAL_WATCH_OFF)
{ {
#ifdef ENABLE_VOICE #ifdef ENABLE_VOICE
if (gScheduleDualWatch && gVoiceWriteIndex == 0) if (gScheduleDualWatch && gVoiceWriteIndex == 0)
#else #else
if (gScheduleDualWatch) if (gScheduleDualWatch)
#endif #endif
{ {
if (gScanStateDir == SCAN_OFF && gCssScanMode == CSS_SCAN_MODE_OFF) if (gScanStateDir == SCAN_OFF && gCssScanMode == CSS_SCAN_MODE_OFF)
{ {
if (!gPttIsPressed && if (!gPttIsPressed &&
#ifdef ENABLE_FMRADIO #ifdef ENABLE_FMRADIO
!gFmRadioMode && !gFmRadioMode &&
#endif #endif
gDTMF_CallState == DTMF_CALL_STATE_NONE && gDTMF_CallState == DTMF_CALL_STATE_NONE &&
gCurrentFunction != FUNCTION_POWER_SAVE) gCurrentFunction != FUNCTION_POWER_SAVE)
{ {
@@ -1016,89 +1016,89 @@ void APP_Update(void)
} }
} }
#ifdef ENABLE_FMRADIO #ifdef ENABLE_FMRADIO
if (gScheduleFM && if (gScheduleFM &&
gFM_ScanState != FM_SCAN_OFF && gFM_ScanState != FM_SCAN_OFF &&
gCurrentFunction != FUNCTION_MONITOR && gCurrentFunction != FUNCTION_MONITOR &&
gCurrentFunction != FUNCTION_RECEIVE && gCurrentFunction != FUNCTION_RECEIVE &&
gCurrentFunction != FUNCTION_TRANSMIT) gCurrentFunction != FUNCTION_TRANSMIT)
{ // switch to FM radio mode { // switch to FM radio mode
FM_Play(); FM_Play();
gScheduleFM = false; gScheduleFM = false;
} }
#endif #endif
#ifdef ENABLE_VOX #ifdef ENABLE_VOX
if (gEeprom.VOX_SWITCH) if (gEeprom.VOX_SWITCH)
APP_HandleVox(); APP_HandleVox();
#endif #endif
if (gSchedulePowerSave) if (gSchedulePowerSave)
{ {
#ifdef ENABLE_NOAA #ifdef ENABLE_NOAA
if ( if (
#ifdef ENABLE_FMRADIO #ifdef ENABLE_FMRADIO
gFmRadioMode || gFmRadioMode ||
#endif #endif
gPttIsPressed || gPttIsPressed ||
gKeyBeingHeld || gKeyBeingHeld ||
gEeprom.BATTERY_SAVE == 0 || gEeprom.BATTERY_SAVE == 0 ||
gScanStateDir != SCAN_OFF || gScanStateDir != SCAN_OFF ||
gCssScanMode != CSS_SCAN_MODE_OFF || gCssScanMode != CSS_SCAN_MODE_OFF ||
gScreenToDisplay != DISPLAY_MAIN || gScreenToDisplay != DISPLAY_MAIN ||
gDTMF_CallState != DTMF_CALL_STATE_NONE) gDTMF_CallState != DTMF_CALL_STATE_NONE)
{ {
gBatterySaveCountdown_10ms = battery_save_count_10ms; gBatterySaveCountdown_10ms = battery_save_count_10ms;
} }
else if ((IS_NOT_NOAA_CHANNEL(gEeprom.ScreenChannel[0]) && IS_NOT_NOAA_CHANNEL(gEeprom.ScreenChannel[1])) || !gIsNoaaMode) else if ((IS_NOT_NOAA_CHANNEL(gEeprom.ScreenChannel[0]) && IS_NOT_NOAA_CHANNEL(gEeprom.ScreenChannel[1])) || !gIsNoaaMode)
{ {
//if (gCurrentFunction != FUNCTION_POWER_SAVE) //if (gCurrentFunction != FUNCTION_POWER_SAVE)
FUNCTION_Select(FUNCTION_POWER_SAVE); FUNCTION_Select(FUNCTION_POWER_SAVE);
} }
else else
{ {
gBatterySaveCountdown_10ms = battery_save_count_10ms; gBatterySaveCountdown_10ms = battery_save_count_10ms;
} }
#else #else
if ( if (
#ifdef ENABLE_FMRADIO #ifdef ENABLE_FMRADIO
gFmRadioMode || gFmRadioMode ||
#endif #endif
gPttIsPressed || gPttIsPressed ||
gKeyBeingHeld || gKeyBeingHeld ||
gEeprom.BATTERY_SAVE == 0 || gEeprom.BATTERY_SAVE == 0 ||
gScanStateDir != SCAN_OFF || gScanStateDir != SCAN_OFF ||
gCssScanMode != CSS_SCAN_MODE_OFF || gCssScanMode != CSS_SCAN_MODE_OFF ||
gScreenToDisplay != DISPLAY_MAIN || gScreenToDisplay != DISPLAY_MAIN ||
gDTMF_CallState != DTMF_CALL_STATE_NONE) gDTMF_CallState != DTMF_CALL_STATE_NONE)
{ {
gBatterySaveCountdown_10ms = battery_save_count_10ms; gBatterySaveCountdown_10ms = battery_save_count_10ms;
} }
else else
{ {
//if (gCurrentFunction != FUNCTION_POWER_SAVE) //if (gCurrentFunction != FUNCTION_POWER_SAVE)
FUNCTION_Select(FUNCTION_POWER_SAVE); FUNCTION_Select(FUNCTION_POWER_SAVE);
} }
gSchedulePowerSave = false; gSchedulePowerSave = false;
#endif #endif
} }
#ifdef ENABLE_VOICE #ifdef ENABLE_VOICE
if (gPowerSaveCountdownExpired && gCurrentFunction == FUNCTION_POWER_SAVE && gVoiceWriteIndex == 0) if (gPowerSaveCountdownExpired && gCurrentFunction == FUNCTION_POWER_SAVE && gVoiceWriteIndex == 0)
#else #else
if (gPowerSaveCountdownExpired && gCurrentFunction == FUNCTION_POWER_SAVE) if (gPowerSaveCountdownExpired && gCurrentFunction == FUNCTION_POWER_SAVE)
#endif #endif
{ // wake up, enable RX then go back to sleep { // wake up, enable RX then go back to sleep
if (gRxIdleMode) if (gRxIdleMode)
{ {
BK4819_Conditional_RX_TurnOn_and_GPIO6_Enable(); BK4819_Conditional_RX_TurnOn_and_GPIO6_Enable();
#ifdef ENABLE_VOX #ifdef ENABLE_VOX
if (gEeprom.VOX_SWITCH) if (gEeprom.VOX_SWITCH)
BK4819_EnableVox(gEeprom.VOX1_THRESHOLD, gEeprom.VOX0_THRESHOLD); BK4819_EnableVox(gEeprom.VOX1_THRESHOLD, gEeprom.VOX0_THRESHOLD);
#endif #endif
if (gEeprom.DUAL_WATCH != DUAL_WATCH_OFF && if (gEeprom.DUAL_WATCH != DUAL_WATCH_OFF &&
gScanStateDir == SCAN_OFF && gScanStateDir == SCAN_OFF &&

View File

@@ -202,7 +202,7 @@ static void processFKeyFunction(const KEY_Code_t Key, const bool beep)
case KEY_5: case KEY_5:
if(beep) { if(beep) {
#ifdef ENABLE_NOAA #ifdef ENABLE_NOAA
if (IS_NOT_NOAA_CHANNEL(gTxVfo->CHANNEL_SAVE)) if (IS_NOT_NOAA_CHANNEL(gTxVfo->CHANNEL_SAVE))
{ {
@@ -211,9 +211,9 @@ static void processFKeyFunction(const KEY_Code_t Key, const bool beep)
else else
{ {
gEeprom.ScreenChannel[Vfo] = gEeprom.FreqChannel[gEeprom.TX_VFO]; gEeprom.ScreenChannel[Vfo] = gEeprom.FreqChannel[gEeprom.TX_VFO];
#ifdef ENABLE_VOICE #ifdef ENABLE_VOICE
gAnotherVoiceID = VOICE_ID_FREQUENCY_MODE; gAnotherVoiceID = VOICE_ID_FREQUENCY_MODE;
#endif #endif
} }
gRequestSaveVFO = true; gRequestSaveVFO = true;
gVfoConfigureMode = VFO_CONFIGURE_RELOAD; gVfoConfigureMode = VFO_CONFIGURE_RELOAD;
@@ -223,9 +223,9 @@ static void processFKeyFunction(const KEY_Code_t Key, const bool beep)
#endif #endif
} }
else { else {
#ifdef ENABLE_VOX #ifdef ENABLE_VOX
toggle_chan_scanlist(); toggle_chan_scanlist();
#endif #endif
} }
break; break;
@@ -235,11 +235,11 @@ static void processFKeyFunction(const KEY_Code_t Key, const bool beep)
break; break;
case KEY_7: case KEY_7:
#ifdef ENABLE_VOX #ifdef ENABLE_VOX
ACTION_Vox(); ACTION_Vox();
#else #else
toggle_chan_scanlist(); toggle_chan_scanlist();
#endif #endif
break; break;
case KEY_8: case KEY_8:
@@ -252,11 +252,11 @@ static void processFKeyFunction(const KEY_Code_t Key, const bool beep)
{ {
gEeprom.MrChannel[Vfo] = gEeprom.CHAN_1_CALL; gEeprom.MrChannel[Vfo] = gEeprom.CHAN_1_CALL;
gEeprom.ScreenChannel[Vfo] = gEeprom.CHAN_1_CALL; gEeprom.ScreenChannel[Vfo] = gEeprom.CHAN_1_CALL;
#ifdef ENABLE_VOICE #ifdef ENABLE_VOICE
AUDIO_SetVoiceID(0, VOICE_ID_CHANNEL_MODE); AUDIO_SetVoiceID(0, VOICE_ID_CHANNEL_MODE);
AUDIO_SetDigitVoice(1, gEeprom.CHAN_1_CALL + 1); AUDIO_SetDigitVoice(1, gEeprom.CHAN_1_CALL + 1);
gAnotherVoiceID = (VOICE_ID_t)0xFE; gAnotherVoiceID = (VOICE_ID_t)0xFE;
#endif #endif
gRequestSaveVFO = true; gRequestSaveVFO = true;
gVfoConfigureMode = VFO_CONFIGURE_RELOAD; gVfoConfigureMode = VFO_CONFIGURE_RELOAD;
break; break;
@@ -647,28 +647,28 @@ static void MAIN_Key_STAR(bool bKeyPressed, bool bKeyHeld)
return; return;
} }
if (bKeyHeld && !gWasFKeyPressed) if (bKeyHeld && !gWasFKeyPressed) // long press
{ // long press .. toggle scanning {
if (!bKeyPressed) if (!bKeyPressed) // released
return; // released return;
ACTION_Scan(false); ACTION_Scan(false);// toggle scanning
gBeepToPlay = BEEP_1KHZ_60MS_OPTIONAL; gBeepToPlay = BEEP_1KHZ_60MS_OPTIONAL;
return; return;
} }
if (bKeyPressed) if (bKeyPressed) // just pressed
{ // just pressed {
// gBeepToPlay = BEEP_1KHZ_60MS_OPTIONAL; // gBeepToPlay = BEEP_1KHZ_60MS_OPTIONAL;
gBeepToPlay = BEEP_880HZ_40MS_OPTIONAL; gBeepToPlay = BEEP_880HZ_40MS_OPTIONAL;
return; return;
} }
// just released // just released
if (!gWasFKeyPressed) if (!gWasFKeyPressed) // pressed without the F-key
{ // pressed without the F-key {
#ifdef ENABLE_NOAA #ifdef ENABLE_NOAA
if (gScanStateDir == SCAN_OFF && IS_NOT_NOAA_CHANNEL(gTxVfo->CHANNEL_SAVE)) if (gScanStateDir == SCAN_OFF && IS_NOT_NOAA_CHANNEL(gTxVfo->CHANNEL_SAVE))

37
main.c
View File

@@ -167,21 +167,21 @@ void Main(void)
boot_counter_10ms = 0; boot_counter_10ms = 0;
break; break;
} }
#ifdef ENABLE_BOOT_BEEPS #ifdef ENABLE_BOOT_BEEPS
if ((boot_counter_10ms % 25) == 0) if ((boot_counter_10ms % 25) == 0)
AUDIO_PlayBeep(BEEP_880HZ_40MS_OPTIONAL); AUDIO_PlayBeep(BEEP_880HZ_40MS_OPTIONAL);
#endif #endif
} }
} }
#ifdef ENABLE_PWRON_PASSWORD #ifdef ENABLE_PWRON_PASSWORD
if (gEeprom.POWER_ON_PASSWORD < 1000000) if (gEeprom.POWER_ON_PASSWORD < 1000000)
{ {
bIsInLockScreen = true; bIsInLockScreen = true;
UI_DisplayLock(); UI_DisplayLock();
bIsInLockScreen = false; bIsInLockScreen = false;
} }
#endif #endif
BOOT_ProcessMode(BootMode); BOOT_ProcessMode(BootMode);
@@ -189,7 +189,7 @@ void Main(void)
gUpdateStatus = true; gUpdateStatus = true;
#ifdef ENABLE_VOICE #ifdef ENABLE_VOICE
{ {
uint8_t Channel; uint8_t Channel;
@@ -201,17 +201,16 @@ void Main(void)
AUDIO_SetVoiceID(1, VOICE_ID_CHANNEL_MODE); AUDIO_SetVoiceID(1, VOICE_ID_CHANNEL_MODE);
AUDIO_SetDigitVoice(2, Channel + 1); AUDIO_SetDigitVoice(2, Channel + 1);
} }
else else if (IS_FREQ_CHANNEL(Channel))
if (IS_FREQ_CHANNEL(Channel))
AUDIO_SetVoiceID(1, VOICE_ID_FREQUENCY_MODE); AUDIO_SetVoiceID(1, VOICE_ID_FREQUENCY_MODE);
AUDIO_PlaySingleVoice(0); AUDIO_PlaySingleVoice(0);
} }
#endif #endif
#ifdef ENABLE_NOAA #ifdef ENABLE_NOAA
RADIO_ConfigureNOAA(); RADIO_ConfigureNOAA();
#endif #endif
// ****************** // ******************
} }

24
radio.c
View File

@@ -161,20 +161,20 @@ void RADIO_ConfigureChannel(const unsigned int VFO, const unsigned int configure
if (IS_VALID_CHANNEL(Channel)) if (IS_VALID_CHANNEL(Channel))
{ {
#ifdef ENABLE_NOAA #ifdef ENABLE_NOAA
if (Channel >= NOAA_CHANNEL_FIRST) if (Channel >= NOAA_CHANNEL_FIRST)
{ {
RADIO_InitInfo(pRadio, gEeprom.ScreenChannel[VFO], NoaaFrequencyTable[Channel - NOAA_CHANNEL_FIRST]); RADIO_InitInfo(pRadio, gEeprom.ScreenChannel[VFO], NoaaFrequencyTable[Channel - NOAA_CHANNEL_FIRST]);
if (gEeprom.CROSS_BAND_RX_TX == CROSS_BAND_OFF) if (gEeprom.CROSS_BAND_RX_TX == CROSS_BAND_OFF)
return;
gEeprom.CROSS_BAND_RX_TX = CROSS_BAND_OFF;
gUpdateStatus = true;
return; return;
}
#endif gEeprom.CROSS_BAND_RX_TX = CROSS_BAND_OFF;
gUpdateStatus = true;
return;
}
#endif
if (Channel <= MR_CHANNEL_LAST) if (Channel <= MR_CHANNEL_LAST)
{ {