mirror of
https://github.com/wled/WLED.git
synced 2025-04-24 14:57:18 +00:00
runtime exception fix 🐛
This commit is contained in:
parent
4c8b490c89
commit
85d59945a0
@ -20,9 +20,15 @@ class UsermodBattery : public Usermod
|
||||
int8_t batteryPin = USERMOD_BATTERY_MEASUREMENT_PIN;
|
||||
|
||||
int8_t batteryType = USERMOB_BATTERY_DEFAULT_TYPE;
|
||||
// Battery object
|
||||
Battery* bat;
|
||||
|
||||
|
||||
float minVoltage = USERMOD_BATTERY_MIN_VOLTAGE;
|
||||
float maxVoltage = USERMOD_BATTERY_MAX_VOLTAGE;
|
||||
unsigned int capacity = USERMOD_BATTERY_TOTAL_CAPACITY; // current capacity
|
||||
float voltage = this->maxVoltage; // current voltage
|
||||
int8_t level = 100; // current level
|
||||
float calibration = USERMOD_BATTERY_CALIBRATION; // offset or calibration value to fine tune the calculated voltage
|
||||
Battery* bat = nullptr;
|
||||
|
||||
// how often to read the battery voltage
|
||||
unsigned long readingInterval = USERMOD_BATTERY_MEASUREMENT_INTERVAL;
|
||||
unsigned long nextReadTime = 0;
|
||||
@ -121,7 +127,7 @@ class UsermodBattery : public Usermod
|
||||
pinMode(batteryPin, INPUT);
|
||||
#endif
|
||||
|
||||
// this could also be handled with a factory class but for only 2 types it should be sufficient for now
|
||||
//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
|
||||
@ -315,15 +321,13 @@ class UsermodBattery : public Usermod
|
||||
battery[F("pin")] = batteryPin;
|
||||
#endif
|
||||
|
||||
battery[F("min-voltage")] = bat->getMinVoltage();
|
||||
battery[F("max-voltage")] = bat->getMaxVoltage();
|
||||
battery[F("capacity")] = bat->getCapacity();
|
||||
battery[F("calibration")] = bat->getCalibration();
|
||||
if(bat) {
|
||||
battery[F("min-voltage")] = bat->getMinVoltage();
|
||||
battery[F("max-voltage")] = bat->getMaxVoltage();
|
||||
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;
|
||||
@ -395,10 +399,12 @@ class UsermodBattery : public Usermod
|
||||
newBatteryPin = battery[F("pin")] | newBatteryPin;
|
||||
#endif
|
||||
|
||||
bat->setMinVoltage(battery[F("min-voltage")] | bat->getMinVoltage());
|
||||
bat->setMaxVoltage(battery[F("max-voltage")] | bat->getMaxVoltage());
|
||||
bat->setCapacity(battery[F("capacity")] | bat->getCapacity());
|
||||
bat->setCalibration(battery[F("calibration")] | bat->getCalibration());
|
||||
if(bat) {
|
||||
bat->setMinVoltage(battery[F("min-voltage")] | bat->getMinVoltage());
|
||||
bat->setMaxVoltage(battery[F("max-voltage")] | bat->getMaxVoltage());
|
||||
bat->setCapacity(battery[F("capacity")] | bat->getCapacity());
|
||||
bat->setCalibration(battery[F("calibration")] | bat->getCalibration());
|
||||
}
|
||||
setReadingInterval(battery[FPSTR(_readInterval)] | readingInterval);
|
||||
|
||||
// JsonArray type = battery[F("Type")];
|
||||
|
Loading…
x
Reference in New Issue
Block a user