make a lot of things better
This commit is contained in:
+25
-17
@@ -16,13 +16,14 @@ Pump::Pump(uint8_t pumpPin, uint8_t pressurePin, uint8_t flowPin, uint8_t ledPin
|
||||
}
|
||||
|
||||
void Pump::loop() {
|
||||
this->readSensorValues();
|
||||
switch (this->state) {
|
||||
case State::Off :
|
||||
break;
|
||||
|
||||
case State::On :
|
||||
this->timerStandby = false;
|
||||
this->checkSensors();
|
||||
this->checkSensorsValues();
|
||||
break;
|
||||
|
||||
case State::Timer :
|
||||
@@ -51,6 +52,10 @@ void Pump::activate(uint32_t duration) {
|
||||
}
|
||||
}
|
||||
|
||||
void Pump::activateWithoutSecurity() {
|
||||
this->changeState(State::OnStupid);
|
||||
}
|
||||
|
||||
void Pump::stop() {
|
||||
this->changeState(State::Off);
|
||||
}
|
||||
@@ -62,32 +67,35 @@ void Pump::clearError() {
|
||||
}
|
||||
}
|
||||
|
||||
uint16_t Pump::getPressure() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint32_t Pump::getRunningTime() {
|
||||
uint32_t Pump::getRunningTime() const {
|
||||
if (this->state == State::Off)
|
||||
return 0;
|
||||
|
||||
return (millis() - this->startTime) / 1000;
|
||||
}
|
||||
|
||||
uint16_t Pump::getFlow() {
|
||||
return 0;
|
||||
uint32_t Pump::getRemainingTime() const {
|
||||
if (this->state != State::Timer)
|
||||
return 0;
|
||||
return (this->duration * 60) - ((millis() - this->startTime) / 1000);
|
||||
}
|
||||
|
||||
uint8_t Pump::getStatus() {
|
||||
return (uint8_t) this->state;
|
||||
void Pump::readSensorValues() {
|
||||
if (millis() - this->lastMillisReadSensor < Pump::delayReadSensor)
|
||||
return;
|
||||
this->lastMillisReadSensor = millis();
|
||||
|
||||
|
||||
//TODO: read pressure
|
||||
this->pressure = 12;
|
||||
//TODO: read flow
|
||||
this->flow = 13;
|
||||
}
|
||||
|
||||
bool Pump::checkSensors() {
|
||||
bool Pump::checkSensorsValues() {
|
||||
if (millis() - this->lastMillisCheckSensor < Pump::delayCheckSensor)
|
||||
return true;
|
||||
this->lastMillisCheckSensor = millis();
|
||||
|
||||
//TODO: read pressure
|
||||
//TODO: read flow
|
||||
|
||||
if (this->flow) {
|
||||
return true;
|
||||
@@ -161,10 +169,10 @@ void Pump::changeState(State state) {
|
||||
}
|
||||
|
||||
void Pump::stateTimer() {
|
||||
if (!this->checkSensors())
|
||||
if (!this->checkSensorsValues())
|
||||
return;
|
||||
|
||||
if (millis() - this->lastMillisTimer < Pump::delayTimer)
|
||||
if (millis() - this->lastMillisTimer < this->delayTimer)
|
||||
return;
|
||||
this->lastMillisTimer = millis();
|
||||
|
||||
@@ -174,7 +182,7 @@ void Pump::stateTimer() {
|
||||
}
|
||||
|
||||
void Pump::stateStandby() {
|
||||
this->checkSensors();
|
||||
this->checkSensorsValues();
|
||||
if (this->pressure < Pump::maxPressure / 2) {
|
||||
if (this->timerStandby)
|
||||
this->changeState(State::Timer);
|
||||
|
||||
Reference in New Issue
Block a user