- battery calc now more efficent
- new battery values now every 0.5s
This commit is contained in:
@@ -15,6 +15,7 @@ Battery::Battery(uint8_t pin, uint32_t r1, uint32_t r2) {
|
||||
this->pin = pin;
|
||||
this->r1 = r1;
|
||||
this->r2 = r2;
|
||||
this->batteryVoltageFactor = (double) (this->r1 + this->r2)) / (double) this->r2
|
||||
this->initBuffer();
|
||||
this->loopDelay = 100;
|
||||
}
|
||||
@@ -71,7 +72,7 @@ double Battery::calculateInputVoltage() {
|
||||
|
||||
void Battery::calculateBatteryVoltage() {
|
||||
if (this->r1 && this->r2) {
|
||||
this->batteryVoltage = (this->calculateInputVoltage() * (double) (this->r1 + this->r2)) / (double) this->r2;
|
||||
this->batteryVoltage = (this->calculateInputVoltage() * this->batteryVoltageFactor;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -88,13 +88,14 @@ class Battery : public Component {
|
||||
uint8_t batteryPercent = 0;
|
||||
uint8_t batteryLowPercent = 10;
|
||||
uint8_t bufferPos = 0;
|
||||
uint8_t calulationDelayMultiplier = 10;
|
||||
uint8_t calulationDelayMultiplier = 5;
|
||||
uint8_t loopCounter = 0;
|
||||
uint16_t adcBuffer[bufferSize];
|
||||
uint32_t r1 = 0;
|
||||
uint32_t r2 = 0;
|
||||
bool calculatetNewValues = false;
|
||||
double batteryVoltage = 0;
|
||||
double batteryVoltageFactor;
|
||||
|
||||
const float capacityVoltages[21] = {9.82, 10.83, 11.06, 11.12, // 0 5 10 15
|
||||
11.18, 11.24, 11.3, 11.36, // 20 25 30 35
|
||||
|
||||
Reference in New Issue
Block a user