minor changes

This commit is contained in:
Maximilian Mewes 2023-01-05 20:38:55 +01:00
parent 8dd1745149
commit 4c8b490c89
5 changed files with 20 additions and 17 deletions

View File

@ -81,11 +81,7 @@ class Battery
*/ */
virtual void setMaxVoltage(float voltage) virtual void setMaxVoltage(float voltage)
{ {
#ifdef USERMOD_BATTERY_USE_LIPO this->maxVoltage = max(getMinVoltage()+.5f, voltage);
this->maxVoltage = max(getMinVoltage()+0.7f, voltage);
#else
this->maxVoltage = max(getMinVoltage()+1.0f, voltage);
#endif
} }
/* /*

View File

@ -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 // 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 // Discharge voltage: 2.5 volt + .1 for personal safety
#ifndef USERMOD_BATTERY_MIN_VOLTAGE #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 !! // LiPo "1S" Batteries should not be dischared below 3V !!
#define USERMOD_BATTERY_MIN_VOLTAGE 3.2f #define USERMOD_BATTERY_MIN_VOLTAGE 3.2f
#else #else
@ -49,11 +49,6 @@
#define USERMOD_BATTERY_CALIBRATION 0 #define USERMOD_BATTERY_CALIBRATION 0
#endif #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 // auto-off feature
#ifndef USERMOD_BATTERY_AUTO_OFF_ENABLED #ifndef USERMOD_BATTERY_AUTO_OFF_ENABLED
#define USERMOD_BATTERY_AUTO_OFF_ENABLED true #define USERMOD_BATTERY_AUTO_OFF_ENABLED true

View File

@ -20,12 +20,12 @@ class Lion : public Battery
float mapVoltage(float v, float min, float max) override 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 void calculateAndSetLevel(float voltage) override
{ {
this->setLevel(this->mapVoltage(voltage, this->getMinVoltage(), this->getMaxVoltage()));
}; };
virtual void setMaxVoltage(float voltage) override virtual void setMaxVoltage(float voltage) override

View File

@ -35,6 +35,8 @@ class Lipo : public Battery
else // level > 90% else // level > 90%
lvl = this->linearMapping(lvl, 90, 105, 95, 100); // highest 15% -> drop slowly lvl = this->linearMapping(lvl, 90, 105, 95, 100); // highest 15% -> drop slowly
} }
return lvl;
}; };
void calculateAndSetLevel(float voltage) override void calculateAndSetLevel(float voltage) override

View File

@ -18,8 +18,11 @@ class UsermodBattery : public Usermod
private: private:
// battery pin can be defined in my_config.h // battery pin can be defined in my_config.h
int8_t batteryPin = USERMOD_BATTERY_MEASUREMENT_PIN; int8_t batteryPin = USERMOD_BATTERY_MEASUREMENT_PIN;
int8_t batteryType = USERMOB_BATTERY_DEFAULT_TYPE;
// Battery object // Battery object
Battery* bat; Battery* bat;
// how often to read the battery voltage // how often to read the battery voltage
unsigned long readingInterval = USERMOD_BATTERY_MEASUREMENT_INTERVAL; unsigned long readingInterval = USERMOD_BATTERY_MEASUREMENT_INTERVAL;
unsigned long nextReadTime = 0; unsigned long nextReadTime = 0;
@ -118,14 +121,14 @@ class UsermodBattery : public Usermod
pinMode(batteryPin, INPUT); pinMode(batteryPin, INPUT);
#endif #endif
// this could also be handled with a factory class but for only 2 types now it should be sufficient // this could also be handled with a factory class but for only 2 types it should be sufficient for now
if(USERMOB_BATTERY_DEFAULT_TYPE == 1) { if(batteryType == 1) {
bat = new Lipo(); bat = new Lipo();
} else } else
if(USERMOB_BATTERY_DEFAULT_TYPE == 2) { if(batteryType == 2) {
bat = new Lion(); bat = new Lion();
} else { } else {
bat = new Lipo(); bat = new Lipo(); // in the future one could create a nullObject
} }
nextReadTime = millis() + readingInterval; nextReadTime = millis() + readingInterval;
@ -317,6 +320,10 @@ class UsermodBattery : public Usermod
battery[F("capacity")] = bat->getCapacity(); battery[F("capacity")] = bat->getCapacity();
battery[F("calibration")] = bat->getCalibration(); battery[F("calibration")] = bat->getCalibration();
battery[FPSTR(_readInterval)] = readingInterval; 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 JsonObject ao = battery.createNestedObject(F("auto-off")); // auto off section
ao[FPSTR(_enabled)] = autoOffEnabled; ao[FPSTR(_enabled)] = autoOffEnabled;
@ -393,6 +400,9 @@ class UsermodBattery : public Usermod
bat->setCapacity(battery[F("capacity")] | bat->getCapacity()); bat->setCapacity(battery[F("capacity")] | bat->getCapacity());
bat->setCalibration(battery[F("calibration")] | bat->getCalibration()); bat->setCalibration(battery[F("calibration")] | bat->getCalibration());
setReadingInterval(battery[FPSTR(_readInterval)] | readingInterval); setReadingInterval(battery[FPSTR(_readInterval)] | readingInterval);
// JsonArray type = battery[F("Type")];
// batteryType = type["bt"] | batteryType;
JsonObject ao = battery[F("auto-off")]; JsonObject ao = battery[F("auto-off")];
setAutoOffEnabled(ao[FPSTR(_enabled)] | autoOffEnabled); setAutoOffEnabled(ao[FPSTR(_enabled)] | autoOffEnabled);