From 8125662753b8b8969eca53c689ee74c90aa1bff2 Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Thu, 27 Sep 2018 21:13:18 +0200 Subject: [PATCH] ota battery check modified --- src/battery.cpp | 5 +++++ src/battery.h | 1 + src/ota.cpp | 2 +- src/ota.h | 1 + 4 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/battery.cpp b/src/battery.cpp index 11371748..0e894965 100644 --- a/src/battery.cpp +++ b/src/battery.cpp @@ -49,4 +49,9 @@ uint16_t read_voltage() { return voltage; } +bool batt_sufficient() { + uint16_t volts = read_voltage(); + return (( volts < 1000 ) || (volts > OTA_MIN_BATT)); // no battery or battery sufficient +} + #endif // HAS_BATTERY_PROBE \ No newline at end of file diff --git a/src/battery.h b/src/battery.h index 93696fb5..b4a83676 100644 --- a/src/battery.h +++ b/src/battery.h @@ -9,5 +9,6 @@ uint16_t read_voltage(void); void calibrate_voltage(void); +bool batt_sufficient(void); #endif diff --git a/src/ota.cpp b/src/ota.cpp index 15ef87b5..ece73e28 100644 --- a/src/ota.cpp +++ b/src/ota.cpp @@ -45,7 +45,7 @@ void start_ota_update() { // check battery status if we can before doing ota #ifdef HAS_BATTERY_PROBE - if (batt_voltage < OTA_MIN_BATT) { + if (!batt_sufficient()) { ESP_LOGW(TAG, "Battery voltage %dmV too low for OTA", batt_voltage); return; } diff --git a/src/ota.h b/src/ota.h index 59c1e464..135591ea 100644 --- a/src/ota.h +++ b/src/ota.h @@ -5,6 +5,7 @@ #include "globals.h" #include "update.h" +#include "battery.h" #include #include #include