mirror of
https://github.com/wled/WLED.git
synced 2025-07-18 00:06:31 +00:00
Move battery types to a separate folder 📁
This commit is contained in:
parent
b77e1eb94b
commit
b8c61b5236
@ -14,7 +14,6 @@ class Battery
|
|||||||
protected:
|
protected:
|
||||||
float minVoltage;
|
float minVoltage;
|
||||||
float maxVoltage;
|
float maxVoltage;
|
||||||
unsigned int capacity;
|
|
||||||
float voltage;
|
float voltage;
|
||||||
int8_t level = 100;
|
int8_t level = 100;
|
||||||
float calibration; // offset or calibration value to fine tune the calculated voltage
|
float calibration; // offset or calibration value to fine tune the calculated voltage
|
||||||
@ -34,7 +33,7 @@ class Battery
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Corresponding battery curves
|
* Corresponding battery curves
|
||||||
* calculates the capacity in % (0-100) with given voltage and possible voltage range
|
* calculates the level in % (0-100) with given voltage and possible voltage range
|
||||||
*/
|
*/
|
||||||
virtual float mapVoltage(float v, float min, float max) = 0;
|
virtual float mapVoltage(float v, float min, float max) = 0;
|
||||||
// {
|
// {
|
||||||
@ -86,20 +85,6 @@ class Battery
|
|||||||
this->maxVoltage = max(getMinVoltage()+.5f, voltage);
|
this->maxVoltage = max(getMinVoltage()+.5f, voltage);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Get the capacity of all cells in parralel sumed up
|
|
||||||
* unit: mAh
|
|
||||||
*/
|
|
||||||
unsigned int getCapacity()
|
|
||||||
{
|
|
||||||
return this->capacity;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setCapacity(unsigned int capacity)
|
|
||||||
{
|
|
||||||
this->capacity = capacity;
|
|
||||||
}
|
|
||||||
|
|
||||||
float getVoltage()
|
float getVoltage()
|
||||||
{
|
{
|
||||||
return this->voltage;
|
return this->voltage;
|
||||||
|
@ -40,9 +40,6 @@
|
|||||||
#ifndef USERMOD_BATTERY_UNKOWN_MAX_VOLTAGE
|
#ifndef USERMOD_BATTERY_UNKOWN_MAX_VOLTAGE
|
||||||
#define USERMOD_BATTERY_UNKOWN_MAX_VOLTAGE 4.2f
|
#define USERMOD_BATTERY_UNKOWN_MAX_VOLTAGE 4.2f
|
||||||
#endif
|
#endif
|
||||||
#ifndef USERMOD_BATTERY_UNKOWN_CAPACITY
|
|
||||||
#define USERMOD_BATTERY_UNKOWN_CAPACITY 2500
|
|
||||||
#endif
|
|
||||||
#ifndef USERMOD_BATTERY_UNKOWN_CALIBRATION
|
#ifndef USERMOD_BATTERY_UNKOWN_CALIBRATION
|
||||||
// offset or calibration value to fine tune the calculated voltage
|
// offset or calibration value to fine tune the calculated voltage
|
||||||
#define USERMOD_BATTERY_UNKOWN_CALIBRATION 0
|
#define USERMOD_BATTERY_UNKOWN_CALIBRATION 0
|
||||||
@ -59,9 +56,6 @@
|
|||||||
#ifndef USERMOD_BATTERY_LIPO_MAX_VOLTAGE
|
#ifndef USERMOD_BATTERY_LIPO_MAX_VOLTAGE
|
||||||
#define USERMOD_BATTERY_LIPO_MAX_VOLTAGE 4.2f
|
#define USERMOD_BATTERY_LIPO_MAX_VOLTAGE 4.2f
|
||||||
#endif
|
#endif
|
||||||
#ifndef USERMOD_BATTERY_LIPO_CAPACITY
|
|
||||||
#define USERMOD_BATTERY_LIPO_CAPACITY 5000
|
|
||||||
#endif
|
|
||||||
#ifndef USERMOD_BATTERY_LIPO_CALIBRATION
|
#ifndef USERMOD_BATTERY_LIPO_CALIBRATION
|
||||||
#define USERMOD_BATTERY_LIPO_CALIBRATION 0
|
#define USERMOD_BATTERY_LIPO_CALIBRATION 0
|
||||||
#endif
|
#endif
|
||||||
@ -77,10 +71,6 @@
|
|||||||
#ifndef USERMOD_BATTERY_LION_MAX_VOLTAGE
|
#ifndef USERMOD_BATTERY_LION_MAX_VOLTAGE
|
||||||
#define USERMOD_BATTERY_LION_MAX_VOLTAGE 4.2f
|
#define USERMOD_BATTERY_LION_MAX_VOLTAGE 4.2f
|
||||||
#endif
|
#endif
|
||||||
#ifndef USERMOD_BATTERY_LION_CAPACITY
|
|
||||||
// a common capacity for single 18650 battery cells is between 2500 and 3600 mAh
|
|
||||||
#define USERMOD_BATTERY_LION_CAPACITY 3100
|
|
||||||
#endif
|
|
||||||
#ifndef USERMOD_BATTERY_LION_CALIBRATION
|
#ifndef USERMOD_BATTERY_LION_CALIBRATION
|
||||||
// offset or calibration value to fine tune the calculated voltage
|
// offset or calibration value to fine tune the calculated voltage
|
||||||
#define USERMOD_BATTERY_LION_CALIBRATION 0
|
#define USERMOD_BATTERY_LION_CALIBRATION 0
|
||||||
@ -109,11 +99,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
|
||||||
@ -157,6 +142,7 @@ typedef struct bconfig_t
|
|||||||
float voltage; // current voltage
|
float voltage; // current voltage
|
||||||
int8_t level; // current level
|
int8_t level; // current level
|
||||||
float calibration; // offset or calibration value to fine tune the calculated voltage
|
float calibration; // offset or calibration value to fine tune the calculated voltage
|
||||||
|
float voltageMultiplier;
|
||||||
} batteryConfig;
|
} batteryConfig;
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
#ifndef UMBLion_h
|
#ifndef UMBLion_h
|
||||||
#define UMBLion_h
|
#define UMBLion_h
|
||||||
|
|
||||||
#include "battery_defaults.h"
|
#include "../battery_defaults.h"
|
||||||
#include "battery.h"
|
#include "../battery.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Lion Battery
|
* Lion Battery
|
||||||
@ -17,7 +17,6 @@ class Lion : public Battery
|
|||||||
{
|
{
|
||||||
this->setMinVoltage(USERMOD_BATTERY_LION_MIN_VOLTAGE);
|
this->setMinVoltage(USERMOD_BATTERY_LION_MIN_VOLTAGE);
|
||||||
this->setMaxVoltage(USERMOD_BATTERY_LION_MAX_VOLTAGE);
|
this->setMaxVoltage(USERMOD_BATTERY_LION_MAX_VOLTAGE);
|
||||||
this->setCapacity(USERMOD_BATTERY_LION_CAPACITY);
|
|
||||||
this->setVoltage(this->getVoltage());
|
this->setVoltage(this->getVoltage());
|
||||||
this->setCalibration(USERMOD_BATTERY_LION_CALIBRATION);
|
this->setCalibration(USERMOD_BATTERY_LION_CALIBRATION);
|
||||||
}
|
}
|
||||||
@ -26,7 +25,6 @@ class Lion : public Battery
|
|||||||
{
|
{
|
||||||
if(cfg.minVoltage) this->setMinVoltage(cfg.minVoltage);
|
if(cfg.minVoltage) this->setMinVoltage(cfg.minVoltage);
|
||||||
if(cfg.maxVoltage) this->setMaxVoltage(cfg.maxVoltage);
|
if(cfg.maxVoltage) this->setMaxVoltage(cfg.maxVoltage);
|
||||||
if(cfg.calibration) this->setCapacity(cfg.calibration);
|
|
||||||
if(cfg.level) this->setLevel(cfg.level);
|
if(cfg.level) this->setLevel(cfg.level);
|
||||||
if(cfg.calibration) this->setCalibration(cfg.calibration);
|
if(cfg.calibration) this->setCalibration(cfg.calibration);
|
||||||
}
|
}
|
@ -1,8 +1,8 @@
|
|||||||
#ifndef UMBLipo_h
|
#ifndef UMBLipo_h
|
||||||
#define UMBLipo_h
|
#define UMBLipo_h
|
||||||
|
|
||||||
#include "battery_defaults.h"
|
#include "../battery_defaults.h"
|
||||||
#include "battery.h"
|
#include "../battery.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Lipo Battery
|
* Lipo Battery
|
||||||
@ -17,7 +17,6 @@ class Lipo : public Battery
|
|||||||
{
|
{
|
||||||
this->setMinVoltage(USERMOD_BATTERY_LIPO_MIN_VOLTAGE);
|
this->setMinVoltage(USERMOD_BATTERY_LIPO_MIN_VOLTAGE);
|
||||||
this->setMaxVoltage(USERMOD_BATTERY_LIPO_MAX_VOLTAGE);
|
this->setMaxVoltage(USERMOD_BATTERY_LIPO_MAX_VOLTAGE);
|
||||||
this->setCapacity(USERMOD_BATTERY_LIPO_CAPACITY);
|
|
||||||
this->setVoltage(this->getVoltage());
|
this->setVoltage(this->getVoltage());
|
||||||
this->setCalibration(USERMOD_BATTERY_LIPO_CALIBRATION);
|
this->setCalibration(USERMOD_BATTERY_LIPO_CALIBRATION);
|
||||||
}
|
}
|
||||||
@ -26,13 +25,12 @@ class Lipo : public Battery
|
|||||||
{
|
{
|
||||||
if(cfg.minVoltage) this->setMinVoltage(cfg.minVoltage);
|
if(cfg.minVoltage) this->setMinVoltage(cfg.minVoltage);
|
||||||
if(cfg.maxVoltage) this->setMaxVoltage(cfg.maxVoltage);
|
if(cfg.maxVoltage) this->setMaxVoltage(cfg.maxVoltage);
|
||||||
if(cfg.calibration) this->setCapacity(cfg.calibration);
|
|
||||||
if(cfg.level) this->setLevel(cfg.level);
|
if(cfg.level) this->setLevel(cfg.level);
|
||||||
if(cfg.calibration) this->setCalibration(cfg.calibration);
|
if(cfg.calibration) this->setCalibration(cfg.calibration);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* LiPo batteries have a differnt dischargin curve, see
|
* LiPo batteries have a differnt discharge curve, see
|
||||||
* https://blog.ampow.com/lipo-voltage-chart/
|
* https://blog.ampow.com/lipo-voltage-chart/
|
||||||
*/
|
*/
|
||||||
float mapVoltage(float v, float min, float max) override
|
float mapVoltage(float v, float min, float max) override
|
||||||
@ -41,12 +39,12 @@ class Lipo : public Battery
|
|||||||
lvl = this->linearMapping(v, min, max); // basic mapping
|
lvl = this->linearMapping(v, min, max); // basic mapping
|
||||||
|
|
||||||
if (lvl < 40.0f)
|
if (lvl < 40.0f)
|
||||||
lvl = this->linearMapping(lvl, 0, 40, 0, 12); // last 45% -> drops very quickly
|
lvl = this->linearMapping(lvl, 0, 40, 0, 12); // last 45% -> drops very quickly
|
||||||
else {
|
else {
|
||||||
if (lvl < 90.0f)
|
if (lvl < 90.0f)
|
||||||
lvl = this->linearMapping(lvl, 40, 90, 12, 95); // 90% ... 40% -> almost linear drop
|
lvl = this->linearMapping(lvl, 40, 90, 12, 95); // 90% ... 40% -> almost linear drop
|
||||||
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;
|
return lvl;
|
@ -1,8 +1,8 @@
|
|||||||
#ifndef UMBUnkown_h
|
#ifndef UMBUnkown_h
|
||||||
#define UMBUnkown_h
|
#define UMBUnkown_h
|
||||||
|
|
||||||
#include "battery_defaults.h"
|
#include "../battery_defaults.h"
|
||||||
#include "battery.h"
|
#include "../battery.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Lion Battery
|
* Lion Battery
|
||||||
@ -17,7 +17,6 @@ class Unkown : public Battery
|
|||||||
{
|
{
|
||||||
this->setMinVoltage(USERMOD_BATTERY_UNKOWN_MIN_VOLTAGE);
|
this->setMinVoltage(USERMOD_BATTERY_UNKOWN_MIN_VOLTAGE);
|
||||||
this->setMaxVoltage(USERMOD_BATTERY_UNKOWN_MAX_VOLTAGE);
|
this->setMaxVoltage(USERMOD_BATTERY_UNKOWN_MAX_VOLTAGE);
|
||||||
this->setCapacity(USERMOD_BATTERY_UNKOWN_CAPACITY);
|
|
||||||
this->setVoltage(this->getVoltage());
|
this->setVoltage(this->getVoltage());
|
||||||
this->setCalibration(USERMOD_BATTERY_UNKOWN_CALIBRATION);
|
this->setCalibration(USERMOD_BATTERY_UNKOWN_CALIBRATION);
|
||||||
}
|
}
|
||||||
@ -26,7 +25,6 @@ class Unkown : public Battery
|
|||||||
{
|
{
|
||||||
if(cfg.minVoltage) this->setMinVoltage(cfg.minVoltage); else this->setMinVoltage(USERMOD_BATTERY_UNKOWN_MIN_VOLTAGE);
|
if(cfg.minVoltage) this->setMinVoltage(cfg.minVoltage); else this->setMinVoltage(USERMOD_BATTERY_UNKOWN_MIN_VOLTAGE);
|
||||||
if(cfg.maxVoltage) this->setMaxVoltage(cfg.maxVoltage); else this->setMaxVoltage(USERMOD_BATTERY_UNKOWN_MAX_VOLTAGE);
|
if(cfg.maxVoltage) this->setMaxVoltage(cfg.maxVoltage); else this->setMaxVoltage(USERMOD_BATTERY_UNKOWN_MAX_VOLTAGE);
|
||||||
if(cfg.calibration) this->setCapacity(cfg.calibration); else this->setCapacity(USERMOD_BATTERY_UNKOWN_CAPACITY);
|
|
||||||
if(cfg.calibration) this->setCalibration(cfg.calibration); else this->setCalibration(USERMOD_BATTERY_UNKOWN_CALIBRATION);
|
if(cfg.calibration) this->setCalibration(cfg.calibration); else this->setCalibration(USERMOD_BATTERY_UNKOWN_CALIBRATION);
|
||||||
}
|
}
|
||||||
|
|
@ -3,9 +3,9 @@
|
|||||||
#include "wled.h"
|
#include "wled.h"
|
||||||
#include "battery_defaults.h"
|
#include "battery_defaults.h"
|
||||||
#include "battery.h"
|
#include "battery.h"
|
||||||
#include "unkown.h"
|
#include "types/unkown.h"
|
||||||
#include "lion.h"
|
#include "types/lion.h"
|
||||||
#include "lipo.h"
|
#include "types/lipo.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Usermod by Maximilian Mewes
|
* Usermod by Maximilian Mewes
|
||||||
@ -28,7 +28,7 @@ class UsermodBattery : public Usermod
|
|||||||
unsigned long nextReadTime = 0;
|
unsigned long nextReadTime = 0;
|
||||||
unsigned long lastReadTime = 0;
|
unsigned long lastReadTime = 0;
|
||||||
// battery min. voltage
|
// battery min. voltage
|
||||||
float minBatteryVoltage = USERMOD_BATTERY_MIN_VOLTAGE;
|
float minBatteryVoltage = 3.3f;
|
||||||
// battery max. voltage
|
// battery max. voltage
|
||||||
float maxBatteryVoltage = USERMOD_BATTERY_MAX_VOLTAGE;
|
float maxBatteryVoltage = USERMOD_BATTERY_MAX_VOLTAGE;
|
||||||
// all battery cells summed up
|
// all battery cells summed up
|
||||||
@ -39,17 +39,11 @@ class UsermodBattery : public Usermod
|
|||||||
float voltage = maxBatteryVoltage;
|
float voltage = maxBatteryVoltage;
|
||||||
// between 0 and 1, to control strength of voltage smoothing filter
|
// between 0 and 1, to control strength of voltage smoothing filter
|
||||||
float alpha = 0.05f;
|
float alpha = 0.05f;
|
||||||
// multiplier for the voltage divider that is in place between ADC pin and battery, default will be 2 but might be adapted to readout voltages over ~5v ESP32 or ~6.6v ESP8266
|
|
||||||
float voltageMultiplier = USERMOD_BATTERY_VOLTAGE_MULTIPLIER;
|
|
||||||
// mapped battery level based on voltage
|
// mapped battery level based on voltage
|
||||||
int8_t batteryLevel = 100;
|
int8_t batteryLevel = 100;
|
||||||
// offset or calibration value to fine tune the calculated voltage
|
// offset or calibration value to fine tune the calculated voltage
|
||||||
float calibration = USERMOD_BATTERY_CALIBRATION;
|
float calibration = USERMOD_BATTERY_CALIBRATION;
|
||||||
|
|
||||||
// time left estimation feature
|
|
||||||
// bool calculateTimeLeftEnabled = USERMOD_BATTERY_CALCULATE_TIME_LEFT_ENABLED;
|
|
||||||
// float estimatedTimeLeft = 0.0;
|
|
||||||
|
|
||||||
// auto shutdown/shutoff/master off feature
|
// auto shutdown/shutoff/master off feature
|
||||||
bool autoOffEnabled = USERMOD_BATTERY_AUTO_OFF_ENABLED;
|
bool autoOffEnabled = USERMOD_BATTERY_AUTO_OFF_ENABLED;
|
||||||
uint8_t autoOffThreshold = USERMOD_BATTERY_AUTO_OFF_THRESHOLD;
|
uint8_t autoOffThreshold = USERMOD_BATTERY_AUTO_OFF_THRESHOLD;
|
||||||
@ -114,18 +108,22 @@ class UsermodBattery : public Usermod
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
float readVoltage()
|
// float readVoltage()
|
||||||
{
|
// {
|
||||||
#ifdef ARDUINO_ARCH_ESP32
|
// #ifdef ARDUINO_ARCH_ESP32
|
||||||
// use calibrated millivolts analogread on esp32 (150 mV ~ 2450 mV default attentuation) and divide by 1000 to get from milivolts to volts and multiply by voltage multiplier and apply calibration value
|
// // use calibrated millivolts analogread on esp32 (150 mV ~ 2450 mV default attentuation) and divide by 1000 to get from milivolts to volts and multiply by voltage multiplier and apply calibration value
|
||||||
return (analogReadMilliVolts(batteryPin) / 1000.0f) * voltageMultiplier + calibration;
|
// return (analogReadMilliVolts(batteryPin) / 1000.0f) * voltageMultiplier + calibration;
|
||||||
#else
|
// #else
|
||||||
// use analog read on esp8266 ( 0V ~ 1V no attenuation options) and divide by ADC precision 1023 and multiply by voltage multiplier and apply calibration value
|
// // use analog read on esp8266 ( 0V ~ 1V no attenuation options) and divide by ADC precision 1023 and multiply by voltage multiplier and apply calibration value
|
||||||
return (analogRead(batteryPin) / 1023.0f) * voltageMultiplier + calibration;
|
// return (analogRead(batteryPin) / 1023.0f) * voltageMultiplier + calibration;
|
||||||
#endif
|
// #endif
|
||||||
}
|
// }
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
UsermodBattery()
|
||||||
|
{
|
||||||
|
bat = new Unkown();
|
||||||
|
}
|
||||||
//Functions called by WLED
|
//Functions called by WLED
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -152,14 +150,13 @@ class UsermodBattery : public Usermod
|
|||||||
}
|
}
|
||||||
#else //ESP8266 boards have only one analog input pin A0
|
#else //ESP8266 boards have only one analog input pin A0
|
||||||
pinMode(batteryPin, INPUT);
|
pinMode(batteryPin, INPUT);
|
||||||
voltage = readVoltage();
|
// voltage = readVoltage();
|
||||||
#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(bcfg.type == (batteryType)lipo) {
|
if(bcfg.type == (batteryType)lipo) {
|
||||||
bat = new Lipo();
|
bat = new Lipo();
|
||||||
} else
|
} else if(bcfg.type == (batteryType)lion) {
|
||||||
if(bcfg.type == (batteryType)lion) {
|
|
||||||
bat = new Lion();
|
bat = new Lion();
|
||||||
} else {
|
} else {
|
||||||
bat = new Unkown(); // nullObject pattern
|
bat = new Unkown(); // nullObject pattern
|
||||||
@ -218,14 +215,8 @@ class UsermodBattery : public Usermod
|
|||||||
// calculate the voltage
|
// calculate the voltage
|
||||||
voltage = ((rawValue / getAdcPrecision()) * bat->getMaxVoltage()) + bat->getCalibration();
|
voltage = ((rawValue / getAdcPrecision()) * bat->getMaxVoltage()) + bat->getCalibration();
|
||||||
#endif
|
#endif
|
||||||
// initializing = false;
|
// filter with exponential smoothing because ADC in esp32 is fluctuating too much for a good single readout
|
||||||
|
voltage = voltage + alpha * (rawValue - voltage);
|
||||||
// rawValue = readVoltage();
|
|
||||||
// // filter with exponential smoothing because ADC in esp32 is fluctuating too much for a good single readout
|
|
||||||
// voltage = voltage + alpha * (rawValue - voltage);
|
|
||||||
|
|
||||||
// check if voltage is within specified voltage range, allow 10% over/under voltage - removed cause this just makes it hard for people to troubleshoot as the voltage in the web gui will say invalid instead of displaying a voltage
|
|
||||||
//voltage = ((voltage < minBatteryVoltage * 0.85f) || (voltage > maxBatteryVoltage * 1.1f)) ? -1.0f : voltage;
|
|
||||||
|
|
||||||
bat->setVoltage(voltage);
|
bat->setVoltage(voltage);
|
||||||
// translate battery voltage into percentage
|
// translate battery voltage into percentage
|
||||||
@ -298,7 +289,6 @@ class UsermodBattery : public Usermod
|
|||||||
if(forJsonState) { battery[F("type")] = bcfg.type; } else {battery[F("type")] = (String)bcfg.type; } // has to be a String otherwise it won't get converted to a Dropdown
|
if(forJsonState) { battery[F("type")] = bcfg.type; } else {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("calibration")] = bat->getCalibration();
|
battery[F("calibration")] = bat->getCalibration();
|
||||||
battery[FPSTR(_readInterval)] = readingInterval;
|
battery[FPSTR(_readInterval)] = readingInterval;
|
||||||
|
|
||||||
@ -318,8 +308,8 @@ class UsermodBattery : public Usermod
|
|||||||
getJsonValue(battery[F("type")], bcfg.type);
|
getJsonValue(battery[F("type")], bcfg.type);
|
||||||
getJsonValue(battery[F("min-voltage")], bcfg.minVoltage);
|
getJsonValue(battery[F("min-voltage")], bcfg.minVoltage);
|
||||||
getJsonValue(battery[F("max-voltage")], bcfg.maxVoltage);
|
getJsonValue(battery[F("max-voltage")], bcfg.maxVoltage);
|
||||||
getJsonValue(battery[F("capacity")], bcfg.capacity);
|
|
||||||
getJsonValue(battery[F("calibration")], bcfg.calibration);
|
getJsonValue(battery[F("calibration")], bcfg.calibration);
|
||||||
|
|
||||||
setReadingInterval(battery[FPSTR(_readInterval)] | readingInterval);
|
setReadingInterval(battery[FPSTR(_readInterval)] | readingInterval);
|
||||||
|
|
||||||
JsonObject ao = battery[F("auto-off")];
|
JsonObject ao = battery[F("auto-off")];
|
||||||
@ -422,25 +412,17 @@ class UsermodBattery : public Usermod
|
|||||||
battery[F("pin")] = batteryPin;
|
battery[F("pin")] = batteryPin;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// battery[F("time-left")] = calculateTimeLeftEnabled;
|
|
||||||
battery[F("min-voltage")] = minBatteryVoltage;
|
|
||||||
battery[F("max-voltage")] = maxBatteryVoltage;
|
|
||||||
battery[F("capacity")] = totalBatteryCapacity;
|
|
||||||
battery[F("calibration")] = calibration;
|
|
||||||
battery[F("voltage-multiplier")] = voltageMultiplier;
|
|
||||||
battery[FPSTR(_readInterval)] = readingInterval;
|
|
||||||
|
|
||||||
addBatteryToJsonObject(battery, false);
|
addBatteryToJsonObject(battery, false);
|
||||||
|
|
||||||
// read voltage in case calibration or voltage multiplier changed to see immediate effect
|
// read voltage in case calibration or voltage multiplier changed to see immediate effect
|
||||||
voltage = readVoltage();
|
// voltage = readVoltage();
|
||||||
|
|
||||||
DEBUG_PRINTLN(F("Battery config saved."));
|
DEBUG_PRINTLN(F("Battery config saved."));
|
||||||
}
|
}
|
||||||
|
|
||||||
void appendConfigData()
|
void appendConfigData()
|
||||||
{
|
{
|
||||||
// Total: 501 Bytes
|
// Total: 462 Bytes
|
||||||
oappend(SET_F("td=addDropdown('Battery', 'type');")); // 35 Bytes
|
oappend(SET_F("td=addDropdown('Battery', 'type');")); // 35 Bytes
|
||||||
oappend(SET_F("addOption(td, 'Unkown', '0');")); // 30 Bytes
|
oappend(SET_F("addOption(td, 'Unkown', '0');")); // 30 Bytes
|
||||||
oappend(SET_F("addOption(td, 'LiPo', '1');")); // 28 Bytes
|
oappend(SET_F("addOption(td, 'LiPo', '1');")); // 28 Bytes
|
||||||
@ -448,7 +430,6 @@ class UsermodBattery : public Usermod
|
|||||||
oappend(SET_F("addInfo('Battery:type',1,'<small style=\"color:orange\">requires reboot</small>');")); // 81 Bytes
|
oappend(SET_F("addInfo('Battery:type',1,'<small style=\"color:orange\">requires reboot</small>');")); // 81 Bytes
|
||||||
oappend(SET_F("addInfo('Battery:min-voltage', 1, 'v');")); // 40 Bytes
|
oappend(SET_F("addInfo('Battery:min-voltage', 1, 'v');")); // 40 Bytes
|
||||||
oappend(SET_F("addInfo('Battery:max-voltage', 1, 'v');")); // 40 Bytes
|
oappend(SET_F("addInfo('Battery:max-voltage', 1, 'v');")); // 40 Bytes
|
||||||
oappend(SET_F("addInfo('Battery:capacity', 1, 'mAh');")); // 39 Bytes
|
|
||||||
oappend(SET_F("addInfo('Battery:interval', 1, 'ms');")); // 38 Bytes
|
oappend(SET_F("addInfo('Battery:interval', 1, 'ms');")); // 38 Bytes
|
||||||
oappend(SET_F("addInfo('Battery:auto-off:threshold', 1, '%');")); // 47 Bytes
|
oappend(SET_F("addInfo('Battery:auto-off:threshold', 1, '%');")); // 47 Bytes
|
||||||
oappend(SET_F("addInfo('Battery:indicator:threshold', 1, '%');")); // 48 Bytes
|
oappend(SET_F("addInfo('Battery:indicator:threshold', 1, '%');")); // 48 Bytes
|
||||||
@ -503,9 +484,7 @@ class UsermodBattery : public Usermod
|
|||||||
// calculateTimeLeftEnabled = battery[F("time-left")] | calculateTimeLeftEnabled;
|
// calculateTimeLeftEnabled = battery[F("time-left")] | calculateTimeLeftEnabled;
|
||||||
setMinBatteryVoltage(battery[F("min-voltage")] | minBatteryVoltage);
|
setMinBatteryVoltage(battery[F("min-voltage")] | minBatteryVoltage);
|
||||||
setMaxBatteryVoltage(battery[F("max-voltage")] | maxBatteryVoltage);
|
setMaxBatteryVoltage(battery[F("max-voltage")] | maxBatteryVoltage);
|
||||||
setTotalBatteryCapacity(battery[F("capacity")] | totalBatteryCapacity);
|
|
||||||
setCalibration(battery[F("calibration")] | calibration);
|
setCalibration(battery[F("calibration")] | calibration);
|
||||||
setVoltageMultiplier(battery[F("voltage-multiplier")] | voltageMultiplier);
|
|
||||||
setReadingInterval(battery[FPSTR(_readInterval)] | readingInterval);
|
setReadingInterval(battery[FPSTR(_readInterval)] | readingInterval);
|
||||||
|
|
||||||
getUsermodConfigFromJsonObject(battery);
|
getUsermodConfigFromJsonObject(battery);
|
||||||
@ -655,22 +634,6 @@ class UsermodBattery : public Usermod
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Get the capacity of all cells in parralel sumed up
|
|
||||||
* unit: mAh
|
|
||||||
*/
|
|
||||||
unsigned int getTotalBatteryCapacity()
|
|
||||||
{
|
|
||||||
return totalBatteryCapacity;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setTotalBatteryCapacity(unsigned int capacity)
|
|
||||||
{
|
|
||||||
totalBatteryCapacity = capacity;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Get the calculated voltage
|
* Get the calculated voltage
|
||||||
* formula: (adc pin value / adc precision * max voltage) + calibration
|
* formula: (adc pin value / adc precision * max voltage) + calibration
|
||||||
@ -707,24 +670,6 @@ class UsermodBattery : public Usermod
|
|||||||
calibration = offset;
|
calibration = offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Set the voltage multiplier value
|
|
||||||
* A multiplier that may need adjusting for different voltage divider setups
|
|
||||||
*/
|
|
||||||
void setVoltageMultiplier(float multiplier)
|
|
||||||
{
|
|
||||||
voltageMultiplier = multiplier;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Get the voltage multiplier value
|
|
||||||
* A multiplier that may need adjusting for different voltage divider setups
|
|
||||||
*/
|
|
||||||
float getVoltageMultiplier()
|
|
||||||
{
|
|
||||||
return voltageMultiplier;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Get auto-off feature enabled status
|
* Get auto-off feature enabled status
|
||||||
* is auto-off enabled, true/false
|
* is auto-off enabled, true/false
|
||||||
|
Loading…
x
Reference in New Issue
Block a user