From 2245ee6fce23343cacfd6cd424a6339be0f1fada Mon Sep 17 00:00:00 2001 From: Maximilian Mewes Date: Tue, 30 Apr 2024 17:02:57 +0200 Subject: [PATCH] bugfixes --- usermods/Battery/battery.h | 9 +++++---- usermods/Battery/usermod_v2_Battery.h | 18 ++++-------------- 2 files changed, 9 insertions(+), 18 deletions(-) diff --git a/usermods/Battery/battery.h b/usermods/Battery/battery.h index 084e6c0aa..31e2e0755 100644 --- a/usermods/Battery/battery.h +++ b/usermods/Battery/battery.h @@ -27,7 +27,7 @@ class Battery public: Battery() { - this->setVoltage(this->getVoltage()); + this->setVoltage(USERMOD_BATTERY_UNKOWN_MAX_VOLTAGE); this->setVoltageMultiplier(USERMOD_BATTERY_VOLTAGE_MULTIPLIER); this->setCalibration(USERMOD_BATTERY_CALIBRATION); } @@ -105,9 +105,10 @@ class Battery */ void setVoltage(float voltage) { - this->voltage = ( (voltage < this->getMinVoltage() * 0.85f) || (voltage > this->getMaxVoltage() * 1.1f) ) - ? -1.0f - : voltage; + // this->voltage = ( (voltage < this->getMinVoltage() * 0.85f) || (voltage > this->getMaxVoltage() * 1.1f) ) + // ? -1.0f + // : voltage; + this->voltage = voltage; } float getLevel() diff --git a/usermods/Battery/usermod_v2_Battery.h b/usermods/Battery/usermod_v2_Battery.h index b9631d6db..31c31f066 100644 --- a/usermods/Battery/usermod_v2_Battery.h +++ b/usermods/Battery/usermod_v2_Battery.h @@ -28,8 +28,6 @@ class UsermodBattery : public Usermod unsigned long lastReadTime = 0; // between 0 and 1, to control strength of voltage smoothing filter float alpha = USERMOD_BATTERY_AVERAGING_ALPHA; - // offset or calibration value to fine tune the calculated voltage - float calibration = USERMOD_BATTERY_CALIBRATION; // auto shutdown/shutoff/master off feature bool autoOffEnabled = USERMOD_BATTERY_AUTO_OFF_ENABLED; @@ -45,6 +43,7 @@ class UsermodBattery : public Usermod unsigned long lowPowerActivationTime = 0; // used temporary during active time uint8_t lastPreset = 0; + // bool initDone = false; bool initializing = true; @@ -311,9 +310,8 @@ class UsermodBattery : public Usermod { JsonObject battery = root.createNestedObject(FPSTR(_name)); - if (battery.isNull()) { + if (battery.isNull()) battery = root.createNestedObject(FPSTR(_name)); - } addBatteryToJsonObject(battery, true); @@ -460,8 +458,8 @@ class UsermodBattery : public Usermod // calculateTimeLeftEnabled = battery[F("time-left")] | calculateTimeLeftEnabled; setMinBatteryVoltage(battery[F("min-voltage")] | bat->getMinVoltage()); setMaxBatteryVoltage(battery[F("max-voltage")] | bat->getMaxVoltage()); - setCalibration(battery[F("calibration")] | calibration); - setVoltageMultiplier(battery[F("voltage-multiplier")] | voltageMultiplier); + setCalibration(battery[F("calibration")] | bat->getCalibration()); + setVoltageMultiplier(battery[F("voltage-multiplier")] | bat->getVoltageMultiplier()); setReadingInterval(battery[FPSTR(_readInterval)] | readingInterval); getUsermodConfigFromJsonObject(battery); @@ -548,14 +546,6 @@ class UsermodBattery : public Usermod return cfg.type; } - /** - * Set currently active battery type - */ - batteryType setBatteryType(batteryType type) - { - cfg.type = type; - } - /** * */