Use the custom battery percentage calculations for battery icon and low battery beeping

This commit is contained in:
Krzysiek Egzmont
2023-10-31 19:40:00 +01:00
parent 2344478301
commit 2796973ad3
2 changed files with 25 additions and 15 deletions

View File

@@ -778,12 +778,12 @@ void MENU_AcceptSetting(void)
case MENU_BATCAL: case MENU_BATCAL:
{ // voltages are averages between discharge curves of 1600 and 2200 mAh { // voltages are averages between discharge curves of 1600 and 2200 mAh
gBatteryCalibration[0] = (520ul * gSubMenuSelection) / 760; // 5.20V empty, blinking above this value, reduced functionality below // gBatteryCalibration[0] = (520ul * gSubMenuSelection) / 760; // 5.20V empty, blinking above this value, reduced functionality below
gBatteryCalibration[1] = (689ul * gSubMenuSelection) / 760; // 6.89V, ~5%, 1 bars above this value // gBatteryCalibration[1] = (689ul * gSubMenuSelection) / 760; // 6.89V, ~5%, 1 bars above this value
gBatteryCalibration[2] = (724ul * gSubMenuSelection) / 760; // 7.24V, ~17%, 2 bars above this value // gBatteryCalibration[2] = (724ul * gSubMenuSelection) / 760; // 7.24V, ~17%, 2 bars above this value
gBatteryCalibration[3] = gSubMenuSelection; // 7.6V, ~29%, 3 bars above this value gBatteryCalibration[3] = gSubMenuSelection; // 7.6V, ~29%, 3 bars above this value
gBatteryCalibration[4] = (771ul * gSubMenuSelection) / 760; // 7.71V, ~65%, 4 bars above this value // gBatteryCalibration[4] = (771ul * gSubMenuSelection) / 760; // 7.71V, ~65%, 4 bars above this value
gBatteryCalibration[5] = 2300; // gBatteryCalibration[5] = 2300;
SETTINGS_SaveBatteryCalibration(gBatteryCalibration); SETTINGS_SaveBatteryCalibration(gBatteryCalibration);
return; return;
} }

View File

@@ -42,7 +42,7 @@ unsigned int BATTERY_VoltsToPercent(const unsigned int voltage_10mV)
{814, 100}, {814, 100},
{756, 24 }, {756, 24 },
{729, 7 }, {729, 7 },
{597, 0 }, {620, 0 },
{0, 0} {0, 0}
}; };
@@ -51,7 +51,7 @@ unsigned int BATTERY_VoltsToPercent(const unsigned int voltage_10mV)
{740, 60}, {740, 60},
{707, 21}, {707, 21},
{680, 5}, {680, 5},
{505, 0}, {620, 0},
{0, 0} {0, 0}
}; };
@@ -84,16 +84,26 @@ void BATTERY_GetReadings(const bool bDisplayBatteryLevel)
const uint8_t PreviousBatteryLevel = gBatteryDisplayLevel; const uint8_t PreviousBatteryLevel = gBatteryDisplayLevel;
const uint16_t Voltage = (gBatteryVoltages[0] + gBatteryVoltages[1] + gBatteryVoltages[2] + gBatteryVoltages[3]) / 4; const uint16_t Voltage = (gBatteryVoltages[0] + gBatteryVoltages[1] + gBatteryVoltages[2] + gBatteryVoltages[3]) / 4;
gBatteryDisplayLevel = 0;
for(uint8_t i = 6; i > 0; i--){
if (Voltage > gBatteryCalibration[i-1]) { gBatteryVoltageAverage = (Voltage * 760) / gBatteryCalibration[3];
gBatteryDisplayLevel = i;
break; if(gBatteryVoltageAverage > 840)
gBatteryDisplayLevel = 6; // battery overvoltage
else if(gBatteryVoltageAverage < 620)
gBatteryDisplayLevel = 0; // battery critical
else {
gBatteryDisplayLevel = 1;
const uint8_t levels[] = {5,25,50,75};
uint8_t perc = BATTERY_VoltsToPercent(gBatteryVoltageAverage);
for(uint8_t i = 5; i >= 1; i--){
if (perc > levels[i-2]) {
gBatteryDisplayLevel = i;
break;
}
} }
} }
gBatteryVoltageAverage = (Voltage * 760) / gBatteryCalibration[3];
if ((gScreenToDisplay == DISPLAY_MENU) && GetCurrentMenuId() == MENU_VOL) if ((gScreenToDisplay == DISPLAY_MENU) && GetCurrentMenuId() == MENU_VOL)
gUpdateDisplay = true; gUpdateDisplay = true;