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