mirror of
https://github.com/wled/WLED.git
synced 2025-07-16 15:26:31 +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 batteryPin = USERMOD_BATTERY_MEASUREMENT_PIN;
|
||||||
|
|
||||||
int8_t batteryType = USERMOB_BATTERY_DEFAULT_TYPE;
|
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
|
// 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;
|
||||||
@ -121,7 +127,7 @@ 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 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) {
|
if(batteryType == 1) {
|
||||||
bat = new Lipo();
|
bat = new Lipo();
|
||||||
} else
|
} else
|
||||||
@ -315,15 +321,13 @@ class UsermodBattery : public Usermod
|
|||||||
battery[F("pin")] = batteryPin;
|
battery[F("pin")] = batteryPin;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
battery[F("min-voltage")] = bat->getMinVoltage();
|
if(bat) {
|
||||||
battery[F("max-voltage")] = bat->getMaxVoltage();
|
battery[F("min-voltage")] = bat->getMinVoltage();
|
||||||
battery[F("capacity")] = bat->getCapacity();
|
battery[F("max-voltage")] = bat->getMaxVoltage();
|
||||||
battery[F("calibration")] = bat->getCalibration();
|
battery[F("capacity")] = bat->getCapacity();
|
||||||
|
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;
|
||||||
@ -395,10 +399,12 @@ class UsermodBattery : public Usermod
|
|||||||
newBatteryPin = battery[F("pin")] | newBatteryPin;
|
newBatteryPin = battery[F("pin")] | newBatteryPin;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
bat->setMinVoltage(battery[F("min-voltage")] | bat->getMinVoltage());
|
if(bat) {
|
||||||
bat->setMaxVoltage(battery[F("max-voltage")] | bat->getMaxVoltage());
|
bat->setMinVoltage(battery[F("min-voltage")] | bat->getMinVoltage());
|
||||||
bat->setCapacity(battery[F("capacity")] | bat->getCapacity());
|
bat->setMaxVoltage(battery[F("max-voltage")] | bat->getMaxVoltage());
|
||||||
bat->setCalibration(battery[F("calibration")] | bat->getCalibration());
|
bat->setCapacity(battery[F("capacity")] | bat->getCapacity());
|
||||||
|
bat->setCalibration(battery[F("calibration")] | bat->getCalibration());
|
||||||
|
}
|
||||||
setReadingInterval(battery[FPSTR(_readInterval)] | readingInterval);
|
setReadingInterval(battery[FPSTR(_readInterval)] | readingInterval);
|
||||||
|
|
||||||
// JsonArray type = battery[F("Type")];
|
// JsonArray type = battery[F("Type")];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user