|
@@ -38,6 +38,7 @@ bool doing_multi_input = false;
|
38
|
38
|
|
39
|
39
|
#include "Plants.h"
|
40
|
40
|
#include "Statemachine.h"
|
|
41
|
+#include "WifiStuff.h"
|
41
|
42
|
|
42
|
43
|
Plants plants(VALVE_COUNT, PUMP_COUNT, SWITCH_COUNT);
|
43
|
44
|
int valve_pins[VALVE_COUNT] = { VALVE_PINS };
|
|
@@ -50,6 +51,144 @@ Statemachine sm(write_to_all, backspace);
|
50
|
51
|
|
51
|
52
|
// ----------------------------------------------------------------------------
|
52
|
53
|
|
|
54
|
+void write_lcd_to_serial(const char *a, const char *b,
|
|
55
|
+ const char *c, const char *d) {
|
|
56
|
+#ifdef DEBUG_ENABLE_LCD_OUTPUT_ON_SERIAL
|
|
57
|
+ int la = strlen(a);
|
|
58
|
+ int lb = strlen(b);
|
|
59
|
+ int lc = strlen(c);
|
|
60
|
+ int ld = strlen(d);
|
|
61
|
+
|
|
62
|
+ Serial.println();
|
|
63
|
+ Serial.println(" ----------------------");
|
|
64
|
+
|
|
65
|
+ Serial.print("| ");
|
|
66
|
+ Serial.print(a);
|
|
67
|
+ if (la < 20) {
|
|
68
|
+ for (int i = 0; i < (20 - la); i++) {
|
|
69
|
+ Serial.print(' ');
|
|
70
|
+ }
|
|
71
|
+ }
|
|
72
|
+ Serial.println(" |");
|
|
73
|
+
|
|
74
|
+ Serial.print("| ");
|
|
75
|
+ Serial.print(b);
|
|
76
|
+ if (lb < 20) {
|
|
77
|
+ for (int i = 0; i < (20 - lb); i++) {
|
|
78
|
+ Serial.print(' ');
|
|
79
|
+ }
|
|
80
|
+ }
|
|
81
|
+ Serial.println(" |");
|
|
82
|
+
|
|
83
|
+ Serial.print("| ");
|
|
84
|
+ Serial.print(c);
|
|
85
|
+ if (lc < 20) {
|
|
86
|
+ for (int i = 0; i < (20 - lc); i++) {
|
|
87
|
+ Serial.print(' ');
|
|
88
|
+ }
|
|
89
|
+ }
|
|
90
|
+ Serial.println(" |");
|
|
91
|
+
|
|
92
|
+ Serial.print("| ");
|
|
93
|
+ Serial.print(d);
|
|
94
|
+ if (ld < 20) {
|
|
95
|
+ for (int i = 0; i < (20 - ld); i++) {
|
|
96
|
+ Serial.print(' ');
|
|
97
|
+ }
|
|
98
|
+ }
|
|
99
|
+ Serial.println(" |");
|
|
100
|
+
|
|
101
|
+ Serial.println(" ----------------------");
|
|
102
|
+ Serial.println("Please provide keypad input:");
|
|
103
|
+#endif // DEBUG_ENABLE_LCD_OUTPUT_ON_SERIAL
|
|
104
|
+}
|
|
105
|
+
|
|
106
|
+void handle_input(int n) {
|
|
107
|
+#ifdef FUNCTION_CONTROL
|
|
108
|
+
|
|
109
|
+ sm.input(n);
|
|
110
|
+
|
|
111
|
+#else
|
|
112
|
+
|
|
113
|
+ keybuffer.push(n);
|
|
114
|
+
|
|
115
|
+#endif // FUNCTION_CONTROL
|
|
116
|
+}
|
|
117
|
+
|
|
118
|
+void input_serial(void) {
|
|
119
|
+#ifdef DEBUG_ENABLE_KEYPAD_INPUT_ON_SERIAL
|
|
120
|
+ if (Serial.available() > 0) {
|
|
121
|
+
|
|
122
|
+#ifdef FUNCTION_UI
|
|
123
|
+ last_input_time = millis();
|
|
124
|
+ if (!backlight_state) {
|
|
125
|
+ backlight_state = true;
|
|
126
|
+ lcd.setBacklight(255);
|
|
127
|
+ }
|
|
128
|
+#endif // FUNCTION_UI
|
|
129
|
+
|
|
130
|
+ int c = Serial.read();
|
|
131
|
+ if (c == '*') {
|
|
132
|
+ Serial.write(c);
|
|
133
|
+ Serial.write('\n');
|
|
134
|
+
|
|
135
|
+#ifdef FUNCTION_UI
|
|
136
|
+ if (doing_multi_input) {
|
|
137
|
+ char s[2] = { (char)(c), '\0' };
|
|
138
|
+ lcd.write(s);
|
|
139
|
+ }
|
|
140
|
+#endif // FUNCTION_UI
|
|
141
|
+
|
|
142
|
+ handle_input(-1);
|
|
143
|
+ } else if (c == '#') {
|
|
144
|
+ Serial.write(c);
|
|
145
|
+ Serial.write('\n');
|
|
146
|
+
|
|
147
|
+#ifdef FUNCTION_UI
|
|
148
|
+ if (doing_multi_input) {
|
|
149
|
+ char s[2] = { (char)(c), '\0' };
|
|
150
|
+ lcd.write(s);
|
|
151
|
+ }
|
|
152
|
+#endif // FUNCTION_UI
|
|
153
|
+
|
|
154
|
+ handle_input(-2);
|
|
155
|
+ } else if (c == '\n') {
|
|
156
|
+ Serial.write('#');
|
|
157
|
+ Serial.write('\n');
|
|
158
|
+
|
|
159
|
+#ifdef FUNCTION_UI
|
|
160
|
+ if (doing_multi_input) {
|
|
161
|
+ char s[2] = { '#', '\0' };
|
|
162
|
+ lcd.write(s);
|
|
163
|
+ }
|
|
164
|
+#endif // FUNCTION_UI
|
|
165
|
+
|
|
166
|
+ handle_input(-2);
|
|
167
|
+ } else if (c == '\b') {
|
|
168
|
+ Serial.write(c);
|
|
169
|
+ handle_input(-1);
|
|
170
|
+ } else if ((c >= '0') && (c <= '9')) {
|
|
171
|
+ Serial.write(c);
|
|
172
|
+
|
|
173
|
+#ifdef FUNCTION_UI
|
|
174
|
+ if (!doing_multi_input) {
|
|
175
|
+ Serial.write('\n');
|
|
176
|
+ }
|
|
177
|
+
|
|
178
|
+ if (doing_multi_input) {
|
|
179
|
+ char s[2] = { (char)(c), '\0' };
|
|
180
|
+ lcd.write(s);
|
|
181
|
+ }
|
|
182
|
+#endif // FUNCTION_UI
|
|
183
|
+
|
|
184
|
+ handle_input(c - '0');
|
|
185
|
+ }
|
|
186
|
+ }
|
|
187
|
+#endif // DEBUG_ENABLE_KEYPAD_INPUT_ON_SERIAL
|
|
188
|
+}
|
|
189
|
+
|
|
190
|
+// ----------------------------------------------------------------------------
|
|
191
|
+
|
53
|
192
|
#ifdef FUNCTION_UI
|
54
|
193
|
|
55
|
194
|
#ifndef FUNCTION_CONTROL
|
|
@@ -176,18 +315,6 @@ void ui_setup(void) {
|
176
|
315
|
#endif // ! FUNCTION_CONTROL
|
177
|
316
|
}
|
178
|
317
|
|
179
|
|
-void handle_input(int n) {
|
180
|
|
-#ifdef FUNCTION_CONTROL
|
181
|
|
-
|
182
|
|
- sm.input(n);
|
183
|
|
-
|
184
|
|
-#else
|
185
|
|
-
|
186
|
|
- keybuffer.push(n);
|
187
|
|
-
|
188
|
|
-#endif // FUNCTION_CONTROL
|
189
|
|
-}
|
190
|
|
-
|
191
|
318
|
void input_keypad(void) {
|
192
|
319
|
keys.scan();
|
193
|
320
|
while (keys.hasEvent()) {
|
|
@@ -224,66 +351,6 @@ void input_keypad(void) {
|
224
|
351
|
}
|
225
|
352
|
}
|
226
|
353
|
|
227
|
|
-void input_serial(void) {
|
228
|
|
-#ifdef DEBUG_ENABLE_KEYPAD_INPUT_ON_SERIAL
|
229
|
|
- if (Serial.available() > 0) {
|
230
|
|
- last_input_time = millis();
|
231
|
|
- if (!backlight_state) {
|
232
|
|
- backlight_state = true;
|
233
|
|
- lcd.setBacklight(255);
|
234
|
|
- }
|
235
|
|
-
|
236
|
|
- int c = Serial.read();
|
237
|
|
- if (c == '*') {
|
238
|
|
- Serial.write(c);
|
239
|
|
- Serial.write('\n');
|
240
|
|
-
|
241
|
|
- if (doing_multi_input) {
|
242
|
|
- char s[2] = { (char)(c), '\0' };
|
243
|
|
- lcd.write(s);
|
244
|
|
- }
|
245
|
|
-
|
246
|
|
- handle_input(-1);
|
247
|
|
- } else if (c == '#') {
|
248
|
|
- Serial.write(c);
|
249
|
|
- Serial.write('\n');
|
250
|
|
-
|
251
|
|
- if (doing_multi_input) {
|
252
|
|
- char s[2] = { (char)(c), '\0' };
|
253
|
|
- lcd.write(s);
|
254
|
|
- }
|
255
|
|
-
|
256
|
|
- handle_input(-2);
|
257
|
|
- } else if (c == '\n') {
|
258
|
|
- Serial.write('#');
|
259
|
|
- Serial.write('\n');
|
260
|
|
-
|
261
|
|
- if (doing_multi_input) {
|
262
|
|
- char s[2] = { '#', '\0' };
|
263
|
|
- lcd.write(s);
|
264
|
|
- }
|
265
|
|
-
|
266
|
|
- handle_input(-2);
|
267
|
|
- } else if (c == '\b') {
|
268
|
|
- Serial.write(c);
|
269
|
|
- handle_input(-1);
|
270
|
|
- } else if ((c >= '0') && (c <= '9')) {
|
271
|
|
- Serial.write(c);
|
272
|
|
- if (!doing_multi_input) {
|
273
|
|
- Serial.write('\n');
|
274
|
|
- }
|
275
|
|
-
|
276
|
|
- if (doing_multi_input) {
|
277
|
|
- char s[2] = { (char)(c), '\0' };
|
278
|
|
- lcd.write(s);
|
279
|
|
- }
|
280
|
|
-
|
281
|
|
- handle_input(c - '0');
|
282
|
|
- }
|
283
|
|
- }
|
284
|
|
-#endif // DEBUG_ENABLE_KEYPAD_INPUT_ON_SERIAL
|
285
|
|
-}
|
286
|
|
-
|
287
|
354
|
void ui_run(void) {
|
288
|
355
|
input_keypad();
|
289
|
356
|
input_serial();
|
|
@@ -322,54 +389,7 @@ void write_to_all(const char *a, const char *b,
|
322
|
389
|
doing_multi_input = false;
|
323
|
390
|
}
|
324
|
391
|
|
325
|
|
-#ifdef DEBUG_ENABLE_LCD_OUTPUT_ON_SERIAL
|
326
|
|
- int la = strlen(a);
|
327
|
|
- int lb = strlen(b);
|
328
|
|
- int lc = strlen(c);
|
329
|
|
- int ld = strlen(d);
|
330
|
|
-
|
331
|
|
- Serial.println();
|
332
|
|
- Serial.println(" ----------------------");
|
333
|
|
-
|
334
|
|
- Serial.print("| ");
|
335
|
|
- Serial.print(a);
|
336
|
|
- if (la < 20) {
|
337
|
|
- for (int i = 0; i < (20 - la); i++) {
|
338
|
|
- Serial.print(' ');
|
339
|
|
- }
|
340
|
|
- }
|
341
|
|
- Serial.println(" |");
|
342
|
|
-
|
343
|
|
- Serial.print("| ");
|
344
|
|
- Serial.print(b);
|
345
|
|
- if (lb < 20) {
|
346
|
|
- for (int i = 0; i < (20 - lb); i++) {
|
347
|
|
- Serial.print(' ');
|
348
|
|
- }
|
349
|
|
- }
|
350
|
|
- Serial.println(" |");
|
351
|
|
-
|
352
|
|
- Serial.print("| ");
|
353
|
|
- Serial.print(c);
|
354
|
|
- if (lc < 20) {
|
355
|
|
- for (int i = 0; i < (20 - lc); i++) {
|
356
|
|
- Serial.print(' ');
|
357
|
|
- }
|
358
|
|
- }
|
359
|
|
- Serial.println(" |");
|
360
|
|
-
|
361
|
|
- Serial.print("| ");
|
362
|
|
- Serial.print(d);
|
363
|
|
- if (ld < 20) {
|
364
|
|
- for (int i = 0; i < (20 - ld); i++) {
|
365
|
|
- Serial.print(' ');
|
366
|
|
- }
|
367
|
|
- }
|
368
|
|
- Serial.println(" |");
|
369
|
|
-
|
370
|
|
- Serial.println(" ----------------------");
|
371
|
|
- Serial.println("Please provide keypad input:");
|
372
|
|
-#endif // DEBUG_ENABLE_LCD_OUTPUT_ON_SERIAL
|
|
392
|
+ write_lcd_to_serial(a, b, c, d);
|
373
|
393
|
}
|
374
|
394
|
|
375
|
395
|
void backspace(void) {
|
|
@@ -401,9 +421,11 @@ void control_setup(void) {
|
401
|
421
|
#ifndef FUNCTION_UI
|
402
|
422
|
|
403
|
423
|
Serial.println("Initializing I2C Master");
|
|
424
|
+ Wire.setClock(I2C_BUS_SPEED);
|
404
|
425
|
Wire.begin();
|
405
|
426
|
|
406
|
427
|
#ifdef DEBUG_WAIT_FOR_SERIAL_CONN
|
|
428
|
+ Serial.println("Wait for Serial");
|
407
|
429
|
while (!Serial);
|
408
|
430
|
#endif // DEBUG_WAIT_FOR_SERIAL_CONN
|
409
|
431
|
|
|
@@ -436,6 +458,8 @@ void control_run(void) {
|
436
|
458
|
sm.input(c);
|
437
|
459
|
}
|
438
|
460
|
}
|
|
461
|
+
|
|
462
|
+ input_serial();
|
439
|
463
|
|
440
|
464
|
#endif // ! FUNCTION_UI
|
441
|
465
|
|
|
@@ -488,6 +512,9 @@ void write_to_all(const char *a, const char *b,
|
488
|
512
|
Wire.write(0x04); // display command
|
489
|
513
|
Wire.write((int8_t)num_input);
|
490
|
514
|
Wire.endTransmission();
|
|
515
|
+
|
|
516
|
+ wifi_set_message_buffer(a, b, c, d);
|
|
517
|
+ write_lcd_to_serial(a, b, c, d);
|
491
|
518
|
}
|
492
|
519
|
|
493
|
520
|
#endif // ! FUNCTION_UI
|