full update for BatteryHealthMonitor
This commit is contained in:
parent
c6687529da
commit
3589f54d02
|
|
@ -52,7 +52,7 @@
|
|||
"sendExternalVoltage": false,
|
||||
"externalVoltagePin": 34,
|
||||
"monitorExternalVoltage": false,
|
||||
"externalSleepVoltage": 3.0
|
||||
"externalSleepVoltage": 10.9
|
||||
},
|
||||
"bme": {
|
||||
"active": false,
|
||||
|
|
|
|||
|
|
@ -982,7 +982,7 @@
|
|||
class="form-control"
|
||||
step="0.1"
|
||||
min="3.0"
|
||||
max="4.2"
|
||||
max="3.7"
|
||||
/>
|
||||
<span class="input-group-text"
|
||||
>volts</span
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ String batteryVoltage; // ????
|
|||
bool backUpDigiMode = false;
|
||||
bool modemLoggedToAPRSIS = false;
|
||||
|
||||
bool shouldSleep = false;
|
||||
bool shouldSleepLowVoltage = false;
|
||||
|
||||
std::vector<ReceivedPacket> receivedPackets;
|
||||
|
||||
|
|
@ -185,5 +185,5 @@ void loop() {
|
|||
|
||||
show_display(firstLine, secondLine, thirdLine, fourthLine, fifthLine, sixthLine, seventhLine, 0);
|
||||
Utils::checkRebootTime();
|
||||
Utils::checkSleepByLowBatteryVoltage();
|
||||
Utils::checkSleepByLowBatteryVoltage(1);
|
||||
}
|
||||
|
|
@ -1,9 +1,11 @@
|
|||
#include "battery_utils.h"
|
||||
#include "configuration.h"
|
||||
#include "boards_pinout.h"
|
||||
#include "utils.h"
|
||||
|
||||
extern Configuration Config;
|
||||
extern uint32_t lastBatteryCheck;
|
||||
extern bool shouldSleepLowVoltage;
|
||||
|
||||
float adcReadingTransformation = (3.3/4095);
|
||||
float voltageDividerCorrection = 0.288;
|
||||
|
|
@ -88,4 +90,18 @@ namespace BATTERY_Utils {
|
|||
}
|
||||
}
|
||||
|
||||
void startupBatteryHealth() {
|
||||
#ifdef BATTERY_PIN
|
||||
if (Config.battery.monitorInternalVoltage && checkInternalVoltage() < Config.battery.internalSleepVoltage) {
|
||||
shouldSleepLowVoltage = true;
|
||||
}
|
||||
#endif
|
||||
if (Config.battery.monitorExternalVoltage && checkExternalVoltage() < Config.battery.externalSleepVoltage) {
|
||||
shouldSleepLowVoltage = true;
|
||||
}
|
||||
if (shouldSleepLowVoltage) {
|
||||
Utils::checkSleepByLowBatteryVoltage(0);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -8,7 +8,8 @@ namespace BATTERY_Utils {
|
|||
|
||||
float checkInternalVoltage();
|
||||
float checkExternalVoltage();
|
||||
void checkIfShouldSleep();
|
||||
void checkIfShouldSleep(); // ????
|
||||
void startupBatteryHealth();
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
#include "configuration.h"
|
||||
#include "battery_utils.h"
|
||||
#include "boards_pinout.h"
|
||||
#include "power_utils.h"
|
||||
|
||||
|
|
@ -128,7 +129,7 @@ namespace POWER_Utils {
|
|||
pinMode(INTERNAL_LED_PIN, OUTPUT);
|
||||
#endif
|
||||
|
||||
if (Config.battery.sendExternalVoltage) {
|
||||
if (Config.battery.sendExternalVoltage || Config.battery.monitorExternalVoltage) {
|
||||
pinMode(Config.battery.externalVoltagePin, INPUT);
|
||||
}
|
||||
|
||||
|
|
@ -152,6 +153,8 @@ namespace POWER_Utils {
|
|||
#endif
|
||||
|
||||
delay(1000);
|
||||
|
||||
BATTERY_Utils::startupBatteryHealth();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -32,7 +32,7 @@ extern String distance;
|
|||
extern bool WiFiConnected;
|
||||
extern int wxModuleType;
|
||||
extern bool backUpDigiMode;
|
||||
extern bool shouldSleep;
|
||||
extern bool shouldSleepLowVoltage;
|
||||
|
||||
bool statusAfterBoot = true;
|
||||
bool beaconUpdate = true;
|
||||
|
|
@ -123,12 +123,19 @@ namespace Utils {
|
|||
secondaryBeaconPacket += Config.beacon.comment;
|
||||
|
||||
#ifdef BATTERY_PIN
|
||||
if (Config.battery.sendInternalVoltage) {
|
||||
if (Config.battery.sendInternalVoltage || Config.battery.monitorInternalVoltage) {
|
||||
float internalVoltage = BATTERY_Utils::checkInternalVoltage();
|
||||
String internalVoltageInfo = "Batt=" + String(internalVoltage,2) + "V";
|
||||
beaconPacket += " " + internalVoltageInfo;
|
||||
secondaryBeaconPacket += " " + internalVoltageInfo;
|
||||
sixthLine = " ( " + internalVoltageInfo + ")";
|
||||
String internalVoltageInfo = String(internalVoltage,2) + "V";
|
||||
if (Config.battery.sendInternalVoltage) {
|
||||
beaconPacket += " Batt=" + internalVoltageInfo;
|
||||
secondaryBeaconPacket += " Batt=" + internalVoltageInfo;
|
||||
sixthLine = " (Batt=" + internalVoltageInfo + ")";
|
||||
}
|
||||
if (Config.battery.monitorInternalVoltage && internalVoltage < Config.battery.internalSleepVoltage) {
|
||||
beaconPacket += " **IntBatWarning:SLEEP**";
|
||||
secondaryBeaconPacket += " **IntBatWarning:SLEEP**";
|
||||
shouldSleepLowVoltage = true;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
@ -140,10 +147,10 @@ namespace Utils {
|
|||
secondaryBeaconPacket += " Ext=" + externalVoltageInfo;
|
||||
sixthLine = " (Ext V=" + externalVoltageInfo + ")";
|
||||
}
|
||||
if (Config.battery.monitorExternalVoltage && externalVoltage <= Config.battery.externalSleepVoltage) {
|
||||
if (Config.battery.monitorExternalVoltage && externalVoltage < Config.battery.externalSleepVoltage) {
|
||||
beaconPacket += " **ExtBatWarning:SLEEP**";
|
||||
secondaryBeaconPacket += " **ExtBatWarning:SLEEP**";
|
||||
shouldSleep = true;
|
||||
shouldSleepLowVoltage = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -272,11 +279,22 @@ namespace Utils {
|
|||
}
|
||||
}
|
||||
|
||||
void checkSleepByLowBatteryVoltage() {
|
||||
if (shouldSleep) {
|
||||
// dormir
|
||||
shouldSleep = false;
|
||||
Serial.println("Durmiendo");
|
||||
void checkSleepByLowBatteryVoltage(uint8_t mode) {
|
||||
if (shouldSleepLowVoltage) {
|
||||
if (mode == 0) {
|
||||
delay(3000);
|
||||
}
|
||||
Serial.println("\n\n*** Sleeping Low Battey Voltage ***\n\n");
|
||||
esp_sleep_enable_timer_wakeup(30 * 60 * 1000000); // sleep 30 min
|
||||
if (mode == 1) {
|
||||
display_toggle(false);
|
||||
}
|
||||
#ifdef VEXT_CTRL
|
||||
#ifndef HELTEC_WSL_V3
|
||||
digitalWrite(VEXT_CTRL, LOW);
|
||||
#endif
|
||||
#endif
|
||||
esp_deep_sleep_start();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ namespace Utils {
|
|||
void println(const String& text);
|
||||
void checkRebootMode();
|
||||
void checkRebootTime();
|
||||
void checkSleepByLowBatteryVoltage();
|
||||
void checkSleepByLowBatteryVoltage(uint8_t mode);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
#include "configuration.h"
|
||||
#include "ota_utils.h"
|
||||
#include "web_utils.h"
|
||||
#include "display.h"
|
||||
#include "utils.h"
|
||||
|
||||
extern Configuration Config;
|
||||
|
|
@ -192,7 +193,7 @@ namespace WEB_Utils {
|
|||
AsyncWebServerResponse *response = request->beginResponse(302, "text/html", "");
|
||||
response->addHeader("Location", "/");
|
||||
request->send(response);
|
||||
|
||||
display_toggle(false);
|
||||
ESP.restart();
|
||||
}
|
||||
|
||||
|
|
@ -204,6 +205,7 @@ namespace WEB_Utils {
|
|||
|
||||
request->send(200, "text/plain", "Beacon will be sent in a while");
|
||||
} else if (type == "reboot") {
|
||||
display_toggle(false);
|
||||
ESP.restart();
|
||||
} else {
|
||||
request->send(404, "text/plain", "Not Found");
|
||||
|
|
|
|||
Loading…
Reference in New Issue