Another Bugfx 🧑‍🔧

This commit is contained in:
Maximilian Mewes 2023-01-06 19:07:39 +01:00
parent 3759071449
commit 8ba5dfe447
4 changed files with 25 additions and 13 deletions

View File

@ -30,14 +30,7 @@ class Battery
}
virtual void update(batteryConfig cfg)
{
if(cfg.minVoltage) this->setMinVoltage(cfg.minVoltage);
if(cfg.maxVoltage) this->setMaxVoltage(cfg.maxVoltage);
if(cfg.calibration) this->setCapacity(cfg.calibration);
if(cfg.level) this->setLevel(cfg.level);
if(cfg.calibration) this->setCalibration(cfg.calibration);
}
virtual void update(batteryConfig cfg) = 0;
/**
* Corresponding battery curves

View File

@ -22,6 +22,15 @@ class Lion : public Battery
this->setCalibration(USERMOD_BATTERY_LION_CALIBRATION);
}
void update(batteryConfig cfg)
{
if(cfg.minVoltage) this->setMinVoltage(cfg.minVoltage);
if(cfg.maxVoltage) this->setMaxVoltage(cfg.maxVoltage);
if(cfg.calibration) this->setCapacity(cfg.calibration);
if(cfg.level) this->setLevel(cfg.level);
if(cfg.calibration) this->setCalibration(cfg.calibration);
}
float mapVoltage(float v, float min, float max) override
{
return this->linearMapping(v, min, max); // basic mapping

View File

@ -22,6 +22,15 @@ class Lipo : public Battery
this->setCalibration(USERMOD_BATTERY_LIPO_CALIBRATION);
}
void update(batteryConfig cfg)
{
if(cfg.minVoltage) this->setMinVoltage(cfg.minVoltage);
if(cfg.maxVoltage) this->setMaxVoltage(cfg.maxVoltage);
if(cfg.calibration) this->setCapacity(cfg.calibration);
if(cfg.level) this->setLevel(cfg.level);
if(cfg.calibration) this->setCalibration(cfg.calibration);
}
/**
* LiPo batteries have a differnt dischargin curve, see
* https://blog.ampow.com/lipo-voltage-chart/

View File

@ -132,6 +132,7 @@ class UsermodBattery : public Usermod
}
bat->update(bcfg);
nextReadTime = millis() + readingInterval;
lastReadTime = millis();
@ -316,7 +317,7 @@ class UsermodBattery : public Usermod
battery[F("pin")] = batteryPin;
#endif
battery[F("type")] = (String)bcfg.type;
battery[F("type")] = (String)bcfg.type; // has to be a String otherwise it won't get converted to a Dropdown
battery[F("min-voltage")] = bat->getMinVoltage();
battery[F("max-voltage")] = bat->getMaxVoltage();
battery[F("capacity")] = bat->getCapacity();
@ -404,9 +405,6 @@ class UsermodBattery : public Usermod
getJsonValue(battery[F("capacity")], bcfg.capacity);
getJsonValue(battery[F("calibration")], bcfg.calibration);
setReadingInterval(battery[FPSTR(_readInterval)] | readingInterval);
// JsonArray type = battery[F("Type")];
// batteryType = type["bt"] | btype;
JsonObject ao = battery[F("auto-off")];
setAutoOffEnabled(ao[FPSTR(_enabled)] | autoOffEnabled);
@ -444,7 +442,10 @@ class UsermodBattery : public Usermod
}
#endif
return !battery[F("min-voltage")].isNull();
if(initDone)
bat->update(bcfg);
return !battery[FPSTR(_readInterval)].isNull();
}
/*