bugfix getBattLevel() (issue #444)

This commit is contained in:
Verkehrsrot 2019-09-20 09:04:24 +02:00
parent af0fd577d3
commit d9c6153559
5 changed files with 36 additions and 25 deletions

View File

@ -49,6 +49,7 @@ void myRxCallback(void *pUserData, uint8_t port, const uint8_t *pMsg,
void myTxCallback(void *pUserData, int fSuccess); void myTxCallback(void *pUserData, int fSuccess);
void mac_decode(const uint8_t cmd[], const uint8_t cmdlen, const mac_t table[], void mac_decode(const uint8_t cmd[], const uint8_t cmdlen, const mac_t table[],
const uint8_t tablesize); const uint8_t tablesize);
uint8_t getBattLevel(void);
#if (TIME_SYNC_LORAWAN) #if (TIME_SYNC_LORAWAN)
void user_request_network_time_callback(void *pVoidUserUTCTime, void user_request_network_time_callback(void *pVoidUserUTCTime,

View File

@ -19,6 +19,6 @@ void AXP192_init(void);
void AXP192_displaypower(void); void AXP192_displaypower(void);
uint16_t read_voltage(void); uint16_t read_voltage(void);
void calibrate_voltage(void); void calibrate_voltage(void);
uint8_t getBattLevel(void); bool batt_sufficient(void);
#endif #endif

View File

@ -666,4 +666,30 @@ void mac_decode(const uint8_t cmd[], const uint8_t cmdlen, const mac_t table[],
} // mac_decode() } // 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 #endif // HAS_LORA

View File

@ -41,7 +41,7 @@ inline String getHeaderValue(String header, String headerName) {
void start_ota_update() { void start_ota_update() {
// check battery status if we can before doing ota // 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); ESP_LOGE(TAG, "Battery voltage %dmV too low for OTA", batt_voltage);
return; return;
} }

View File

@ -167,31 +167,15 @@ void calibrate_voltage(void) {
#endif #endif
} }
uint8_t getBattLevel() { bool batt_sufficient() {
/*
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) #if (defined HAS_PMU || defined BAT_MEASURE_ADC)
uint16_t voltage = read_voltage(); uint16_t volts = read_voltage();
return ((volts < 1000) ||
switch (voltage) { (volts > OTA_MIN_BATT)); // no battery or battery sufficient
case 0: #else
return MCMD_DEVS_BATT_NOINFO; return true;
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 #endif
} // getBattLevel() }
// u1_t os_getBattLevel(void) { return getBattLevel(); };
uint16_t read_voltage() { uint16_t read_voltage() {