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);
|
||||
|
||||
+14
-7
@@ -9,6 +9,7 @@ class Pump {
|
||||
On = 1,
|
||||
Timer = 2,
|
||||
Standby = 3,
|
||||
clearErrorHelper = 99,
|
||||
Error = 100,
|
||||
OnStupid = 200
|
||||
};
|
||||
@@ -18,23 +19,27 @@ class Pump {
|
||||
void loop();
|
||||
|
||||
void activate(uint32_t duration = 0);
|
||||
void activateWithoutSecurity();
|
||||
void stop();
|
||||
void clearError();
|
||||
|
||||
uint16_t getPressure();
|
||||
uint32_t getRunningTime();
|
||||
uint16_t getFlow();
|
||||
uint8_t getStatus();
|
||||
uint16_t getPressure() const { return this->pressure; }
|
||||
uint32_t getRunningTime() const;
|
||||
uint32_t getRemainingTime() const;
|
||||
uint16_t getFlow() const { return this->flow; }
|
||||
uint8_t getStatus() const { return (uint8_t) this->state; }
|
||||
|
||||
State getState() { return this->state; }
|
||||
State getState() const { return this->state; }
|
||||
|
||||
private:
|
||||
static const uint8_t delayCheckSensor = 50;
|
||||
static const uint8_t delayCheckSensor = 100;
|
||||
static const uint8_t delayReadSensor = 33;
|
||||
static const uint16_t blinkTime = 1000;
|
||||
static const uint16_t maxPressure = 1000;
|
||||
static const uint16_t maxMaxPressureTime = 30000;
|
||||
|
||||
bool checkSensors();
|
||||
void readSensorValues();
|
||||
bool checkSensorsValues();
|
||||
void handlePins(bool state);
|
||||
void changeState(State state);
|
||||
void stateTimer();
|
||||
@@ -50,6 +55,7 @@ class Pump {
|
||||
uint8_t flowPin;
|
||||
uint8_t ledPin;
|
||||
|
||||
uint16_t delayTimer = 1000;
|
||||
uint16_t flow;
|
||||
uint16_t pressure;
|
||||
|
||||
@@ -57,5 +63,6 @@ class Pump {
|
||||
uint32_t duration;
|
||||
uint32_t lastMillisTimer = 0;
|
||||
uint32_t lastMillisCheckSensor = 0;
|
||||
uint32_t lastMillisReadSensor = 0;
|
||||
uint32_t maxPressureStart = 0;
|
||||
};
|
||||
Reference in New Issue
Block a user