battery percentage display fixes
This commit is contained in:
parent
bf2d32896f
commit
4a1499b2bb
@ -15,7 +15,7 @@
|
||||
#define BAT_MAX_VOLTAGE 4300 // millivolts
|
||||
#endif
|
||||
#ifndef BAT_MIN_VOLTAGE
|
||||
#define BAT_MIN_VOLTAGE 3100 // millivolts
|
||||
#define BAT_MIN_VOLTAGE 3200 // millivolts
|
||||
#endif
|
||||
|
||||
uint16_t read_voltage(void);
|
||||
|
@ -283,7 +283,7 @@ void dp_drawPage(time_t t, bool nextpage) {
|
||||
#if (defined BAT_MEASURE_ADC || defined HAS_PMU)
|
||||
switch (batt_level) {
|
||||
case MCMD_DEVS_EXT_POWER:
|
||||
dp_printf("USB ");
|
||||
dp_printf("ext.Pwr ");
|
||||
break;
|
||||
case MCMD_DEVS_BATT_NOINFO:
|
||||
dp_printf("No batt ");
|
||||
|
@ -223,24 +223,24 @@ uint8_t read_battlevel() {
|
||||
|
||||
const uint16_t batt_voltage_range = BAT_MAX_VOLTAGE - BAT_MIN_VOLTAGE;
|
||||
const uint8_t batt_level_range = MCMD_DEVS_BATT_MAX - MCMD_DEVS_BATT_MIN + 1;
|
||||
const uint16_t batt_voltage = read_voltage() - BAT_MIN_VOLTAGE;
|
||||
const uint8_t batt_percent = batt_voltage > 0
|
||||
? batt_voltage / batt_voltage_range * 100
|
||||
const int batt_voltage = read_voltage() - BAT_MIN_VOLTAGE;
|
||||
const uint8_t batt_percent = (batt_voltage > 0)
|
||||
? (float)batt_voltage / (float)batt_voltage_range * 100.0
|
||||
: MCMD_DEVS_BATT_NOINFO;
|
||||
uint8_t lmic_batt_level;
|
||||
|
||||
ESP_LOGD(TAG, "batt_voltage = %d mV / batt_level = %u%%", batt_voltage,
|
||||
batt_percent);
|
||||
|
||||
if (batt_percent != MCMD_DEVS_BATT_NOINFO)
|
||||
#ifdef HAS_PMU
|
||||
if ((batt_percent > 0) && (batt_percent != MCMD_DEVS_BATT_NOINFO))
|
||||
lmic_batt_level = pmu.isVBUSPlug() ? MCMD_DEVS_EXT_POWER
|
||||
: batt_percent / 100 * batt_level_range;
|
||||
else
|
||||
lmic_batt_level = MCMD_DEVS_BATT_NOINFO;
|
||||
: (float)batt_percent / (float)batt_level_range * 100.0;
|
||||
#else
|
||||
if ((batt_percent > 0) && (batt_percent != MCMD_DEVS_BATT_NOINFO))
|
||||
lmic_batt_level = batt_percent / 100 * batt_level_range;
|
||||
lmic_batt_level = (float)batt_percent / (float)batt_level_range * 100.0;
|
||||
#endif // HAS_PMU
|
||||
else
|
||||
lmic_batt_level = MCMD_DEVS_BATT_NOINFO;
|
||||
#endif // HAS_PMU
|
||||
|
||||
// set battery level value for lmic stack
|
||||
#if (HAS_LORA)
|
||||
@ -252,14 +252,13 @@ uint8_t read_battlevel() {
|
||||
|
||||
bool batt_sufficient() {
|
||||
#if (defined HAS_PMU || defined BAT_MEASURE_ADC)
|
||||
uint8_t my_batt_level = read_battlevel();
|
||||
switch (my_batt_level) {
|
||||
switch (batt_level) {
|
||||
case MCMD_DEVS_EXT_POWER:
|
||||
return true;
|
||||
case MCMD_DEVS_BATT_NOINFO:
|
||||
return true;
|
||||
default:
|
||||
return (my_batt_level > OTA_MIN_BATT);
|
||||
return (batt_level > OTA_MIN_BATT);
|
||||
}
|
||||
#else
|
||||
return true; // we don't know batt level
|
||||
|
Loading…
Reference in New Issue
Block a user