|
@@ -76,11 +76,14 @@ static const char *state_names[] = {
|
76
|
76
|
stringify(init),
|
77
|
77
|
stringify(menu_a),
|
78
|
78
|
stringify(menu_b),
|
|
79
|
+ stringify(menu_c),
|
79
|
80
|
stringify(auto_mode_a),
|
80
|
81
|
stringify(auto_mode_b),
|
81
|
|
- stringify(auto_fert),
|
|
82
|
+ stringify(auto_fert_a),
|
|
83
|
+ stringify(auto_fert_b),
|
82
|
84
|
stringify(auto_fert_run),
|
83
|
85
|
stringify(auto_tank_run),
|
|
86
|
+ stringify(auto_stirr_run),
|
84
|
87
|
stringify(auto_plant),
|
85
|
88
|
stringify(auto_plant_run),
|
86
|
89
|
stringify(auto_done),
|
|
@@ -98,6 +101,11 @@ static const char *state_names[] = {
|
98
|
101
|
stringify(menu_valves_go),
|
99
|
102
|
stringify(menu_valves_run),
|
100
|
103
|
stringify(menu_valves_done),
|
|
104
|
+ stringify(menu_aux),
|
|
105
|
+ stringify(menu_aux_time),
|
|
106
|
+ stringify(menu_aux_go),
|
|
107
|
+ stringify(menu_aux_run),
|
|
108
|
+ stringify(menu_aux_done),
|
101
|
109
|
stringify(error)
|
102
|
110
|
};
|
103
|
111
|
|
|
@@ -134,7 +142,7 @@ void Statemachine::begin(void) {
|
134
|
142
|
void Statemachine::input(int n) {
|
135
|
143
|
if (state == init) {
|
136
|
144
|
switch_to(menu_a);
|
137
|
|
- } else if ((state == menu_a) || (state == menu_b)) {
|
|
145
|
+ } else if ((state == menu_a) || (state == menu_b) || (state == menu_c)) {
|
138
|
146
|
if (n == 1) {
|
139
|
147
|
switch_to(auto_mode_a);
|
140
|
148
|
} else if (n == 2) {
|
|
@@ -143,17 +151,19 @@ void Statemachine::input(int n) {
|
143
|
151
|
switch_to(menu_pumps);
|
144
|
152
|
} else if (n == 4) {
|
145
|
153
|
switch_to(menu_valves);
|
|
154
|
+ } else if (n == 5) {
|
|
155
|
+ switch_to(menu_aux);
|
146
|
156
|
} else if (n == -1) {
|
147
|
157
|
switch_to(init);
|
148
|
158
|
} else if (n == -2) {
|
149
|
|
- switch_to((state == menu_a) ? menu_b : menu_a);
|
|
159
|
+ switch_to((state == menu_a) ? menu_b : ((state == menu_b) ? menu_c : menu_a));
|
150
|
160
|
}
|
151
|
161
|
} else if (state == automation_mode) {
|
152
|
162
|
// TODO
|
153
|
163
|
switch_to(menu_a);
|
154
|
164
|
} else if ((state == auto_mode_a) || (state == auto_mode_b)) {
|
155
|
165
|
if (n == 1) {
|
156
|
|
- switch_to(auto_fert);
|
|
166
|
+ switch_to(auto_fert_a);
|
157
|
167
|
} else if (n == 2) {
|
158
|
168
|
selected_plants.clear();
|
159
|
169
|
switch_to(fillnwater_plant);
|
|
@@ -181,7 +191,7 @@ void Statemachine::input(int n) {
|
181
|
191
|
} else if (n == -2) {
|
182
|
192
|
switch_to((state == auto_mode_a) ? auto_mode_b : auto_mode_a);
|
183
|
193
|
}
|
184
|
|
- } else if (state == auto_fert) {
|
|
194
|
+ } else if ((state == auto_fert_a) || (state == auto_fert_b)) {
|
185
|
195
|
if ((n >= 1) && (n <= 3)) {
|
186
|
196
|
auto wl = plants.getWaterlevel();
|
187
|
197
|
if ((wl != Plants::full) && (wl != Plants::invalid)) {
|
|
@@ -198,17 +208,22 @@ void Statemachine::input(int n) {
|
198
|
208
|
state = auto_mode_a;
|
199
|
209
|
switch_to(error);
|
200
|
210
|
}
|
201
|
|
- } else if ((n == -1) || (n == -2)) {
|
|
211
|
+ } else if (n == 4) {
|
|
212
|
+ plants.startAux(0);
|
|
213
|
+ selected_id = 1;
|
|
214
|
+ selected_time = AUTO_STIRR_RUNTIME;
|
|
215
|
+ start_time = millis();
|
|
216
|
+ switch_to(auto_stirr_run);
|
|
217
|
+ } else if (n == -1) {
|
202
|
218
|
switch_to(auto_mode_a);
|
|
219
|
+ } else if (n == -2) {
|
|
220
|
+ switch_to((state == auto_fert_a) ? auto_fert_b : auto_fert_a);
|
203
|
221
|
}
|
204
|
|
- } else if (state == auto_fert_run) {
|
205
|
|
- plants.abort();
|
206
|
|
- stop_time = millis();
|
207
|
|
- switch_to(auto_done);
|
208
|
|
- } else if (state == auto_tank_run) {
|
209
|
|
- plants.abort();
|
210
|
|
- stop_time = millis();
|
211
|
|
- switch_to(auto_done);
|
|
222
|
+ } else if ((state == auto_fert_run) || (state == auto_tank_run)
|
|
223
|
+ || (state == auto_stirr_run)) {
|
|
224
|
+ plants.abort();
|
|
225
|
+ stop_time = millis();
|
|
226
|
+ switch_to(auto_done);
|
212
|
227
|
} else if (state == auto_plant) {
|
213
|
228
|
if (n == -1) {
|
214
|
229
|
if (db.hasDigits()) {
|
|
@@ -528,11 +543,82 @@ void Statemachine::input(int n) {
|
528
|
543
|
switch_to(menu_valves_time);
|
529
|
544
|
}
|
530
|
545
|
} else if (state == menu_valves_run) {
|
531
|
|
- plants.abort();
|
532
|
|
- stop_time = millis();
|
533
|
|
- switch_to(menu_valves_done);
|
|
546
|
+ plants.abort();
|
|
547
|
+ stop_time = millis();
|
|
548
|
+ switch_to(menu_valves_done);
|
534
|
549
|
} else if (state == menu_valves_done) {
|
535
|
550
|
switch_to(menu_b);
|
|
551
|
+ } else if (state == menu_aux) {
|
|
552
|
+ if (n == -1) {
|
|
553
|
+ if (db.hasDigits()) {
|
|
554
|
+ backspace();
|
|
555
|
+ db.removeDigit();
|
|
556
|
+ } else {
|
|
557
|
+ switch_to(menu_c);
|
|
558
|
+ }
|
|
559
|
+ } else if (n == -2) {
|
|
560
|
+ if (!db.hasDigits()) {
|
|
561
|
+ return;
|
|
562
|
+ }
|
|
563
|
+
|
|
564
|
+ selected_id = number_input();
|
|
565
|
+
|
|
566
|
+ if ((selected_id <= 0) || (selected_id > plants.countAux())) {
|
|
567
|
+ error_condition = "Invalid valve ID!";
|
|
568
|
+ switch_to(error);
|
|
569
|
+ } else {
|
|
570
|
+ switch_to(menu_aux_time);
|
|
571
|
+ }
|
|
572
|
+ } else {
|
|
573
|
+ if (db.spaceLeft()) {
|
|
574
|
+ db.addDigit(n);
|
|
575
|
+ } else {
|
|
576
|
+ backspace();
|
|
577
|
+ }
|
|
578
|
+ }
|
|
579
|
+ } else if (state == menu_aux_time) {
|
|
580
|
+ if (n == -1) {
|
|
581
|
+ if (db.hasDigits()) {
|
|
582
|
+ backspace();
|
|
583
|
+ db.removeDigit();
|
|
584
|
+ } else {
|
|
585
|
+ switch_to(menu_aux);
|
|
586
|
+ }
|
|
587
|
+ } else if (n == -2) {
|
|
588
|
+ if (!db.hasDigits()) {
|
|
589
|
+ return;
|
|
590
|
+ }
|
|
591
|
+
|
|
592
|
+ selected_time = number_input();
|
|
593
|
+
|
|
594
|
+ if ((selected_time <= 0) || (selected_time > MAX_AUX_RUNTIME)) {
|
|
595
|
+ error_condition = "Invalid time range!";
|
|
596
|
+ switch_to(error);
|
|
597
|
+ } else {
|
|
598
|
+ switch_to(menu_aux_go);
|
|
599
|
+ }
|
|
600
|
+ } else {
|
|
601
|
+ if (db.spaceLeft()) {
|
|
602
|
+ db.addDigit(n);
|
|
603
|
+ } else {
|
|
604
|
+ backspace();
|
|
605
|
+ }
|
|
606
|
+ }
|
|
607
|
+ } else if (state == menu_aux_go) {
|
|
608
|
+ if (n == -2) {
|
|
609
|
+ start_time = millis();
|
|
610
|
+ last_animation_time = start_time;
|
|
611
|
+ plants.startAux(selected_id - 1);
|
|
612
|
+ switch_to(menu_aux_run);
|
|
613
|
+ } else {
|
|
614
|
+ switch_to(menu_aux_time);
|
|
615
|
+ }
|
|
616
|
+ } else if (state == menu_aux_run) {
|
|
617
|
+ plants.abort();
|
|
618
|
+ stop_time = millis();
|
|
619
|
+ switch_to(menu_aux_done);
|
|
620
|
+ } else if (state == menu_aux_done) {
|
|
621
|
+ switch_to(menu_c);
|
536
|
622
|
} else if (state == error) {
|
537
|
623
|
if (old_state != error) {
|
538
|
624
|
switch_to(old_state);
|
|
@@ -557,13 +643,15 @@ uint32_t Statemachine::number_input(void) {
|
557
|
643
|
}
|
558
|
644
|
|
559
|
645
|
void Statemachine::act(void) {
|
560
|
|
- if ((state == menu_pumps_run) || (state == menu_valves_run)) {
|
|
646
|
+ if ((state == menu_pumps_run) || (state == menu_valves_run)
|
|
647
|
+ || (state == menu_aux_run)
|
|
648
|
+ || (state == auto_stirr_run)) {
|
561
|
649
|
unsigned long runtime = millis() - start_time;
|
562
|
650
|
if ((runtime / 1000UL) >= selected_time) {
|
563
|
651
|
// stop if timeout has been reached
|
564
|
652
|
plants.abort();
|
565
|
653
|
stop_time = millis();
|
566
|
|
- switch_to((state == menu_pumps_run) ? menu_pumps_done : menu_valves_done);
|
|
654
|
+ switch_to((state == menu_pumps_run) ? menu_pumps_done : ((state == menu_valves_run) ? menu_valves_done : ((state == menu_aux_run) ? menu_aux_done : auto_done)));
|
567
|
655
|
} else if ((millis() - last_animation_time) >= 500) {
|
568
|
656
|
// update animation if needed
|
569
|
657
|
last_animation_time = millis();
|
|
@@ -757,14 +845,17 @@ void Statemachine::act(void) {
|
757
|
845
|
}
|
758
|
846
|
}
|
759
|
847
|
|
760
|
|
- if ((state == menu_a) || (state == menu_b) || (state == automation_mode)
|
|
848
|
+ if ((state == menu_a) || (state == menu_b) || (state == menu_c)
|
|
849
|
+ || (state == automation_mode) || (state == auto_done)
|
761
|
850
|
|| (state == auto_mode_a) || (state == auto_mode_b)
|
762
|
|
- || (state == auto_fert) || (state == auto_done)
|
|
851
|
+ || (state == auto_fert_a) || (state == auto_fert_b)
|
763
|
852
|
|| (state == auto_plant) || (state == fillnwater_plant)
|
764
|
853
|
|| (state == menu_pumps) || (state == menu_pumps_time)
|
765
|
854
|
|| (state == menu_pumps_go) || (state == menu_pumps_done)
|
766
|
855
|
|| (state == menu_valves) || (state == menu_valves_time)
|
767
|
|
- || (state == menu_valves_go) || (state == menu_valves_done)) {
|
|
856
|
+ || (state == menu_valves_go) || (state == menu_valves_done)
|
|
857
|
+ || (state == menu_aux) || (state == menu_aux_time)
|
|
858
|
+ || (state == menu_aux_go) || (state == menu_aux_done)) {
|
768
|
859
|
unsigned long runtime = millis() - into_state_time;
|
769
|
860
|
if (runtime >= BACK_TO_IDLE_TIMEOUT) {
|
770
|
861
|
debug.print("Idle timeout reached in state ");
|
|
@@ -796,16 +887,22 @@ void Statemachine::switch_to(States s) {
|
796
|
887
|
"# Execute input num.",
|
797
|
888
|
-1);
|
798
|
889
|
} else if (s == menu_a) {
|
799
|
|
- print("----- Menu 1/2 -----",
|
|
890
|
+ print("----- Menu 1/3 -----",
|
800
|
891
|
"1: Manual Operation",
|
801
|
892
|
"2: Automation",
|
802
|
|
- "#: Go to page 2/2...",
|
|
893
|
+ "#: Go to page 2/3...",
|
803
|
894
|
-1);
|
804
|
895
|
} else if (s == menu_b) {
|
805
|
|
- print("----- Menu 2/2 -----",
|
|
896
|
+ print("----- Menu 2/3 -----",
|
806
|
897
|
"3: Fertilizer pumps",
|
807
|
898
|
"4: Outlet valves",
|
808
|
|
- "#: Go to page 1/2...",
|
|
899
|
+ "#: Go to page 3/3...",
|
|
900
|
+ -1);
|
|
901
|
+ } else if (s == menu_c) {
|
|
902
|
+ print("----- Menu 3/3 -----",
|
|
903
|
+ "5: Aux. Outputs",
|
|
904
|
+ "",
|
|
905
|
+ "#: Go to page 1/3...",
|
809
|
906
|
-1);
|
810
|
907
|
} else if (state == automation_mode) {
|
811
|
908
|
// TODO
|
|
@@ -826,11 +923,17 @@ void Statemachine::switch_to(States s) {
|
826
|
923
|
"4: Water a plant",
|
827
|
924
|
"#: Go to page 1/2...",
|
828
|
925
|
-1);
|
829
|
|
- } else if (s == auto_fert) {
|
830
|
|
- print("---- Fertilizer ----",
|
|
926
|
+ } else if (s == auto_fert_a) {
|
|
927
|
+ print("-- Fertilizer 1/2 --",
|
831
|
928
|
"1: Vegetation Phase",
|
832
|
929
|
"2: Bloom Phase",
|
833
|
|
- "3: Special",
|
|
930
|
+ "#: Go to page 2/2...",
|
|
931
|
+ -1);
|
|
932
|
+ } else if (s == auto_fert_b) {
|
|
933
|
+ print("-- Fertilizer 2/2 --",
|
|
934
|
+ "3: Special Fert.",
|
|
935
|
+ "4: Run Stirrer",
|
|
936
|
+ "#: Go to page 1/2...",
|
834
|
937
|
-1);
|
835
|
938
|
} else if (s == auto_fert_run) {
|
836
|
939
|
unsigned long runtime = millis() - start_time;
|
|
@@ -847,6 +950,21 @@ void Statemachine::switch_to(States s) {
|
847
|
950
|
b.c_str(),
|
848
|
951
|
"Hit any key to stop!",
|
849
|
952
|
-1);
|
|
953
|
+ } else if (s == auto_stirr_run) {
|
|
954
|
+ unsigned long runtime = millis() - start_time;
|
|
955
|
+ String a = String("Time: ") + String(runtime / 1000UL) + String("s / ") + String(selected_time) + String('s');
|
|
956
|
+
|
|
957
|
+ unsigned long anim = runtime * 20UL / (selected_time * 1000UL);
|
|
958
|
+ String b;
|
|
959
|
+ for (unsigned long i = 0; i < anim; i++) {
|
|
960
|
+ b += '#';
|
|
961
|
+ }
|
|
962
|
+
|
|
963
|
+ print("----- Stirring -----",
|
|
964
|
+ a.c_str(),
|
|
965
|
+ b.c_str(),
|
|
966
|
+ "Hit any key to stop!",
|
|
967
|
+ -1);
|
850
|
968
|
} else if ((s == auto_tank_run) || (s == fillnwater_tank_run)) {
|
851
|
969
|
unsigned long runtime = millis() - start_time;
|
852
|
970
|
String a = String("Time: ") + String(runtime / 1000UL) + String("s / ") + String(selected_time) + String('s');
|
|
@@ -1050,6 +1168,54 @@ void Statemachine::switch_to(States s) {
|
1050
|
1168
|
}
|
1051
|
1169
|
}
|
1052
|
1170
|
#endif // PLATFORM_ESP
|
|
1171
|
+ } else if (s == menu_aux) {
|
|
1172
|
+ String a = String("(Input 1 to ") + String(plants.countAux()) + String(")");
|
|
1173
|
+
|
|
1174
|
+ print("------- Aux. -------",
|
|
1175
|
+ "Please select aux.",
|
|
1176
|
+ a.c_str(),
|
|
1177
|
+ "Aux.: ",
|
|
1178
|
+ 3);
|
|
1179
|
+ } else if (s == menu_aux_time) {
|
|
1180
|
+ String header = String("------ Aux ") + String(selected_id) + String(" ------");
|
|
1181
|
+
|
|
1182
|
+ print(header.c_str(),
|
|
1183
|
+ "Please set runtime",
|
|
1184
|
+ "(Input in seconds)",
|
|
1185
|
+ "Runtime: ",
|
|
1186
|
+ 3);
|
|
1187
|
+ } else if (s == menu_aux_go) {
|
|
1188
|
+ String a = String("Aux No. ") + String(selected_id);
|
|
1189
|
+ String b = String("Runtime ") + String(selected_time) + String('s');
|
|
1190
|
+
|
|
1191
|
+ print("----- Confirm? -----",
|
|
1192
|
+ a.c_str(),
|
|
1193
|
+ b.c_str(),
|
|
1194
|
+ " # Confirm",
|
|
1195
|
+ -1);
|
|
1196
|
+ } else if (s == menu_aux_run) {
|
|
1197
|
+ unsigned long runtime = millis() - start_time;
|
|
1198
|
+ String a = String("Time: ") + String(runtime / 1000UL) + String("s / ") + String(selected_time) + String('s');
|
|
1199
|
+
|
|
1200
|
+ unsigned long anim = runtime * 20UL / (selected_time * 1000UL);
|
|
1201
|
+ String b;
|
|
1202
|
+ for (unsigned long i = 0; i <= anim; i++) {
|
|
1203
|
+ b += '#';
|
|
1204
|
+ }
|
|
1205
|
+
|
|
1206
|
+ print("----- Stirring -----",
|
|
1207
|
+ a.c_str(),
|
|
1208
|
+ b.c_str(),
|
|
1209
|
+ "Hit any key to stop!",
|
|
1210
|
+ -1);
|
|
1211
|
+ } else if (s == menu_aux_done) {
|
|
1212
|
+ String a = String("after ") + String((stop_time - start_time) / 1000UL) + String("s.");
|
|
1213
|
+
|
|
1214
|
+ print("------- Done -------",
|
|
1215
|
+ "Stirring finished",
|
|
1216
|
+ a.c_str(),
|
|
1217
|
+ "Hit any key for menu",
|
|
1218
|
+ -1);
|
1053
|
1219
|
} else if (s == error) {
|
1054
|
1220
|
print("------ Error! ------",
|
1055
|
1221
|
"There is a problem:",
|