Battery voltage below minimum should be treated as 0%

This commit is contained in:
Ollo
2024-04-20 13:39:16 +02:00
parent dd3888ba52
commit cbde8ee11c
2 changed files with 13 additions and 4 deletions

View File

@@ -1095,7 +1095,16 @@ void plantcontrol()
sensorWater.setProperty("raw").send(String(waterRawSensor.getAverage()));
}
}
sensorLipo.setProperty("percent").send(String(100 * mBatteryVoltage / VOLT_MAX_BATT));
if (mBatteryVoltage < VOLT_MIN_BATT)
{
sensorLipo.setProperty("percent").send("0");
}
else
{
sensorLipo.setProperty("percent").send(String(100 * (((mBatteryVoltage - VOLT_MIN_BATT) / (VOLT_MAX_BATT - VOLT_MIN_BATT)))));
}
sensorLipo.setProperty("volt").send(String(mBatteryVoltage));
sensorLipo.setProperty("current").send(String(battery.getCurrent()));
sensorLipo.setProperty("Ah").send(String(battery.getAh()));