refactore
all components now have a base class compnent for loop functions
This commit is contained in:
2023-08-18 10:47:35 +02:00
parent 25d37e3970
commit 11d21e2e89
35 changed files with 303 additions and 511 deletions
+14 -7
View File
@@ -16,28 +16,27 @@ Battery::Battery(uint8_t pin, uint32_t r1, uint32_t r2) {
this->r1 = r1;
this->r2 = r2;
this->initBuffer();
this->loopDelay = 100;
}
Battery::Battery(uint8_t pin) {
this->pin = pin;
this->initBuffer();
this->loopDelay = 100;
}
bool Battery::loop() {
if (millis() - this->lastMillis < this->delay)
return false;
void Battery::run() {
this->readAdcToBuf();
this->loopCounter++;
this->lastMillis = millis();
if (this->loopCounter == this->calulationDelayMultiplier) {
this->calculateBatteryVoltage();
this->calculateBatteryPercent();
return true;
this->loopCounter = 0;
this->calculatetNewValues = true;
}
return false;
return;
}
double Battery::getBatteryVoltage() {
@@ -51,6 +50,14 @@ bool Battery::isBatteryLow(double voltage) {
return false;
}
bool Battery::isNewValue() {
if (!this->calculatetNewValues)
return false;
this->calculatetNewValues = false;
return true;
}
double Battery::calculateInputVoltage() {
// Reference voltage is 3v3 so maximum reading is 3v3 = 4095 in range 0 to 4095
double reading = this->getBufAvg();