Low battery popup

This commit is contained in:
Krzysiek Egzmont
2023-11-01 00:11:04 +01:00
parent 9f1e6ab91f
commit c2be853ef1
4 changed files with 56 additions and 25 deletions

View File

@@ -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) bool lowBatPopup = gLowBattery && !gLowBatteryConfirmed && gScreenToDisplay == DISPLAY_MAIN;
{ // keyboard is locked
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) if (Key == KEY_F)
{ // function/key-lock key { // function/key-lock key

View File

@@ -32,10 +32,19 @@ uint16_t gBatteryVoltageAverage;
uint8_t gBatteryDisplayLevel; uint8_t gBatteryDisplayLevel;
bool gChargingWithTypeC; bool gChargingWithTypeC;
bool gLowBatteryBlink; bool gLowBatteryBlink;
bool gLowBattery;
bool gLowBatteryConfirmed;
uint16_t gBatteryCheckCounter; uint16_t gBatteryCheckCounter;
bool lowBattery; typedef enum {
BATTERY_LOW_INACTIVE,
BATTERY_LOW_ACTIVE,
BATTERY_LOW_CONFIRMED
} BatteryLow_t;
uint16_t lowBatteryCountdown; uint16_t lowBatteryCountdown;
const uint16_t lowBatteryPeriod = 30;
volatile uint16_t gPowerSave_10ms; volatile uint16_t gPowerSave_10ms;
@@ -46,7 +55,7 @@ unsigned int BATTERY_VoltsToPercent(const unsigned int voltage_10mV)
{814, 100}, {814, 100},
{756, 24 }, {756, 24 },
{729, 7 }, {729, 7 },
{620, 0 }, {630, 0 },
{0, 0} {0, 0}
}; };
@@ -55,7 +64,7 @@ unsigned int BATTERY_VoltsToPercent(const unsigned int voltage_10mV)
{740, 60}, {740, 60},
{707, 21}, {707, 21},
{680, 5}, {680, 5},
{620, 0}, {630, 0},
{0, 0} {0, 0}
}; };
@@ -94,7 +103,7 @@ void BATTERY_GetReadings(const bool bDisplayBatteryLevel)
if(gBatteryVoltageAverage > 840) if(gBatteryVoltageAverage > 840)
gBatteryDisplayLevel = 6; // battery overvoltage gBatteryDisplayLevel = 6; // battery overvoltage
else if(gBatteryVoltageAverage < 620) else if(gBatteryVoltageAverage < 630)
gBatteryDisplayLevel = 0; // battery critical gBatteryDisplayLevel = 0; // battery critical
else { else {
gBatteryDisplayLevel = 1; gBatteryDisplayLevel = 1;
@@ -136,17 +145,22 @@ void BATTERY_GetReadings(const bool bDisplayBatteryLevel)
if (PreviousBatteryLevel != gBatteryDisplayLevel) if (PreviousBatteryLevel != gBatteryDisplayLevel)
{ {
if (gBatteryDisplayLevel < 2) if(gBatteryDisplayLevel > 2)
gLowBatteryConfirmed = false;
else if (gBatteryDisplayLevel < 2)
{ {
lowBattery = true; gLowBattery = true;
} }
else else
{ {
lowBattery = false; gLowBattery = false;
if (bDisplayBatteryLevel) if (bDisplayBatteryLevel)
UI_DisplayBattery(gBatteryDisplayLevel, gLowBatteryBlink); UI_DisplayBattery(gBatteryDisplayLevel, gLowBatteryBlink);
} }
if(!gLowBatteryConfirmed)
gUpdateDisplay = true;
lowBatteryCountdown = 0; lowBatteryCountdown = 0;
} }
@@ -154,7 +168,7 @@ void BATTERY_GetReadings(const bool bDisplayBatteryLevel)
void BATTERY_TimeSlice500ms(void) void BATTERY_TimeSlice500ms(void)
{ {
if (lowBattery) if (gLowBattery)
{ {
gLowBatteryBlink = ++lowBatteryCountdown & 1; gLowBatteryBlink = ++lowBatteryCountdown & 1;
@@ -163,9 +177,9 @@ void BATTERY_TimeSlice500ms(void)
if (gCurrentFunction != FUNCTION_TRANSMIT) if (gCurrentFunction != FUNCTION_TRANSMIT)
{ // not transmitting { // 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); AUDIO_PlayBeep(BEEP_500HZ_60MS_DOUBLE_BEEP);
} }
else else
@@ -174,18 +188,17 @@ void BATTERY_TimeSlice500ms(void)
if (!gChargingWithTypeC) if (!gChargingWithTypeC)
{ // not on charge { // not on charge
if(!gLowBatteryConfirmed) {
AUDIO_PlayBeep(BEEP_500HZ_60MS_DOUBLE_BEEP); AUDIO_PlayBeep(BEEP_500HZ_60MS_DOUBLE_BEEP);
#ifdef ENABLE_VOICE
#ifdef ENABLE_VOICE
AUDIO_SetVoiceID(0, VOICE_ID_LOW_VOLTAGE); AUDIO_SetVoiceID(0, VOICE_ID_LOW_VOLTAGE);
#endif #endif
}
if (gBatteryDisplayLevel == 0) if (gBatteryDisplayLevel == 0)
{ {
#ifdef ENABLE_VOICE #ifdef ENABLE_VOICE
AUDIO_PlaySingleVoice(true); AUDIO_PlaySingleVoice(true);
#endif #endif
gReducedService = true; gReducedService = true;
@@ -197,10 +210,10 @@ void BATTERY_TimeSlice500ms(void)
if (gEeprom.BACKLIGHT_TIME < (ARRAY_SIZE(gSubMenu_BACKLIGHT) - 1)) if (gEeprom.BACKLIGHT_TIME < (ARRAY_SIZE(gSubMenu_BACKLIGHT) - 1))
BACKLIGHT_TurnOff(); // turn the backlight off BACKLIGHT_TurnOff(); // turn the backlight off
} }
#ifdef ENABLE_VOICE #ifdef ENABLE_VOICE
else else
AUDIO_PlaySingleVoice(false); AUDIO_PlaySingleVoice(false);
#endif #endif
} }
} }
} }

View File

@@ -28,6 +28,8 @@ extern uint16_t gBatteryVoltageAverage;
extern uint8_t gBatteryDisplayLevel; extern uint8_t gBatteryDisplayLevel;
extern bool gChargingWithTypeC; extern bool gChargingWithTypeC;
extern bool gLowBatteryBlink; extern bool gLowBatteryBlink;
extern bool gLowBattery;
extern bool gLowBatteryConfirmed;
extern uint16_t gBatteryCheckCounter; extern uint16_t gBatteryCheckCounter;
extern volatile uint16_t gPowerSave_10ms; extern volatile uint16_t gPowerSave_10ms;

View File

@@ -234,6 +234,12 @@ void UI_DisplayMain(void)
// clear the screen // clear the screen
memset(gFrameBuffer, 0, sizeof(gFrameBuffer)); memset(gFrameBuffer, 0, sizeof(gFrameBuffer));
if(gLowBattery && !gLowBatteryConfirmed) {
UI_DisplayPopup("LOW BATTERY");
ST7565_BlitFullScreen();
return;
}
if (gEeprom.KEY_LOCK && gKeypadLocked > 0) if (gEeprom.KEY_LOCK && gKeypadLocked > 0)
{ // tell user how to unlock the keyboard { // tell user how to unlock the keyboard
UI_PrintString("Long press #", 0, LCD_WIDTH, 1, 8); UI_PrintString("Long press #", 0, LCD_WIDTH, 1, 8);