diff --git a/usermods/Battery/battery.h b/usermods/Battery/battery.h index f3daf05c4..c678f775d 100644 --- a/usermods/Battery/battery.h +++ b/usermods/Battery/battery.h @@ -81,11 +81,7 @@ class Battery */ virtual void setMaxVoltage(float voltage) { - #ifdef USERMOD_BATTERY_USE_LIPO - this->maxVoltage = max(getMinVoltage()+0.7f, voltage); - #else - this->maxVoltage = max(getMinVoltage()+1.0f, voltage); - #endif + this->maxVoltage = max(getMinVoltage()+.5f, voltage); } /* diff --git a/usermods/Battery/battery_defaults.h b/usermods/Battery/battery_defaults.h index 73f14f62a..4a04ac352 100644 --- a/usermods/Battery/battery_defaults.h +++ b/usermods/Battery/battery_defaults.h @@ -27,7 +27,7 @@ // https://batterybro.com/blogs/18650-wholesale-battery-reviews/18852515-when-to-recycle-18650-batteries-and-how-to-start-a-collection-center-in-your-vape-shop // Discharge voltage: 2.5 volt + .1 for personal safety #ifndef USERMOD_BATTERY_MIN_VOLTAGE - #ifdef USERMOD_BATTERY_USE_LIPO + #if USERMOB_BATTERY_DEFAULT_TYPE == 1 // LiPo "1S" Batteries should not be dischared below 3V !! #define USERMOD_BATTERY_MIN_VOLTAGE 3.2f #else @@ -49,11 +49,6 @@ #define USERMOD_BATTERY_CALIBRATION 0 #endif -// calculate remaining time / the time that is left before the battery runs out of power -// #ifndef USERMOD_BATTERY_CALCULATE_TIME_LEFT_ENABLED -// #define USERMOD_BATTERY_CALCULATE_TIME_LEFT_ENABLED false -// #endif - // auto-off feature #ifndef USERMOD_BATTERY_AUTO_OFF_ENABLED #define USERMOD_BATTERY_AUTO_OFF_ENABLED true diff --git a/usermods/Battery/lion.h b/usermods/Battery/lion.h index e8d78cc72..69095ac09 100644 --- a/usermods/Battery/lion.h +++ b/usermods/Battery/lion.h @@ -20,12 +20,12 @@ class Lion : public Battery float mapVoltage(float v, float min, float max) override { - return 0.0f; + return this->linearMapping(v, min, max); // basic mapping }; void calculateAndSetLevel(float voltage) override { - + this->setLevel(this->mapVoltage(voltage, this->getMinVoltage(), this->getMaxVoltage())); }; virtual void setMaxVoltage(float voltage) override diff --git a/usermods/Battery/lipo.h b/usermods/Battery/lipo.h index 4e9b0be7c..92ede8f81 100644 --- a/usermods/Battery/lipo.h +++ b/usermods/Battery/lipo.h @@ -35,6 +35,8 @@ class Lipo : public Battery else // level > 90% lvl = this->linearMapping(lvl, 90, 105, 95, 100); // highest 15% -> drop slowly } + + return lvl; }; void calculateAndSetLevel(float voltage) override diff --git a/usermods/Battery/usermod_v2_Battery.h b/usermods/Battery/usermod_v2_Battery.h index 4c77ca5dd..87b73ec6d 100644 --- a/usermods/Battery/usermod_v2_Battery.h +++ b/usermods/Battery/usermod_v2_Battery.h @@ -18,8 +18,11 @@ class UsermodBattery : public Usermod private: // battery pin can be defined in my_config.h int8_t batteryPin = USERMOD_BATTERY_MEASUREMENT_PIN; + + int8_t batteryType = USERMOB_BATTERY_DEFAULT_TYPE; // Battery object Battery* bat; + // how often to read the battery voltage unsigned long readingInterval = USERMOD_BATTERY_MEASUREMENT_INTERVAL; unsigned long nextReadTime = 0; @@ -118,14 +121,14 @@ class UsermodBattery : public Usermod pinMode(batteryPin, INPUT); #endif - // this could also be handled with a factory class but for only 2 types now it should be sufficient - if(USERMOB_BATTERY_DEFAULT_TYPE == 1) { + // this could also be handled with a factory class but for only 2 types it should be sufficient for now + if(batteryType == 1) { bat = new Lipo(); } else - if(USERMOB_BATTERY_DEFAULT_TYPE == 2) { + if(batteryType == 2) { bat = new Lion(); } else { - bat = new Lipo(); + bat = new Lipo(); // in the future one could create a nullObject } nextReadTime = millis() + readingInterval; @@ -317,6 +320,10 @@ class UsermodBattery : public Usermod battery[F("capacity")] = bat->getCapacity(); battery[F("calibration")] = bat->getCalibration(); battery[FPSTR(_readInterval)] = readingInterval; + + // JsonArray type = battery[F("Type")]; + // type[0] = 1; + // type[1] = 2; JsonObject ao = battery.createNestedObject(F("auto-off")); // auto off section ao[FPSTR(_enabled)] = autoOffEnabled; @@ -393,6 +400,9 @@ class UsermodBattery : public Usermod bat->setCapacity(battery[F("capacity")] | bat->getCapacity()); bat->setCalibration(battery[F("calibration")] | bat->getCalibration()); setReadingInterval(battery[FPSTR(_readInterval)] | readingInterval); + + // JsonArray type = battery[F("Type")]; + // batteryType = type["bt"] | batteryType; JsonObject ao = battery[F("auto-off")]; setAutoOffEnabled(ao[FPSTR(_enabled)] | autoOffEnabled);