battery monitor fixes
This commit is contained in:
parent
5818c8d1d3
commit
f91b3fa016
@ -283,10 +283,8 @@ void dp_drawPage(time_t t, bool nextpage) {
|
||||
#if (defined BAT_MEASURE_ADC || defined HAS_PMU || defined HAS_IP5306)
|
||||
if (batt_level == 0)
|
||||
dp_printf("No batt ");
|
||||
else if (batt_level < 100)
|
||||
dp_printf("B:%3d%% ", batt_level);
|
||||
else
|
||||
dp_printf("ext.Pwr ");
|
||||
dp_printf("B:%3d%% ", batt_level);
|
||||
#else
|
||||
dp_printf(" ");
|
||||
#endif
|
||||
|
@ -482,29 +482,22 @@ uint8_t myBattLevelCb(void *pUserData) {
|
||||
// we calculate the applicable value from MCMD_DEVS_BATT_MIN to
|
||||
// MCMD_DEVS_BATT_MAX from bat_percent value
|
||||
|
||||
uint8_t lmic_batt_level;
|
||||
uint8_t const batt_percent = read_battlevel();
|
||||
|
||||
if (batt_percent == 0)
|
||||
lmic_batt_level = MCMD_DEVS_BATT_NOINFO;
|
||||
return MCMD_DEVS_BATT_NOINFO;
|
||||
else
|
||||
|
||||
#ifdef HAS_PMU
|
||||
if (pmu.isVBUSPlug())
|
||||
lmic_batt_level = MCMD_DEVS_EXT_POWER;
|
||||
return MCMD_DEVS_EXT_POWER;
|
||||
#elif defined HAS_IP5306
|
||||
if (IP5306_GetPowerSource())
|
||||
lmic_batt_level = MCMD_DEVS_EXT_POWER;
|
||||
return MCMD_DEVS_EXT_POWER;
|
||||
#else
|
||||
if (batt_percent >= 100)
|
||||
lmic_batt_level = MCMD_DEVS_EXT_POWER;
|
||||
return (batt_percent / 100.0 *
|
||||
(MCMD_DEVS_BATT_MAX - MCMD_DEVS_BATT_MIN + 1));
|
||||
#endif // HAS_PMU
|
||||
|
||||
else
|
||||
lmic_batt_level =
|
||||
batt_percent / 100.0 * (MCMD_DEVS_BATT_MAX - MCMD_DEVS_BATT_MIN + 1);
|
||||
|
||||
return lmic_batt_level;
|
||||
}
|
||||
|
||||
// event EV_RXCOMPLETE message handler
|
||||
|
@ -211,26 +211,18 @@ uint16_t read_voltage(void) {
|
||||
}
|
||||
|
||||
uint8_t read_battlevel(mapFn_t mapFunction) {
|
||||
|
||||
// returns the estimated battery level in values 0 ... 100 [percent]
|
||||
|
||||
uint8_t batt_percent;
|
||||
|
||||
#ifdef HAS_IP5306
|
||||
batt_percent = IP5306_GetBatteryLevel();
|
||||
return IP5306_GetBatteryLevel();
|
||||
#else
|
||||
const uint16_t batt_voltage = read_voltage();
|
||||
|
||||
if (batt_voltage <= BAT_MIN_VOLTAGE)
|
||||
batt_percent = 0;
|
||||
return 0;
|
||||
else if (batt_voltage >= BAT_MAX_VOLTAGE)
|
||||
batt_percent = 100;
|
||||
return 100;
|
||||
else
|
||||
batt_percent =
|
||||
(*mapFunction)(batt_voltage, BAT_MIN_VOLTAGE, BAT_MAX_VOLTAGE);
|
||||
#endif // HAS_IP5306
|
||||
|
||||
return batt_percent;
|
||||
return (*mapFunction)(batt_voltage, BAT_MIN_VOLTAGE, BAT_MAX_VOLTAGE);
|
||||
#endif
|
||||
}
|
||||
|
||||
bool batt_sufficient() {
|
||||
|
Loading…
Reference in New Issue
Block a user