Improve power saving (#1024)

* Limit tasks in loop based on voltage

* Updated disconnect voltage limit

* Fixed 8266 build
This commit is contained in:
Gunnar Skjold
2025-10-02 12:59:47 +02:00
committed by GitHub
parent 6a75b0fe71
commit b06aa5f71b
4 changed files with 375 additions and 285 deletions

View File

@@ -166,7 +166,7 @@ bool AmsMqttHandler::connected() {
bool AmsMqttHandler::loop() {
bool ret = mqtt.loop();
delay(10);
delay(10); // Needed to preserve power. After adding this, the voltage is super smooth on a HAN powered device
yield();
#if defined(ESP32)
esp_task_wdt_reset();

View File

@@ -67,7 +67,9 @@ private:
bool ledInvert, rgbInvert;
uint8_t vccPin, vccGnd_r, vccVcc_r;
float vccOffset, vccMultiplier;
float vcc = 3.3; // Last known Vcc
float maxVcc = 3.25; // Best to have this close to max as a start, in case Pow-U reboots and starts off with a low voltage, we dont want that to be perceived as max
unsigned long lastVccRead = 0;
uint16_t analogRange = 1024;
AdcConfig voltAdc, tempAdc;

View File

@@ -654,8 +654,12 @@ bool HwTools::writeLedPin(uint8_t color, uint8_t state) {
}
bool HwTools::isVoltageOptimal(float range) {
if(boardType >= 5 && boardType <= 7 && maxVcc > 2.8) { // Pow-*
float vcc = getVcc();
if(boardType >= 1 && boardType <= 8 && maxVcc > 2.8) { // BUS-Power boards
unsigned long now = millis();
if(now - lastVccRead > 250) {
vcc = getVcc();
lastVccRead = now;
}
if(vcc > 3.4 || vcc < 2.8) {
maxVcc = 0; // Voltage is outside the operating range, we have to assume voltage is OK
} else if(vcc > maxVcc) {