diff --git a/app/app.c b/app/app.c index dcda5a1..a920e76 100644 --- a/app/app.c +++ b/app/app.c @@ -98,7 +98,7 @@ static void APP_CheckForIncoming(void) } gDualWatchCountdown_10ms = dual_watch_count_after_rx_10ms; - gDualWatchCountdownExpired = false; + gScheduleDualWatch = false; // let the user see DW is not active gDualWatchActive = false; @@ -166,8 +166,8 @@ static void APP_HandleIncoming(void) { if (gRxReceptionMode == RX_MODE_DETECTED) { - gDualWatchCountdown_10ms = dual_watch_count_after_1_10ms; - gDualWatchCountdownExpired = false; + gDualWatchCountdown_10ms = dual_watch_count_after_1_10ms; + gScheduleDualWatch = false; gRxReceptionMode = RX_MODE_LISTENING; @@ -449,8 +449,8 @@ void APP_StartListening(FUNCTION_Type_t Function) if (gScanState == SCAN_OFF && gCssScanMode == CSS_SCAN_MODE_OFF && gEeprom.DUAL_WATCH != DUAL_WATCH_OFF) { - gDualWatchCountdown_10ms = dual_watch_count_after_2_10ms; - gDualWatchCountdownExpired = false; + gDualWatchCountdown_10ms = dual_watch_count_after_2_10ms; + gScheduleDualWatch = false; gRxVfoIsActive = true; @@ -944,14 +944,14 @@ void APP_CheckRadioInterrupts(void) { if (gCurrentFunction == FUNCTION_POWER_SAVE && !gRxIdleMode) { - gBatterySave_10ms = 20; // 200ms - gBatterySaveExpired = false; + gBatterySave_10ms = 20; // 200ms + gBatterySaveCountdownExpired = 0; } - if (gEeprom.DUAL_WATCH != DUAL_WATCH_OFF && (gBatterySaveCountdownExpired || gDualWatchCountdown_10ms < dual_watch_count_after_vox_10ms)) + if (gEeprom.DUAL_WATCH != DUAL_WATCH_OFF && (gScheduleDualWatch || gDualWatchCountdown_10ms < dual_watch_count_after_vox_10ms)) { - gDualWatchCountdown_10ms = dual_watch_count_after_vox_10ms; - gDualWatchCountdownExpired = false; + gDualWatchCountdown_10ms = dual_watch_count_after_vox_10ms; + gScheduleDualWatch = false; // let the user see DW is not active gDualWatchActive = false; @@ -1182,9 +1182,9 @@ void APP_Update(void) if (gScreenToDisplay != DISPLAY_SCANNER && gEeprom.DUAL_WATCH != DUAL_WATCH_OFF) { #ifdef ENABLE_VOICE - if (gDualWatchCountdownExpired && gVoiceWriteIndex == 0) + if (gScheduleDualWatch && gVoiceWriteIndex == 0) #else - if (gDualWatchCountdownExpired) + if (gScheduleDualWatch) #endif { if (gScanState == SCAN_OFF && gCssScanMode == CSS_SCAN_MODE_OFF) @@ -1196,16 +1196,15 @@ void APP_Update(void) gDTMF_CallState == DTMF_CALL_STATE_NONE && gCurrentFunction != FUNCTION_POWER_SAVE) { - gDualWatchCountdownExpired = false; - DUALWATCH_Alternate(); // toggle between the two VFO's if (gRxVfoIsActive && gScreenToDisplay == DISPLAY_MAIN) GUI_SelectNextDisplay(DISPLAY_MAIN); - gRxVfoIsActive = false; - gScanPauseMode = false; - gRxReceptionMode = RX_MODE_NONE; + gRxVfoIsActive = false; + gScanPauseMode = false; + gRxReceptionMode = RX_MODE_NONE; + gScheduleDualWatch = false; } } } @@ -1226,7 +1225,7 @@ void APP_Update(void) if (gEeprom.VOX_SWITCH) APP_HandleVox(); - if (gBatterySaveCountdownExpired) + if (gSchedulePowerSave) { #ifdef ENABLE_NOAA if ( @@ -1242,7 +1241,6 @@ void APP_Update(void) gDTMF_CallState != DTMF_CALL_STATE_NONE) { gBatterySaveCountdown_10ms = battery_save_count_10ms; - gBatterySaveCountdownExpired = false; } else if ((IS_NOT_NOAA_CHANNEL(gEeprom.ScreenChannel[0]) && IS_NOT_NOAA_CHANNEL(gEeprom.ScreenChannel[1])) || !gIsNoaaMode) @@ -1252,7 +1250,6 @@ void APP_Update(void) else { gBatterySaveCountdown_10ms = battery_save_count_10ms; - gBatterySaveCountdownExpired = false; } #else if ( @@ -1268,19 +1265,20 @@ void APP_Update(void) gDTMF_CallState != DTMF_CALL_STATE_NONE) { gBatterySaveCountdown_10ms = battery_save_count_10ms; - gBatterySaveCountdownExpired = false; } else { FUNCTION_Select(FUNCTION_POWER_SAVE); } + + gSchedulePowerSave = false; #endif } #ifdef ENABLE_VOICE - if (gBatterySaveExpired && gCurrentFunction == FUNCTION_POWER_SAVE && gVoiceWriteIndex == 0) + if (gBatterySaveCountdownExpired && gCurrentFunction == FUNCTION_POWER_SAVE && gVoiceWriteIndex == 0) #else - if (gBatterySaveExpired && gCurrentFunction == FUNCTION_POWER_SAVE) + if (gBatterySaveCountdownExpired && gCurrentFunction == FUNCTION_POWER_SAVE) #endif { if (gRxIdleMode) @@ -1300,8 +1298,6 @@ void APP_Update(void) FUNCTION_Init(); gBatterySave_10ms = 10; // 100ms - gBatterySaveExpired = false; - gRxIdleMode = false; } else @@ -1311,8 +1307,6 @@ void APP_Update(void) UI_UpdateRSSI(gCurrentRSSI); gBatterySave_10ms = gEeprom.BATTERY_SAVE * 10; - gBatterySaveExpired = false; - gRxIdleMode = true; BK4819_DisableVox(); @@ -1329,8 +1323,9 @@ void APP_Update(void) gUpdateRSSI = true; gBatterySave_10ms = 10; // 100ms - gBatterySaveExpired = false; } + + gBatterySaveCountdownExpired = false; } } diff --git a/firmware b/firmware index 4eb09e0..28df24f 100644 Binary files a/firmware and b/firmware differ diff --git a/firmware.bin b/firmware.bin index db50aaf..899439e 100644 Binary files a/firmware.bin and b/firmware.bin differ diff --git a/firmware.packed.bin b/firmware.packed.bin index 103e088..0b86c6f 100644 Binary files a/firmware.packed.bin and b/firmware.packed.bin differ diff --git a/functions.c b/functions.c index 7bb8a79..a71ba8c 100644 --- a/functions.c +++ b/functions.c @@ -86,11 +86,9 @@ void FUNCTION_Init(void) void FUNCTION_Select(FUNCTION_Type_t Function) { - FUNCTION_Type_t PreviousFunction; - bool bWasPowerSave; + FUNCTION_Type_t PreviousFunction = gCurrentFunction; + bool bWasPowerSave = (PreviousFunction == FUNCTION_POWER_SAVE); - PreviousFunction = gCurrentFunction; - bWasPowerSave = (PreviousFunction == FUNCTION_POWER_SAVE); gCurrentFunction = Function; if (bWasPowerSave) @@ -135,7 +133,8 @@ void FUNCTION_Select(FUNCTION_Type_t Function) case FUNCTION_POWER_SAVE: gBatterySave_10ms = gEeprom.BATTERY_SAVE * 10; - gBatterySaveExpired = false; + + gBatterySaveCountdownExpired = false; gRxIdleMode = true; @@ -198,8 +197,8 @@ void FUNCTION_Select(FUNCTION_Type_t Function) break; } - gBatterySaveCountdown_10ms = battery_save_count_10ms; - gBatterySaveCountdownExpired = false; + gBatterySaveCountdown_10ms = battery_save_count_10ms; + gSchedulePowerSave = false; #if defined(ENABLE_FMRADIO) gFM_RestoreCountdown = 0; diff --git a/helper/battery.c b/helper/battery.c index 4fc8482..ca4285f 100644 --- a/helper/battery.c +++ b/helper/battery.c @@ -33,7 +33,6 @@ bool gLowBatteryBlink; uint16_t gBatteryCheckCounter; volatile uint16_t gBatterySave_10ms; -volatile bool gBatterySaveExpired; void BATTERY_GetReadings(bool bDisplayBatteryLevel) { diff --git a/helper/battery.h b/helper/battery.h index a824731..26a4b90 100644 --- a/helper/battery.h +++ b/helper/battery.h @@ -32,7 +32,6 @@ extern bool gLowBatteryBlink; extern uint16_t gBatteryCheckCounter; extern volatile uint16_t gBatterySave_10ms; -extern volatile bool gBatterySaveExpired; void BATTERY_GetReadings(bool bDisplayBatteryLevel); diff --git a/misc.c b/misc.c index 5966656..eb64a15 100644 --- a/misc.c +++ b/misc.c @@ -83,6 +83,9 @@ uint8_t gMR_ChannelAttributes[207]; volatile uint16_t gBatterySaveCountdown_10ms = battery_save_count_10ms; volatile bool gBatterySaveCountdownExpired; +volatile bool gSchedulePowerSave; + +volatile bool gScheduleDualWatch = true; volatile uint16_t gDualWatchCountdown_10ms; volatile bool gDualWatchCountdownExpired = true; diff --git a/misc.h b/misc.h index fc4ce95..8292878 100644 --- a/misc.h +++ b/misc.h @@ -140,8 +140,11 @@ extern uint16_t gEEPROM_1F8C; extern uint8_t gMR_ChannelAttributes[207]; extern volatile uint16_t gBatterySaveCountdown_10ms; +extern volatile bool gSchedulePowerSave; extern volatile bool gBatterySaveCountdownExpired; +extern volatile bool gScheduleDualWatch; + extern volatile uint16_t gDualWatchCountdown_10ms; extern volatile bool gDualWatchCountdownExpired; extern bool gDualWatchActive; diff --git a/radio.c b/radio.c index 72a0eda..2f252a7 100644 --- a/radio.c +++ b/radio.c @@ -876,8 +876,8 @@ void RADIO_PrepareTX(void) { if (gEeprom.DUAL_WATCH != DUAL_WATCH_OFF) { - gDualWatchCountdown_10ms = dual_watch_count_after_tx_10ms; - gDualWatchCountdownExpired = false; + gDualWatchCountdown_10ms = dual_watch_count_after_tx_10ms; + gScheduleDualWatch = false; if (!gRxVfoIsActive) { diff --git a/scheduler.c b/scheduler.c index 4c236aa..6444851 100644 --- a/scheduler.c +++ b/scheduler.c @@ -70,14 +70,14 @@ void SystickHandler(void) DECREMENT(gFoundCTCSSCountdown_10ms); if (gCurrentFunction == FUNCTION_FOREGROUND) - DECREMENT_AND_TRIGGER(gBatterySaveCountdown_10ms, gBatterySaveCountdownExpired); + DECREMENT_AND_TRIGGER(gBatterySaveCountdown_10ms, gSchedulePowerSave); if (gCurrentFunction == FUNCTION_POWER_SAVE) - DECREMENT_AND_TRIGGER(gBatterySave_10ms, gBatterySaveExpired); + DECREMENT_AND_TRIGGER(gBatterySave_10ms, gBatterySaveCountdownExpired); if (gScanState == SCAN_OFF && gCssScanMode == CSS_SCAN_MODE_OFF && gEeprom.DUAL_WATCH != DUAL_WATCH_OFF) if (gCurrentFunction != FUNCTION_MONITOR && gCurrentFunction != FUNCTION_TRANSMIT && gCurrentFunction != FUNCTION_RECEIVE) - DECREMENT_AND_TRIGGER(gDualWatchCountdown_10ms, gDualWatchCountdownExpired); + DECREMENT_AND_TRIGGER(gDualWatchCountdown_10ms, gScheduleDualWatch); #ifdef ENABLE_NOAA if (gScanState == SCAN_OFF && gCssScanMode == CSS_SCAN_MODE_OFF && gEeprom.DUAL_WATCH == DUAL_WATCH_OFF)