1
1
#include " MainMenu.h"
2
2
3
3
#include " CalibrationManagement.h"
4
+ #include " Devices/PHProbe.h"
4
5
#include " Devices/TempProbe_TC.h"
5
6
#include " EnablePID.h"
6
7
#include " PHCalibration.h"
18
19
#include " SetTime.h"
19
20
#include " TemperatureCalibration.h"
20
21
22
+ MainMenu::MainMenu (TankControllerLib *tc) : UIState(tc) {
23
+ viewMenus[VIEW_GOOGLE_MINS] = String (" View Google mins" );
24
+ viewMenus[VIEW_IP_ADDRESS] = String (" View IP address " );
25
+ viewMenus[VIEW_LOG_FILE] = String (" View log file " );
26
+ viewMenus[VIEW_MAC_ADDRESS] = String (" View MAC address" );
27
+ viewMenus[VIEW_PID] = String (" View PID " );
28
+ viewMenus[VIEW_PH_SLOPE] = String (" View pH slope " );
29
+ viewMenus[VIEW_TANK_ID] = String (" View tank ID " );
30
+ viewMenus[VIEW_TIME] = String (" View time " );
31
+ viewMenus[VIEW_UPTIME] = String (" View uptime " );
32
+ viewMenus[VIEW_VERSION] = String (" View version " );
33
+
34
+ setMenus[SET_CALIBRATION_1] = String (" 1pt pH calibrate" );
35
+ setMenus[SET_CALIBRATION_2] = String (" 2pt pH calibrate" );
36
+ setMenus[SET_CALIBRATION_CLEAR] = String (" Clear pH calibra" );
37
+ setMenus[SET_CHILL_OR_HEAT] = String (" Set chill/heat " );
38
+ setMenus[SET_GOOGLE_MINS] = String (" Set Google mins " );
39
+ setMenus[SET_PH] = String (" Set pH target " );
40
+ setMenus[SET_PID_AUTO_TUNE] = String (" PID auto-tune " );
41
+ setMenus[SET_PID_MANUAL_TUNE] = String (" PID manual tune " );
42
+ setMenus[SET_PID_ON_OFF] = String (" PID on/off " );
43
+ setMenus[SET_TANK_ID] = String (" Set Tank ID " );
44
+ setMenus[SET_TEMP_CALIBRATION] = String (" Temp calibration" );
45
+ setMenus[SET_TEMPERATURE] = String (" Set temperature " );
46
+ setMenus[SET_TIME] = String (" Set date/time " );
47
+ }
48
+
21
49
/* *
22
50
* Branch to other states to handle various menu options
23
51
*/
@@ -29,58 +57,190 @@ void MainMenu::handleKey(char key) {
29
57
case ' B' : // Set Temperature set_point
30
58
this ->setNextState ((UIState *)new SetTempSetPoint (tc));
31
59
break ;
32
- case ' C' : // pH Calibration
33
- this ->setNextState ((UIState *)new PHCalibration (tc));
60
+ case ' D' : // Reset
61
+ level1 = 0 ;
62
+ level2 = -1 ;
34
63
break ;
35
- case ' D ' : // Calibration Management
36
- this -> setNextState ((UIState *) new CalibrationManagement (tc) );
64
+ case ' 2 ' : // up
65
+ up ( );
37
66
break ;
38
- case ' # ' : // Set Tank ID
39
- this -> setNextState ((UIState *) new SetTankID (tc) );
67
+ case ' 4 ' : // left
68
+ left ( );
40
69
break ;
41
- case ' * ' : // Set Google Sheet Interval
42
- this -> setNextState ((UIState *) new SetGoogleSheetInterval (tc) );
70
+ case ' 6 ' : // right
71
+ right ( );
43
72
break ;
44
- case ' 0 ' : // See Device Uptime & Current Time
45
- this -> setNextState ((UIState *) new SeeDeviceUptime (tc) );
73
+ case ' 8 ' : // down
74
+ down ( );
46
75
break ;
47
- case ' 1' : // See Device addresses
48
- this ->setNextState ((UIState *)new SeeDeviceAddress (tc));
76
+ default :
77
+ // ignore invalid keys
78
+ break ;
79
+ }
80
+ }
81
+
82
+ void MainMenu::left () {
83
+ if (level2 == -1 ) {
84
+ level1 = 0 ;
85
+ } else {
86
+ level2 = -1 ;
87
+ }
88
+ }
89
+
90
+ void MainMenu::right () {
91
+ if (level1 == 0 ) {
92
+ level1 = 1 ;
93
+ level2 = -1 ;
94
+ } else if (level2 == -1 ) {
95
+ level2 = 0 ;
96
+ } else if (level1 == 1 ) {
97
+ selectView ();
98
+ } else {
99
+ selectSet ();
100
+ }
101
+ }
102
+
103
+ void MainMenu::up () {
104
+ if (level2 == -1 ) {
105
+ level1 = (level1 + 2 ) % 3 ;
106
+ } else {
107
+ if (level1 == 1 ) {
108
+ level2 = (level2 + VIEW_COMMAND_COUNT - 1 ) % VIEW_COMMAND_COUNT;
109
+ } else {
110
+ level2 = (level2 + SET_COMMAND_COUNT - 1 ) % SET_COMMAND_COUNT;
111
+ }
112
+ }
113
+ }
114
+
115
+ void MainMenu::down () {
116
+ if (level2 == -1 ) {
117
+ level1 = (level1 + 1 ) % 3 ;
118
+ } else {
119
+ if (level1 == 1 ) {
120
+ level2 = (level2 + 1 ) % VIEW_COMMAND_COUNT;
121
+ } else {
122
+ level2 = (level2 + 1 ) % SET_COMMAND_COUNT;
123
+ }
124
+ }
125
+ }
126
+
127
+ void MainMenu::selectView () {
128
+ switch (level2) {
129
+ case VIEW_GOOGLE_MINS:
130
+ this ->setNextState ((UIState *)new SeeTankID (tc));
49
131
break ;
50
- case ' 2 ' : // Reset LCD Screen
51
- this ->setNextState ((UIState *)new ResetLCDScreen (tc));
132
+ case VIEW_IP_ADDRESS:
133
+ this ->setNextState ((UIState *)new SeeDeviceAddress (tc));
52
134
break ;
53
- case ' 3 ' : // See Tank ID and Log File Name
135
+ case VIEW_LOG_FILE:
54
136
this ->setNextState ((UIState *)new SeeTankID (tc));
55
137
break ;
56
- case ' 4' : // See PID Constants
138
+ case VIEW_MAC_ADDRESS:
139
+ this ->setNextState ((UIState *)new SeeDeviceAddress (tc));
140
+ break ;
141
+ case VIEW_PID:
57
142
this ->setNextState ((UIState *)new SeePIDConstants (tc));
58
143
break ;
59
- case ' 5 ' : // PID Tuning
60
- this ->setNextState ((UIState *)new PIDTuningMenu (tc));
144
+ case VIEW_PH_SLOPE:
145
+ this ->setNextState ((UIState *)new SeePIDConstants (tc));
61
146
break ;
62
- case ' 6 ' : // Temperature Calibration
63
- this ->setNextState ((UIState *)new TemperatureCalibration (tc));
147
+ case VIEW_TANK_ID:
148
+ this ->setNextState ((UIState *)new SeeTankID (tc));
64
149
break ;
65
- case ' 7' : // Manual Set Time
66
- this ->setNextState ((UIState *)new SetTime (tc));
150
+ case VIEW_TIME:
151
+ this ->setNextState ((UIState *)new SeeDeviceUptime (tc));
152
+ break ;
153
+ case VIEW_UPTIME:
154
+ this ->setNextState ((UIState *)new SeeDeviceUptime (tc));
67
155
break ;
68
- case ' 8 ' : // Enable PID
69
- this ->setNextState ((UIState *)new EnablePID (tc));
156
+ case VIEW_VERSION:
157
+ this ->setNextState ((UIState *)new SeeDeviceAddress (tc));
70
158
break ;
71
- case ' 9' : // Set Chill or Heat
159
+ default :
160
+ break ;
161
+ }
162
+ }
163
+
164
+ void MainMenu::selectSet () {
165
+ switch (level2) {
166
+ case SET_CALIBRATION_1:
167
+ this ->setNextState ((UIState *)new PHCalibration (tc));
168
+ break ;
169
+ case SET_CALIBRATION_2:
170
+ this ->setNextState ((UIState *)new PHCalibration (tc));
171
+ break ;
172
+ case SET_CALIBRATION_CLEAR:
173
+ this ->setNextState ((UIState *)new PHCalibration (tc));
174
+ break ;
175
+ case SET_CHILL_OR_HEAT:
72
176
this ->setNextState ((UIState *)new SetChillOrHeat (tc));
73
177
break ;
178
+ case SET_GOOGLE_MINS:
179
+ this ->setNextState ((UIState *)new SetGoogleSheetInterval (tc));
180
+ break ;
181
+ case SET_PH:
182
+ this ->setNextState ((UIState *)new SetPHSetPoint (tc));
183
+ break ;
184
+ case SET_PID_AUTO_TUNE:
185
+ this ->setNextState ((UIState *)new PIDTuningMenu (tc));
186
+ break ;
187
+ case SET_PID_MANUAL_TUNE:
188
+ this ->setNextState ((UIState *)new PIDTuningMenu (tc));
189
+ break ;
190
+ case SET_PID_ON_OFF:
191
+ this ->setNextState ((UIState *)new PIDTuningMenu (tc));
192
+ break ;
193
+ case SET_TANK_ID:
194
+ this ->setNextState ((UIState *)new SetTankID (tc));
195
+ break ;
196
+ case SET_TEMP_CALIBRATION:
197
+ this ->setNextState ((UIState *)new TemperatureCalibration (tc));
198
+ break ;
199
+ case SET_TEMPERATURE:
200
+ this ->setNextState ((UIState *)new SetTempSetPoint (tc));
201
+ break ;
202
+ case SET_TIME:
203
+ this ->setNextState ((UIState *)new SetTime (tc));
204
+ break ;
74
205
default :
75
- returnToMainMenu ();
76
206
break ;
77
207
}
78
208
}
79
209
80
210
// show current temp and pH
81
- void MainMenu::loop () {
82
- TempProbe_TC *tempProbe = TempProbe_TC ::instance ();
211
+ void MainMenu::idle () {
212
+ PHProbe *pPHProbe = PHProbe ::instance ();
83
213
char output[17 ];
84
- sprintf (output, " Temp=%2.2f" , tempProbe->getRunningAverage ());
214
+ sprintf (output, " pH=%01.3f %1.3f" , pPHProbe->getPH (), 7.125 );
215
+ LiquidCrystal_TC::instance ()->writeLine (output, 0 );
216
+ TempProbe_TC *tempProbe = TempProbe_TC::instance ();
217
+ double temp = tempProbe->getRunningAverage ();
218
+ if (temp < 0.0 ) {
219
+ temp = 0.0 ;
220
+ } else if (99.99 < temp) {
221
+ temp = 99.99 ;
222
+ }
223
+ sprintf (output, " T=%02.2f %c %2.2f" , temp, ' C' , 12.25 );
85
224
LiquidCrystal_TC::instance ()->writeLine (output, 1 );
86
225
}
226
+
227
+ void MainMenu::loop () {
228
+ if (level1 == 0 ) {
229
+ idle ();
230
+ } else {
231
+ if (level1 == 1 ) {
232
+ if (level2 == -1 ) {
233
+ LiquidCrystal_TC::instance ()->writeLine (" View TC settings" , 0 );
234
+ } else {
235
+ LiquidCrystal_TC::instance ()->writeLine (viewMenus[level2].c_str (), 0 );
236
+ }
237
+ } else {
238
+ if (level2 == -1 ) {
239
+ LiquidCrystal_TC::instance ()->writeLine (" Change settings " , 0 );
240
+ } else {
241
+ LiquidCrystal_TC::instance ()->writeLine (setMenus[level2].c_str (), 0 );
242
+ }
243
+ }
244
+ LiquidCrystal_TC::instance ()->writeLine (" <4 ^2 8v 6>" , 1 );
245
+ }
246
+ }
0 commit comments