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;
|
||||
};
|
||||
+7
-3
@@ -1,7 +1,7 @@
|
||||
#include "valve.h"
|
||||
|
||||
Valve::Valve() {
|
||||
|
||||
Valve::Valve(uint8_t maxOpen) {
|
||||
this->maxOpen = maxOpen;
|
||||
}
|
||||
|
||||
void Valve::loop() {
|
||||
@@ -37,6 +37,10 @@ void Valve::open(uint8_t valveNumber, uint8_t minutes) {
|
||||
if (valveNumber >= this->valveCount)
|
||||
return;
|
||||
|
||||
if (this->getNumOfOpen() >= this->maxOpen) {
|
||||
return;
|
||||
}
|
||||
|
||||
this->valves[valveNumber].duration = minutes;
|
||||
this->valves[valveNumber].startTime = millis();
|
||||
this->setValve(valveNumber, true);
|
||||
@@ -60,7 +64,7 @@ void Valve::closeAll() {
|
||||
this->close(i);
|
||||
}
|
||||
|
||||
uint8_t Valve::getNumOfOpen() {
|
||||
uint8_t Valve::getNumOfOpen() const {
|
||||
uint8_t res = 0;
|
||||
for (uint8_t i = 0; i < this->valveCount; i++)
|
||||
if (this->valves[i].duration)
|
||||
|
||||
+4
-2
@@ -13,7 +13,7 @@ class Valve {
|
||||
uint32_t startTime;
|
||||
};
|
||||
|
||||
Valve();
|
||||
Valve(uint8_t maxOpen);
|
||||
|
||||
void loop();
|
||||
|
||||
@@ -24,7 +24,8 @@ class Valve {
|
||||
void close(uint8_t valveNumber);
|
||||
void closeAll();
|
||||
|
||||
uint8_t getNumOfOpen();
|
||||
uint8_t getNumOfOpen() const;
|
||||
uint8_t getMaxOpen() const { return this->maxOpen; }
|
||||
uint16_t getTimeLeft(uint8_t valveNumber);
|
||||
|
||||
private:
|
||||
@@ -33,6 +34,7 @@ class Valve {
|
||||
ShiftRegister* shiftRegister = nullptr;
|
||||
|
||||
ValveData valves[MAX_VALVES];
|
||||
uint8_t maxOpen;
|
||||
uint8_t valveCount = 0;
|
||||
uint16_t loopDelay = 1000;
|
||||
uint32_t loopLastMillis = 0;
|
||||
|
||||
Reference in New Issue
Block a user