mirror of
https://github.com/wled/WLED.git
synced 2025-07-27 04:36:33 +00:00
Another Bugfx 🧑🔧
This commit is contained in:
parent
3759071449
commit
8ba5dfe447
@ -30,14 +30,7 @@ class Battery
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void update(batteryConfig cfg)
|
virtual void update(batteryConfig cfg) = 0;
|
||||||
{
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Corresponding battery curves
|
* Corresponding battery curves
|
||||||
|
@ -22,6 +22,15 @@ class Lion : public Battery
|
|||||||
this->setCalibration(USERMOD_BATTERY_LION_CALIBRATION);
|
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
|
float mapVoltage(float v, float min, float max) override
|
||||||
{
|
{
|
||||||
return this->linearMapping(v, min, max); // basic mapping
|
return this->linearMapping(v, min, max); // basic mapping
|
||||||
|
@ -22,6 +22,15 @@ class Lipo : public Battery
|
|||||||
this->setCalibration(USERMOD_BATTERY_LIPO_CALIBRATION);
|
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
|
* LiPo batteries have a differnt dischargin curve, see
|
||||||
* https://blog.ampow.com/lipo-voltage-chart/
|
* https://blog.ampow.com/lipo-voltage-chart/
|
||||||
|
@ -132,6 +132,7 @@ class UsermodBattery : public Usermod
|
|||||||
}
|
}
|
||||||
|
|
||||||
bat->update(bcfg);
|
bat->update(bcfg);
|
||||||
|
|
||||||
nextReadTime = millis() + readingInterval;
|
nextReadTime = millis() + readingInterval;
|
||||||
lastReadTime = millis();
|
lastReadTime = millis();
|
||||||
|
|
||||||
@ -316,7 +317,7 @@ class UsermodBattery : public Usermod
|
|||||||
battery[F("pin")] = batteryPin;
|
battery[F("pin")] = batteryPin;
|
||||||
#endif
|
#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("min-voltage")] = bat->getMinVoltage();
|
||||||
battery[F("max-voltage")] = bat->getMaxVoltage();
|
battery[F("max-voltage")] = bat->getMaxVoltage();
|
||||||
battery[F("capacity")] = bat->getCapacity();
|
battery[F("capacity")] = bat->getCapacity();
|
||||||
@ -405,9 +406,6 @@ class UsermodBattery : public Usermod
|
|||||||
getJsonValue(battery[F("calibration")], bcfg.calibration);
|
getJsonValue(battery[F("calibration")], bcfg.calibration);
|
||||||
setReadingInterval(battery[FPSTR(_readInterval)] | readingInterval);
|
setReadingInterval(battery[FPSTR(_readInterval)] | readingInterval);
|
||||||
|
|
||||||
// JsonArray type = battery[F("Type")];
|
|
||||||
// batteryType = type["bt"] | btype;
|
|
||||||
|
|
||||||
JsonObject ao = battery[F("auto-off")];
|
JsonObject ao = battery[F("auto-off")];
|
||||||
setAutoOffEnabled(ao[FPSTR(_enabled)] | autoOffEnabled);
|
setAutoOffEnabled(ao[FPSTR(_enabled)] | autoOffEnabled);
|
||||||
setAutoOffThreshold(ao[FPSTR(_threshold)] | autoOffThreshold);
|
setAutoOffThreshold(ao[FPSTR(_threshold)] | autoOffThreshold);
|
||||||
@ -444,7 +442,10 @@ class UsermodBattery : public Usermod
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return !battery[F("min-voltage")].isNull();
|
if(initDone)
|
||||||
|
bat->update(bcfg);
|
||||||
|
|
||||||
|
return !battery[FPSTR(_readInterval)].isNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user