-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathWaterController.h
75 lines (61 loc) · 2.5 KB
/
WaterController.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/**
* IIRR -- Intelligent Irrigator Based on ESP8266
Copyright (C) 2016--2018 Sergio Queiroz <[email protected]>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef _WATERCONTROLLER_H
#define _WATERCONTROLLER_H
#include "TimeKeeper.h"
#include "ConfParams.h"
enum WaterStartStatus {
WATER_STARTOK = 0,
WATER_STARTNOACTION, //is already started
WATER_STARTEMPTY, //will not start because empty state was selected, may need resetEmpty first
WATER_STARTNOCONF //will not start because lacks configuration
};
enum WaterCurrSensorStatus {
WATER_CURRFLOWING,
WATER_CURRSTOP,
WATER_CURREMPTY, //empty means water block was detected, may need manual reset
WATER_CURRNOCONF //need to configure first to distinguish between flowing, empty and stop status
};
class WaterController {
public:
virtual WaterStartStatus startWater(bool ignoreNoConf = false) = 0;
virtual void stopWater() = 0;
virtual WaterCurrSensorStatus currStatus() = 0;
virtual void resetEmpty() = 0;
virtual bool configureFlow() = 0;
virtual ~WaterController() = 0;
};
inline WaterController::~WaterController() {}
class WellPumpWaterController : public WaterController {
public:
virtual WaterStartStatus startWater(bool ignoreNoConf = false) override;
virtual void stopWater() override;
virtual WaterCurrSensorStatus currStatus() override;
virtual void resetEmpty() override;
virtual bool configureFlow() override;
virtual ~WellPumpWaterController();
WellPumpWaterController();
inline void setDelayFunction(NTPClient::DelayHandlerFunction delayFunction) { this->delayHandler = delayFunction; }
private:
NTPClient::DelayHandlerFunction delayHandler = delay;
bool pumpIsOn;
inline bool noConfStatus() {return mainConfParams.normalPulsesPerSec > 0 ? false : true;}
bool emptyTriggered;
void turnOnSensor();
void turnOffSensor();
double avgSensorPulsesPerSec();
const double acceptedMinFlowPerc = 0.3;
};
#endif