From 7b9da4a442e403194383e71eaa595bd7729b678f Mon Sep 17 00:00:00 2001 From: Matthias Prinke Date: Sun, 14 Apr 2024 22:34:27 +0200 Subject: [PATCH] Fixed battLevel calculation --- BresserWeatherSensorLW.ino | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/BresserWeatherSensorLW.ino b/BresserWeatherSensorLW.ino index 66e6b64..3336495 100644 --- a/BresserWeatherSensorLW.ino +++ b/BresserWeatherSensorLW.ino @@ -19,7 +19,6 @@ // BresserWeatherSensorTTN by Matthias Prinke (https://github.com/matthias-bs/BresserWeatherSensorTTN) // Lora-Serialization by Joscha Feth (https://github.com/thesolarnomad/lora-serialization) // ESP32Time by Felix Biego (https://github.com/fbiego/ESP32Time) -// ESP32AnalogRead by Kevin Harrington (madhephaestus) (https://github.com/madhephaestus/ESP32AnalogRead) // OneWireNg by Piotr Stolarz (https://github.com/pstolarz/OneWireNg) // DallasTemperature / Arduino-Temperature-Control-Library by Miles Burton (https://github.com/milesburton/Arduino-Temperature-Control-Library) // @@ -624,10 +623,14 @@ void setup() { battLevel = 255; } + else if (voltage > BATTERY_CHARGE_LIMIT) + { + battLevel = 0; + } else { battLevel = static_cast( - static_cast(voltage - BATTERY_DISCHARGE_LIMIT) / static_cast(BATTERY_CHARGE_LIMIT - BATTERY_DISCHARGE_LIMIT)); + static_cast(voltage - BATTERY_DISCHARGE_LIMIT) / static_cast(BATTERY_CHARGE_LIMIT - BATTERY_DISCHARGE_LIMIT) * 255); battLevel = (battLevel == 0) ? 1 : battLevel; battLevel = (battLevel == 255) ? 254 : battLevel; }