Skip to content

Commit 1a6e0d5

Browse files
author
James Foster
authored
Revise Menu to show Commands (Open-Acidification#75)
Revise MainMenu to show commands.
1 parent 0d5c00b commit 1a6e0d5

File tree

10 files changed

+288
-143
lines changed

10 files changed

+288
-143
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
calibra

.github/actions/spelling/excludes.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ LICENSE
1313
.gitignore
1414
Makefile
1515
^other/*
16+
^docs/Menus.xlsx$

.github/actions/spelling/expect.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ elif
2828
emoji
2929
endif
3030
endl
31+
enum
3132
EVT
3233
EZO
3334
FONTFAMILY

GUI/TankController.py

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,8 @@
33
import datetime
44
import threading
55
import time
6-
7-
try:
8-
import libTC
9-
except ImportError:
10-
print('libTC not found!')
11-
exit()
12-
13-
try:
14-
import wx
15-
except ImportError:
16-
print('wxpython is not installed!')
17-
exit()
6+
import libTC
7+
import wx
188

199

2010
class TankController(wx.Frame):

GUI/libTC.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "Keypad_TC.h"
2222
#include "LiquidCrystal_TC.h"
2323
#include "Serial_TC.h"
24+
#include "TC_util.h"
2425
#include "TankControllerLib.h"
2526
#include "TempProbe_TC.h"
2627
#include "UIState.h"
@@ -30,6 +31,7 @@
3031

3132
namespace py = pybind11;
3233
char lcdLine[20];
34+
unsigned long msOffset = 0;
3335

3436
// function prototypes
3537
void loop();
@@ -118,7 +120,7 @@ bool led() {
118120
void loop() {
119121
unsigned long millisecondsSinceEpoch =
120122
std::chrono::system_clock::now().time_since_epoch() / std::chrono::milliseconds(1);
121-
int msBehind = millisecondsSinceEpoch - millis();
123+
int msBehind = millisecondsSinceEpoch - millis() + msOffset;
122124
if (msBehind) {
123125
delay(msBehind);
124126
}
@@ -138,7 +140,6 @@ void setTemperature(double value) {
138140
}
139141

140142
void setTime() {
141-
int timeDelta = 0;
142143
time_t rawtime;
143144
struct tm *timeinfo;
144145
time(&rawtime);
@@ -147,8 +148,7 @@ void setTime() {
147148
timeinfo->tm_min, timeinfo->tm_sec);
148149
unsigned long millisecondsSinceEpoch =
149150
std::chrono::system_clock::now().time_since_epoch() / std::chrono::milliseconds(1);
150-
timeDelta = millisecondsSinceEpoch - millis();
151-
delay(timeDelta);
151+
msOffset = millisecondsSinceEpoch - millis();
152152
now.setAsCurrent();
153153
}
154154

docs/Menus.xlsx

11 KB
Binary file not shown.

src/UIState/MainMenu.cpp

Lines changed: 189 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "MainMenu.h"
22

33
#include "CalibrationManagement.h"
4+
#include "Devices/PHProbe.h"
45
#include "Devices/TempProbe_TC.h"
56
#include "EnablePID.h"
67
#include "PHCalibration.h"
@@ -18,6 +19,33 @@
1819
#include "SetTime.h"
1920
#include "TemperatureCalibration.h"
2021

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+
2149
/**
2250
* Branch to other states to handle various menu options
2351
*/
@@ -29,58 +57,190 @@ void MainMenu::handleKey(char key) {
2957
case 'B': // Set Temperature set_point
3058
this->setNextState((UIState *)new SetTempSetPoint(tc));
3159
break;
32-
case 'C': // pH Calibration
33-
this->setNextState((UIState *)new PHCalibration(tc));
60+
case 'D': // Reset
61+
level1 = 0;
62+
level2 = -1;
3463
break;
35-
case 'D': // Calibration Management
36-
this->setNextState((UIState *)new CalibrationManagement(tc));
64+
case '2': // up
65+
up();
3766
break;
38-
case '#': // Set Tank ID
39-
this->setNextState((UIState *)new SetTankID(tc));
67+
case '4': // left
68+
left();
4069
break;
41-
case '*': // Set Google Sheet Interval
42-
this->setNextState((UIState *)new SetGoogleSheetInterval(tc));
70+
case '6': // right
71+
right();
4372
break;
44-
case '0': // See Device Uptime & Current Time
45-
this->setNextState((UIState *)new SeeDeviceUptime(tc));
73+
case '8': // down
74+
down();
4675
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));
49131
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));
52134
break;
53-
case '3': // See Tank ID and Log File Name
135+
case VIEW_LOG_FILE:
54136
this->setNextState((UIState *)new SeeTankID(tc));
55137
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:
57142
this->setNextState((UIState *)new SeePIDConstants(tc));
58143
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));
61146
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));
64149
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));
67155
break;
68-
case '8': // Enable PID
69-
this->setNextState((UIState *)new EnablePID(tc));
156+
case VIEW_VERSION:
157+
this->setNextState((UIState *)new SeeDeviceAddress(tc));
70158
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:
72176
this->setNextState((UIState *)new SetChillOrHeat(tc));
73177
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;
74205
default:
75-
returnToMainMenu();
76206
break;
77207
}
78208
}
79209

80210
// 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();
83213
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);
85224
LiquidCrystal_TC::instance()->writeLine(output, 1);
86225
}
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+
}

src/UIState/MainMenu.h

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,36 @@
1111
class TankControllerLib; // forward reference
1212
class MainMenu : public UIState {
1313
public:
14-
MainMenu(TankControllerLib* tc) : UIState(tc) {
15-
}
14+
enum ViewCommands {
15+
VIEW_TIME,
16+
VIEW_PID,
17+
VIEW_PH_SLOPE,
18+
VIEW_TANK_ID,
19+
VIEW_LOG_FILE,
20+
VIEW_GOOGLE_MINS,
21+
VIEW_IP_ADDRESS,
22+
VIEW_MAC_ADDRESS,
23+
VIEW_VERSION,
24+
VIEW_UPTIME,
25+
VIEW_COMMAND_COUNT
26+
};
27+
enum SetCommands {
28+
SET_PH,
29+
SET_TEMPERATURE,
30+
SET_CALIBRATION_1,
31+
SET_CALIBRATION_2,
32+
SET_CALIBRATION_CLEAR,
33+
SET_TEMP_CALIBRATION,
34+
SET_PID_AUTO_TUNE,
35+
SET_PID_MANUAL_TUNE,
36+
SET_PID_ON_OFF,
37+
SET_CHILL_OR_HEAT,
38+
SET_GOOGLE_MINS,
39+
SET_TIME,
40+
SET_TANK_ID,
41+
SET_COMMAND_COUNT
42+
};
43+
MainMenu(TankControllerLib* tc);
1644
void handleKey(char key);
1745
const char* name() {
1846
return "MainMenu";
@@ -24,4 +52,17 @@ class MainMenu : public UIState {
2452
return true;
2553
}
2654
void loop();
55+
56+
private:
57+
int level1 = 0;
58+
int level2 = -1;
59+
String viewMenus[VIEW_COMMAND_COUNT];
60+
String setMenus[SET_COMMAND_COUNT];
61+
void left();
62+
void right();
63+
void up();
64+
void down();
65+
void selectView();
66+
void selectSet();
67+
void idle();
2768
};

0 commit comments

Comments
 (0)