diff --git a/app/app.c b/app/app.c index 56a7471..095b328 100644 --- a/app/app.c +++ b/app/app.c @@ -1723,57 +1723,7 @@ void APP_TimeSlice500ms(void) } - if (gLowBattery) - { - gLowBatteryBlink = ++gLowBatteryCountdown & 1; - - UI_DisplayBattery(0, gLowBatteryBlink); - - if (gCurrentFunction != FUNCTION_TRANSMIT) - { // not transmitting - - if (gLowBatteryCountdown < 30) - { - if (gLowBatteryCountdown == 29 && !gChargingWithTypeC) - AUDIO_PlayBeep(BEEP_500HZ_60MS_DOUBLE_BEEP); - } - else - { - gLowBatteryCountdown = 0; - - if (!gChargingWithTypeC) - { // not on charge - - AUDIO_PlayBeep(BEEP_500HZ_60MS_DOUBLE_BEEP); - - #ifdef ENABLE_VOICE - AUDIO_SetVoiceID(0, VOICE_ID_LOW_VOLTAGE); - #endif - - if (gBatteryDisplayLevel == 0) - { - #ifdef ENABLE_VOICE - AUDIO_PlaySingleVoice(true); - #endif - - gReducedService = true; - - //if (gCurrentFunction != FUNCTION_POWER_SAVE) - FUNCTION_Select(FUNCTION_POWER_SAVE); - - ST7565_HardwareReset(); - - if (gEeprom.BACKLIGHT_TIME < (ARRAY_SIZE(gSubMenu_BACKLIGHT) - 1)) - BACKLIGHT_TurnOff(); // turn the backlight off - } - #ifdef ENABLE_VOICE - else - AUDIO_PlaySingleVoice(false); - #endif - } - } - } - } + BATTERY_TimeSlice500ms(); if (gScreenToDisplay == DISPLAY_SCANNER && gScannerEditState == 0 && gScanCssState < SCAN_CSS_STATE_FOUND) { diff --git a/helper/battery.c b/helper/battery.c index 2157589..9726860 100644 --- a/helper/battery.c +++ b/helper/battery.c @@ -16,6 +16,8 @@ #include "battery.h" #include "driver/backlight.h" +#include "driver/st7565.h" +#include "functions.h" #include "misc.h" #include "settings.h" #include "ui/battery.h" @@ -29,10 +31,12 @@ uint16_t gBatteryVoltages[4]; uint16_t gBatteryVoltageAverage; uint8_t gBatteryDisplayLevel; bool gChargingWithTypeC; -bool gLowBattery; bool gLowBatteryBlink; uint16_t gBatteryCheckCounter; +bool lowBattery; +uint16_t lowBatteryCountdown; + volatile uint16_t gPowerSave_10ms; @@ -134,16 +138,71 @@ void BATTERY_GetReadings(const bool bDisplayBatteryLevel) { if (gBatteryDisplayLevel < 2) { - gLowBattery = true; + lowBattery = true; } else { - gLowBattery = false; + lowBattery = false; if (bDisplayBatteryLevel) UI_DisplayBattery(gBatteryDisplayLevel, gLowBatteryBlink); } - gLowBatteryCountdown = 0; + lowBatteryCountdown = 0; } } + +void BATTERY_TimeSlice500ms(void) +{ + if (lowBattery) + { + gLowBatteryBlink = ++lowBatteryCountdown & 1; + + UI_DisplayBattery(0, gLowBatteryBlink); + + if (gCurrentFunction != FUNCTION_TRANSMIT) + { // not transmitting + + if (lowBatteryCountdown < 30) + { + if (lowBatteryCountdown == 29 && !gChargingWithTypeC) + AUDIO_PlayBeep(BEEP_500HZ_60MS_DOUBLE_BEEP); + } + else + { + lowBatteryCountdown = 0; + + if (!gChargingWithTypeC) + { // not on charge + + AUDIO_PlayBeep(BEEP_500HZ_60MS_DOUBLE_BEEP); + + #ifdef ENABLE_VOICE + AUDIO_SetVoiceID(0, VOICE_ID_LOW_VOLTAGE); + #endif + + if (gBatteryDisplayLevel == 0) + { + #ifdef ENABLE_VOICE + AUDIO_PlaySingleVoice(true); + #endif + + gReducedService = true; + + //if (gCurrentFunction != FUNCTION_POWER_SAVE) + FUNCTION_Select(FUNCTION_POWER_SAVE); + + ST7565_HardwareReset(); + + if (gEeprom.BACKLIGHT_TIME < (ARRAY_SIZE(gSubMenu_BACKLIGHT) - 1)) + BACKLIGHT_TurnOff(); // turn the backlight off + } + #ifdef ENABLE_VOICE + else + AUDIO_PlaySingleVoice(false); + #endif + } + } + } + } +} \ No newline at end of file diff --git a/helper/battery.h b/helper/battery.h index 85ecb0a..d8b4dc7 100644 --- a/helper/battery.h +++ b/helper/battery.h @@ -27,7 +27,6 @@ extern uint16_t gBatteryVoltages[4]; extern uint16_t gBatteryVoltageAverage; extern uint8_t gBatteryDisplayLevel; extern bool gChargingWithTypeC; -extern bool gLowBattery; extern bool gLowBatteryBlink; extern uint16_t gBatteryCheckCounter; @@ -41,6 +40,7 @@ typedef enum { unsigned int BATTERY_VoltsToPercent(const unsigned int voltage_10mV); void BATTERY_GetReadings(const bool bDisplayBatteryLevel); +void BATTERY_TimeSlice500ms(void); #endif diff --git a/misc.c b/misc.c index 2a42685..ec30fdc 100644 --- a/misc.c +++ b/misc.c @@ -197,7 +197,6 @@ bool g_SquelchLost; uint8_t gFlashLightState; volatile uint16_t gFlashLightBlinkCounter; bool gFlagEndTransmission; -uint16_t gLowBatteryCountdown; uint8_t gNextMrChannel; ReceptionMode_t gRxReceptionMode; diff --git a/misc.h b/misc.h index c55467e..2b8e805 100644 --- a/misc.h +++ b/misc.h @@ -274,7 +274,6 @@ extern bool g_SquelchLost; extern uint8_t gFlashLightState; extern volatile uint16_t gFlashLightBlinkCounter; extern bool gFlagEndTransmission; -extern uint16_t gLowBatteryCountdown; extern uint8_t gNextMrChannel; extern ReceptionMode_t gRxReceptionMode;