|
@@ -22,6 +22,7 @@
|
22
|
22
|
#include "WifiStuff.h"
|
23
|
23
|
#include "Statemachine.h"
|
24
|
24
|
#include "config.h"
|
|
25
|
+#include "config_pins.h"
|
25
|
26
|
|
26
|
27
|
Statemachine::DigitBuffer::DigitBuffer(int _size) {
|
27
|
28
|
size = _size;
|
|
@@ -74,6 +75,7 @@ uint32_t Statemachine::DigitBuffer::getNumber(void) {
|
74
|
75
|
|
75
|
76
|
static const char *state_names[] = {
|
76
|
77
|
stringify(init),
|
|
78
|
+ stringify(door_select),
|
77
|
79
|
stringify(menu_a),
|
78
|
80
|
stringify(menu_b),
|
79
|
81
|
stringify(menu_c),
|
|
@@ -142,7 +144,93 @@ void Statemachine::begin(void) {
|
142
|
144
|
|
143
|
145
|
void Statemachine::input(int n) {
|
144
|
146
|
if (state == init) {
|
|
147
|
+#if (LOCK_COUNT > 0) && defined(DOOR_LOCK_PIN)
|
|
148
|
+ if (n == -1) {
|
|
149
|
+ if (db.hasDigits()) {
|
|
150
|
+ backspace();
|
|
151
|
+ db.removeDigit();
|
|
152
|
+ if (menu_entered_digits.length() > 0) {
|
|
153
|
+ menu_entered_digits.remove(menu_entered_digits.length() - 1);
|
|
154
|
+ switch_to(state);
|
|
155
|
+ }
|
|
156
|
+ } else {
|
|
157
|
+ switch_to(menu_a);
|
|
158
|
+ }
|
|
159
|
+ } else if (n == -2) {
|
|
160
|
+ switch_to(menu_a);
|
|
161
|
+ } else {
|
|
162
|
+ if (db.spaceLeft()) {
|
|
163
|
+ db.addDigit(n);
|
|
164
|
+ //menu_entered_digits += String(n);
|
|
165
|
+ menu_entered_digits += String("*");
|
|
166
|
+ switch_to(state);
|
|
167
|
+ } else {
|
|
168
|
+ backspace();
|
|
169
|
+ }
|
|
170
|
+
|
|
171
|
+ uint32_t n = db.getNumber();
|
|
172
|
+ if (n == DOOR_LOCK_PIN) {
|
|
173
|
+ db.clear();
|
|
174
|
+ menu_entered_digits = "";
|
|
175
|
+ selected_plants.clear();
|
|
176
|
+ switch_to(door_select);
|
|
177
|
+ } else if (db.countDigits() >= DOOR_LOCK_PIN_MAX_DIGITS) {
|
|
178
|
+ db.clear();
|
|
179
|
+ menu_entered_digits = "";
|
|
180
|
+ switch_to(state);
|
|
181
|
+ }
|
|
182
|
+ }
|
|
183
|
+#else
|
145
|
184
|
switch_to(menu_a);
|
|
185
|
+#endif
|
|
186
|
+ } else if (state == door_select) {
|
|
187
|
+#if (LOCK_COUNT > 0)
|
|
188
|
+ if (n == -1) {
|
|
189
|
+ if (db.hasDigits()) {
|
|
190
|
+ backspace();
|
|
191
|
+ db.removeDigit();
|
|
192
|
+ if (menu_entered_digits.length() > 0) {
|
|
193
|
+ menu_entered_digits.remove(menu_entered_digits.length() - 1);
|
|
194
|
+ switch_to(state);
|
|
195
|
+ }
|
|
196
|
+ } else {
|
|
197
|
+ switch_to(init);
|
|
198
|
+ }
|
|
199
|
+ } else if (n == -2) {
|
|
200
|
+ if (!db.hasDigits()) {
|
|
201
|
+ for (int i = 0; i < LOCK_COUNT; i++) {
|
|
202
|
+ if (selected_plants.isSet(i)) {
|
|
203
|
+ plants.startAux(STIRRER_COUNT + i);
|
|
204
|
+ delay(DOOR_LOCK_ON_TIME);
|
|
205
|
+ plants.stopAux(STIRRER_COUNT + i);
|
|
206
|
+ }
|
|
207
|
+ }
|
|
208
|
+ plants.stopAllAux();
|
|
209
|
+ switch_to(menu_a);
|
|
210
|
+ } else {
|
|
211
|
+ selected_id = number_input();
|
|
212
|
+ if ((selected_id <= 0) || (selected_id > LOCK_COUNT)) {
|
|
213
|
+ error_condition = F("Invalid lock ID!");
|
|
214
|
+ switch_to(error);
|
|
215
|
+ } else {
|
|
216
|
+ selected_plants.set(selected_id - 1);
|
|
217
|
+ menu_entered_digits = "";
|
|
218
|
+ switch_to(state);
|
|
219
|
+ }
|
|
220
|
+ }
|
|
221
|
+ } else {
|
|
222
|
+ if (db.spaceLeft()) {
|
|
223
|
+ db.addDigit(n);
|
|
224
|
+ menu_entered_digits += String(n);
|
|
225
|
+ switch_to(state);
|
|
226
|
+ } else {
|
|
227
|
+ backspace();
|
|
228
|
+ }
|
|
229
|
+ }
|
|
230
|
+#else
|
|
231
|
+ // should never be reached
|
|
232
|
+ switch_to(menu_a);
|
|
233
|
+#endif
|
146
|
234
|
} else if ((state == menu_a) || (state == menu_b) || (state == menu_c)) {
|
147
|
235
|
if (n == 1) {
|
148
|
236
|
switch_to(auto_mode_a);
|
|
@@ -154,6 +242,10 @@ void Statemachine::input(int n) {
|
154
|
242
|
switch_to(menu_valves);
|
155
|
243
|
} else if (n == 5) {
|
156
|
244
|
switch_to(menu_aux);
|
|
245
|
+#if (LOCK_COUNT > 0) && !defined(DOOR_LOCK_PIN)
|
|
246
|
+ } else if (n == 6) {
|
|
247
|
+ switch_to(door_select);
|
|
248
|
+#endif
|
157
|
249
|
} else if (n == -1) {
|
158
|
250
|
switch_to(init);
|
159
|
251
|
} else if (n == -2) {
|
|
@@ -210,7 +302,9 @@ void Statemachine::input(int n) {
|
210
|
302
|
switch_to(error);
|
211
|
303
|
}
|
212
|
304
|
} else if (n == 4) {
|
213
|
|
- plants.startAux(0);
|
|
305
|
+ for (int i = 0; i < STIRRER_COUNT; i++) {
|
|
306
|
+ plants.startAux(i);
|
|
307
|
+ }
|
214
|
308
|
selected_id = 1;
|
215
|
309
|
selected_time = AUTO_STIRR_RUNTIME;
|
216
|
310
|
start_time = millis();
|
|
@@ -933,12 +1027,30 @@ void Statemachine::switch_to(States s) {
|
933
|
1027
|
|
934
|
1028
|
if (s == init) {
|
935
|
1029
|
String a = String(F("- Giess-o-mat V")) + FIRMWARE_VERSION + String(F(" -"));
|
936
|
|
-
|
|
1030
|
+
|
|
1031
|
+#if (LOCK_COUNT > 0) && defined(DOOR_LOCK_PIN)
|
|
1032
|
+ String b = String(F("PIN: ")) + menu_entered_digits;
|
|
1033
|
+ print(a.c_str(),
|
|
1034
|
+ "* or # to enter menu",
|
|
1035
|
+ "Enter PIN for locks:",
|
|
1036
|
+ b.c_str(),
|
|
1037
|
+ 3);
|
|
1038
|
+#else
|
937
|
1039
|
print(a.c_str(),
|
938
|
1040
|
"Usage: Enter number",
|
939
|
1041
|
"* Delete prev. digit",
|
940
|
1042
|
"# Execute input num.",
|
941
|
1043
|
-1);
|
|
1044
|
+#endif
|
|
1045
|
+ } else if (s == door_select) {
|
|
1046
|
+ String a = String("(Input 1 to ") + String(LOCK_COUNT) + String(")");
|
|
1047
|
+ String b = String(F("Door: ")) + menu_entered_digits;
|
|
1048
|
+
|
|
1049
|
+ print("- Select Door Lock -",
|
|
1050
|
+ "Leave empty if done!",
|
|
1051
|
+ a.c_str(),
|
|
1052
|
+ b.c_str(),
|
|
1053
|
+ 3);
|
942
|
1054
|
} else if (s == menu_a) {
|
943
|
1055
|
print("----- Menu 1/3 -----",
|
944
|
1056
|
"1: Manual Operation",
|
|
@@ -954,7 +1066,11 @@ void Statemachine::switch_to(States s) {
|
954
|
1066
|
} else if (s == menu_c) {
|
955
|
1067
|
print("----- Menu 3/3 -----",
|
956
|
1068
|
"5: Aux. Outputs",
|
|
1069
|
+#if (LOCK_COUNT > 0) && !defined(DOOR_LOCK_PIN)
|
|
1070
|
+ "6: Door Locks",
|
|
1071
|
+#else
|
957
|
1072
|
"",
|
|
1073
|
+#endif
|
958
|
1074
|
"#: Go to page 1/3...",
|
959
|
1075
|
-1);
|
960
|
1076
|
} else if (state == automation_mode) {
|
|
@@ -1037,7 +1153,6 @@ void Statemachine::switch_to(States s) {
|
1037
|
1153
|
String a = String("(Input 1 to ") + String(plants.countPlants()) + String(")");
|
1038
|
1154
|
String b = String(F("Plant: ")) + menu_entered_digits;
|
1039
|
1155
|
|
1040
|
|
-
|
1041
|
1156
|
print("--- Select Plant ---",
|
1042
|
1157
|
"Leave empty if done!",
|
1043
|
1158
|
a.c_str(),
|
|
@@ -1273,7 +1388,7 @@ void Statemachine::switch_to(States s) {
|
1273
|
1388
|
String a = String("after ") + String((stop_time - start_time) / 1000UL) + String("s.");
|
1274
|
1389
|
|
1275
|
1390
|
print("------- Done -------",
|
1276
|
|
- "Stirring finished",
|
|
1391
|
+ "Aux. run finished",
|
1277
|
1392
|
a.c_str(),
|
1278
|
1393
|
"Hit any key for menu",
|
1279
|
1394
|
-1);
|