Limit tasks in loop based on voltage

This commit is contained in:
Gunnar Skjold
2025-03-22 07:22:47 +01:00
parent a7324d828a
commit a894541770
4 changed files with 375 additions and 312 deletions

View File

@@ -67,7 +67,10 @@ private:
bool ledInvert, rgbInvert;
uint8_t vccPin, vccGnd_r, vccVcc_r;
float vccOffset, vccMultiplier;
float vcc = 3.3; // Last known Vcc
float maxVcc = 3.2; // 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) {