diff --git a/app/app.c b/app/app.c index 095b328..268c77d 100644 --- a/app/app.c +++ b/app/app.c @@ -1906,8 +1906,18 @@ static void ProcessKey(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld) } } - if (gEeprom.KEY_LOCK && gCurrentFunction != FUNCTION_TRANSMIT && Key != KEY_PTT) - { // keyboard is locked + bool lowBatPopup = gLowBattery && !gLowBatteryConfirmed && gScreenToDisplay == DISPLAY_MAIN; + + if ((gEeprom.KEY_LOCK || lowBatPopup) && gCurrentFunction != FUNCTION_TRANSMIT && Key != KEY_PTT) + { // keyboard is locked or low battery popup + + // close low battery popup + if(Key == KEY_EXIT && bKeyPressed && lowBatPopup) { + gLowBatteryConfirmed = true; + gUpdateDisplay = true; + AUDIO_PlayBeep(BEEP_1KHZ_60MS_OPTIONAL); + return; + } if (Key == KEY_F) { // function/key-lock key diff --git a/helper/battery.c b/helper/battery.c index 9726860..db740b8 100644 --- a/helper/battery.c +++ b/helper/battery.c @@ -32,10 +32,19 @@ uint16_t gBatteryVoltageAverage; uint8_t gBatteryDisplayLevel; bool gChargingWithTypeC; bool gLowBatteryBlink; +bool gLowBattery; +bool gLowBatteryConfirmed; uint16_t gBatteryCheckCounter; -bool lowBattery; +typedef enum { + BATTERY_LOW_INACTIVE, + BATTERY_LOW_ACTIVE, + BATTERY_LOW_CONFIRMED +} BatteryLow_t; + + uint16_t lowBatteryCountdown; +const uint16_t lowBatteryPeriod = 30; volatile uint16_t gPowerSave_10ms; @@ -46,7 +55,7 @@ unsigned int BATTERY_VoltsToPercent(const unsigned int voltage_10mV) {814, 100}, {756, 24 }, {729, 7 }, - {620, 0 }, + {630, 0 }, {0, 0} }; @@ -55,7 +64,7 @@ unsigned int BATTERY_VoltsToPercent(const unsigned int voltage_10mV) {740, 60}, {707, 21}, {680, 5}, - {620, 0}, + {630, 0}, {0, 0} }; @@ -94,7 +103,7 @@ void BATTERY_GetReadings(const bool bDisplayBatteryLevel) if(gBatteryVoltageAverage > 840) gBatteryDisplayLevel = 6; // battery overvoltage - else if(gBatteryVoltageAverage < 620) + else if(gBatteryVoltageAverage < 630) gBatteryDisplayLevel = 0; // battery critical else { gBatteryDisplayLevel = 1; @@ -136,17 +145,22 @@ void BATTERY_GetReadings(const bool bDisplayBatteryLevel) if (PreviousBatteryLevel != gBatteryDisplayLevel) { - if (gBatteryDisplayLevel < 2) + if(gBatteryDisplayLevel > 2) + gLowBatteryConfirmed = false; + else if (gBatteryDisplayLevel < 2) { - lowBattery = true; + gLowBattery = true; } else { - lowBattery = false; + gLowBattery = false; if (bDisplayBatteryLevel) UI_DisplayBattery(gBatteryDisplayLevel, gLowBatteryBlink); } + + if(!gLowBatteryConfirmed) + gUpdateDisplay = true; lowBatteryCountdown = 0; } @@ -154,7 +168,7 @@ void BATTERY_GetReadings(const bool bDisplayBatteryLevel) void BATTERY_TimeSlice500ms(void) { - if (lowBattery) + if (gLowBattery) { gLowBatteryBlink = ++lowBatteryCountdown & 1; @@ -163,9 +177,9 @@ void BATTERY_TimeSlice500ms(void) if (gCurrentFunction != FUNCTION_TRANSMIT) { // not transmitting - if (lowBatteryCountdown < 30) + if (lowBatteryCountdown < lowBatteryPeriod) { - if (lowBatteryCountdown == 29 && !gChargingWithTypeC) + if (lowBatteryCountdown == lowBatteryPeriod-1 && !gChargingWithTypeC && !gLowBatteryConfirmed) AUDIO_PlayBeep(BEEP_500HZ_60MS_DOUBLE_BEEP); } else @@ -174,18 +188,17 @@ void BATTERY_TimeSlice500ms(void) if (!gChargingWithTypeC) { // not on charge - - AUDIO_PlayBeep(BEEP_500HZ_60MS_DOUBLE_BEEP); - - #ifdef ENABLE_VOICE + if(!gLowBatteryConfirmed) { + AUDIO_PlayBeep(BEEP_500HZ_60MS_DOUBLE_BEEP); +#ifdef ENABLE_VOICE AUDIO_SetVoiceID(0, VOICE_ID_LOW_VOLTAGE); - #endif - +#endif + } if (gBatteryDisplayLevel == 0) { - #ifdef ENABLE_VOICE - AUDIO_PlaySingleVoice(true); - #endif +#ifdef ENABLE_VOICE + AUDIO_PlaySingleVoice(true); +#endif gReducedService = true; @@ -197,10 +210,10 @@ void BATTERY_TimeSlice500ms(void) if (gEeprom.BACKLIGHT_TIME < (ARRAY_SIZE(gSubMenu_BACKLIGHT) - 1)) BACKLIGHT_TurnOff(); // turn the backlight off } - #ifdef ENABLE_VOICE - else - AUDIO_PlaySingleVoice(false); - #endif +#ifdef ENABLE_VOICE + else + AUDIO_PlaySingleVoice(false); +#endif } } } diff --git a/helper/battery.h b/helper/battery.h index d8b4dc7..c951bd9 100644 --- a/helper/battery.h +++ b/helper/battery.h @@ -28,6 +28,8 @@ extern uint16_t gBatteryVoltageAverage; extern uint8_t gBatteryDisplayLevel; extern bool gChargingWithTypeC; extern bool gLowBatteryBlink; +extern bool gLowBattery; +extern bool gLowBatteryConfirmed; extern uint16_t gBatteryCheckCounter; extern volatile uint16_t gPowerSave_10ms; diff --git a/ui/main.c b/ui/main.c index cd18c8b..cc5025a 100644 --- a/ui/main.c +++ b/ui/main.c @@ -234,6 +234,12 @@ void UI_DisplayMain(void) // clear the screen memset(gFrameBuffer, 0, sizeof(gFrameBuffer)); + if(gLowBattery && !gLowBatteryConfirmed) { + UI_DisplayPopup("LOW BATTERY"); + ST7565_BlitFullScreen(); + return; + } + if (gEeprom.KEY_LOCK && gKeypadLocked > 0) { // tell user how to unlock the keyboard UI_PrintString("Long press #", 0, LCD_WIDTH, 1, 8);