bugfix getBattLevel() (issue #444)
This commit is contained in:
parent
af0fd577d3
commit
d9c6153559
@ -49,6 +49,7 @@ void myRxCallback(void *pUserData, uint8_t port, const uint8_t *pMsg,
|
||||
void myTxCallback(void *pUserData, int fSuccess);
|
||||
void mac_decode(const uint8_t cmd[], const uint8_t cmdlen, const mac_t table[],
|
||||
const uint8_t tablesize);
|
||||
uint8_t getBattLevel(void);
|
||||
|
||||
#if (TIME_SYNC_LORAWAN)
|
||||
void user_request_network_time_callback(void *pVoidUserUTCTime,
|
||||
|
@ -19,6 +19,6 @@ void AXP192_init(void);
|
||||
void AXP192_displaypower(void);
|
||||
uint16_t read_voltage(void);
|
||||
void calibrate_voltage(void);
|
||||
uint8_t getBattLevel(void);
|
||||
bool batt_sufficient(void);
|
||||
|
||||
#endif
|
@ -666,4 +666,30 @@ void mac_decode(const uint8_t cmd[], const uint8_t cmdlen, const mac_t table[],
|
||||
|
||||
} // mac_decode()
|
||||
|
||||
uint8_t getBattLevel() {
|
||||
/*
|
||||
return values:
|
||||
MCMD_DEVS_EXT_POWER = 0x00, // external power supply
|
||||
MCMD_DEVS_BATT_MIN = 0x01, // min battery value
|
||||
MCMD_DEVS_BATT_MAX = 0xFE, // max battery value
|
||||
MCMD_DEVS_BATT_NOINFO = 0xFF, // unknown battery level
|
||||
*/
|
||||
#if (defined HAS_PMU || defined BAT_MEASURE_ADC)
|
||||
uint16_t voltage = read_voltage();
|
||||
|
||||
switch (voltage) {
|
||||
case 0:
|
||||
return MCMD_DEVS_BATT_NOINFO;
|
||||
case 0xffff:
|
||||
return MCMD_DEVS_EXT_POWER;
|
||||
default:
|
||||
return (voltage > OTA_MIN_BATT ? MCMD_DEVS_BATT_MAX : MCMD_DEVS_BATT_MIN);
|
||||
}
|
||||
#else // we don't have any info on battery level
|
||||
return MCMD_DEVS_BATT_NOINFO;
|
||||
#endif
|
||||
} // getBattLevel()
|
||||
|
||||
//u1_t os_getBattLevel(void) { return getBattLevel(); };
|
||||
|
||||
#endif // HAS_LORA
|
@ -41,7 +41,7 @@ inline String getHeaderValue(String header, String headerName) {
|
||||
void start_ota_update() {
|
||||
|
||||
// check battery status if we can before doing ota
|
||||
if (getBattLevel() == MCMD_DEVS_BATT_MIN) {
|
||||
if (!batt_sufficient()) {
|
||||
ESP_LOGE(TAG, "Battery voltage %dmV too low for OTA", batt_voltage);
|
||||
return;
|
||||
}
|
||||
|
@ -167,31 +167,15 @@ void calibrate_voltage(void) {
|
||||
#endif
|
||||
}
|
||||
|
||||
uint8_t getBattLevel() {
|
||||
/*
|
||||
return values:
|
||||
MCMD_DEVS_EXT_POWER = 0x00, // external power supply
|
||||
MCMD_DEVS_BATT_MIN = 0x01, // min battery value
|
||||
MCMD_DEVS_BATT_MAX = 0xFE, // max battery value
|
||||
MCMD_DEVS_BATT_NOINFO = 0xFF, // unknown battery level
|
||||
*/
|
||||
bool batt_sufficient() {
|
||||
#if (defined HAS_PMU || defined BAT_MEASURE_ADC)
|
||||
uint16_t voltage = read_voltage();
|
||||
|
||||
switch (voltage) {
|
||||
case 0:
|
||||
return MCMD_DEVS_BATT_NOINFO;
|
||||
case 0xffff:
|
||||
return MCMD_DEVS_EXT_POWER;
|
||||
default:
|
||||
return (voltage > OTA_MIN_BATT ? MCMD_DEVS_BATT_MAX : MCMD_DEVS_BATT_MIN);
|
||||
}
|
||||
#else // we don't have any info on battery level
|
||||
return MCMD_DEVS_BATT_NOINFO;
|
||||
uint16_t volts = read_voltage();
|
||||
return ((volts < 1000) ||
|
||||
(volts > OTA_MIN_BATT)); // no battery or battery sufficient
|
||||
#else
|
||||
return true;
|
||||
#endif
|
||||
} // getBattLevel()
|
||||
|
||||
// u1_t os_getBattLevel(void) { return getBattLevel(); };
|
||||
}
|
||||
|
||||
uint16_t read_voltage() {
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user