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