-
Notifications
You must be signed in to change notification settings - Fork 0
/
gardener.cpp
111 lines (89 loc) · 2.11 KB
/
gardener.cpp
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/**
* Defines gardener controller.
*/
#include "gardener.h"
using namespace gardener;
using namespace std;
const int Gardener::waitSpeed = 0;
const int Gardener::waterSpeed = 100;
Gardener::Gardener(
IConfig &config,
IPump &pump,
ITimer &timer)
: config(config)
, pump(pump)
, timer(timer)
, currentState(IDLE)
{
}
void Gardener::transition(void)
{
switch (this->currentState)
{
case IDLE:
default:
this->currentState = START_WAIT;
break;
case START_WAIT:
this->currentState = WAIT;
break;
case WAIT:
if (this->timer.isExpired())
{
this->currentState = START_RAMP_UP;
}
break;
case START_RAMP_UP:
this->currentState = RAMP_UP;
break;
case RAMP_UP:
if (this->pump.isSpeedSteady())
{
this->currentState = START_WATER;
}
break;
case START_WATER:
this->currentState = WATER;
break;
case WATER:
if (this->timer.isExpired())
{
this->currentState = START_RAMP_DOWN;
}
break;
case START_RAMP_DOWN:
this->currentState = RAMP_DOWN;
break;
case RAMP_DOWN:
if (this->pump.isSpeedSteady())
{
this->currentState = START_WAIT;
}
break;
}
}
void Gardener::execute(void)
{
switch (this->currentState)
{
case START_WAIT:
this->timer.reload(this->config.getWaitTime());
break;
case START_RAMP_UP:
this->pump.requestChangeSpeed(100);
break;
case START_WATER:
this->timer.reload(this->config.getWaterTime());
break;
case START_RAMP_DOWN:
this->pump.requestChangeSpeed(0);
break;
case IDLE:
case WAIT:
case RAMP_UP:
case WATER:
case RAMP_DOWN:
default:
break;
}
}