-
Notifications
You must be signed in to change notification settings - Fork 0
/
WaterManager.h
93 lines (84 loc) · 2.72 KB
/
WaterManager.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#ifndef VALVE_MANAGER_H
#define VALVE_MANAGER_H
#include "Arduino.h"
#include "DurationFsm.h"
#include "WaterMeter.h"
#include "ValveManager.h"
#include "LedState.h"
#include "Constants.h"
#define PIPE_FILLING_TIME_MS 11000
// free flow around 68 per second
#define DEFAULT_WATER_METER_STOP_THRESHOLD 68U
class WaterManager: public Runnable {
public:
WaterManager();
~WaterManager();
/**
Switch to next mode. Called when the mode button is pressed.
*/
void modeClicked();
/**
Start automatic watering with first one second on as warning.
If mode is set to modeOffOnce, it is switched back to modeAutomatic.
*/
void startAutomaticRtc();
/**
Start automatic watering without warning second.
This is done on button press.
*/
void startAutomatic();
/**
Set and store the duration the given zone will be on persistently.
@param zone number of the zone to be set, 1, 2 or 3
@param durationSec duration in seconds how long the zone will be watered on every automatic run
*/
void setZoneDuration(byte zone, unsigned int durationSec);
/**
Set the amount of water meter ticks to stop watering if it is reached or exeeded.
*/
void setWaterMeterStopThreshold(int ticksPerSecond);
/**
return the total ticks count of the water meter since system started.
*/
unsigned long getUsedWater();
void printStatus();
/**
Do not call from external, used internally only.
*/
void run();
private:
void initModeFsm();
ValveManager *valveManager;
WaterMeter *waterMeter;
unsigned int stoppedByThreshold;
// ModeFsm
DurationState *modeOff;
DurationState *modeAutomatic;
DurationState *modeOffOnce;
DurationFsm *modeFsm;
// leak check callback
Runnable * const leakCheckListener = new LeakCheckListener(*this);
class LeakCheckListener: public Runnable {
public:
LeakCheckListener(WaterManager &waterManager): waterManager(waterManager) {}
void run() {
waterManager.leakCheckListenerCallback();
}
private:
WaterManager &waterManager;
};
void leakCheckListenerCallback();
// sensor check callback
MeasureStateListener * const waterMeterCheckListener = new WaterMeterCheckListener(*this);
class WaterMeterCheckListener: public MeasureStateListener {
public:
WaterMeterCheckListener(WaterManager &waterManager): waterManager(waterManager) {}
virtual void measuredResult(unsigned int tickCount) {
waterManager.waterMeterCheckCallback(tickCount);
}
private:
WaterManager &waterManager;
};
void waterMeterCheckCallback(unsigned int tickCount);
};
#endif