add class Pump

This commit is contained in:
2023-02-14 10:40:11 +01:00
parent 345b7a84ef
commit 6109967939
2 changed files with 114 additions and 0 deletions
+65
View File
@@ -0,0 +1,65 @@
#include "pump.h"
Pump::Pump(uint8_t pumpPin, uint8_t pressurePin, uint8_t flowPin) {
this->pumpPin = pumpPin;
this->pressurePin = pressurePin;
this->flowPin = flowPin;
pinMode(this->pumpPin, OUTPUT);
pinMode(this->pressurePin, INPUT);
digitalWrite(this->pumpPin, LOW);
}
void Pump::loop() {
if (millis() - lastMillisLoop < this->delayLoopMs)
return;
this->lastMillisLoop = millis();
this->calculatePressure();
this->calculateFlow();
this->checkErrors();
}
bool Pump::switchPump(bool state) {
if (this->error != Error::None)
return false;
if (state)
this->pumpRunningStart = millis();
digitalWrite(this->pumpPin, state);
return true;
}
uint32_t Pump::getPumpRunningTime() {
if (pumpState)
return millis() - this->pumpRunningStart;
return 0;
}
void Pump::calculatePressure() {
uint16_t pressure;
uint16_t rawValue = analogRead(this->pressurePin);
if (rawValue < 104)
pressure = 0;
else if (rawValue > 922)
pressure = 550;
else
pressure = map(rawValue, 104, 922, 0, 550);
//TODO: wenn pumpe lange an und druck hoch dann aus
}
void Pump::calculateFlow() {
}
void Pump::checkErrors() {
if (this->error == Error::None)
return;
digitalWrite(this->pumpPin, LOW);
if (this->errorFunction)
this->errorFunction(this->error);
}