Browse Source

support door locks, with optional pin entry.

Thomas Buck 2 years ago
parent
commit
70659caf77
4 changed files with 130 additions and 8 deletions
  1. 1
    0
      include/Statemachine.h
  2. 5
    1
      include/config.h
  3. 5
    3
      include/config_pins.h
  4. 119
    4
      src/Statemachine.cpp

+ 1
- 0
include/Statemachine.h View File

29
 public:
29
 public:
30
     enum States {
30
     enum States {
31
         init = 0,
31
         init = 0,
32
+        door_select,
32
         menu_a, // manual, auto
33
         menu_a, // manual, auto
33
         menu_b, // pumps, valves
34
         menu_b, // pumps, valves
34
         menu_c, // aux
35
         menu_c, // aux

+ 5
- 1
include/config.h View File

39
 #define MAX_AUX_RUNTIME (5 * 60)
39
 #define MAX_AUX_RUNTIME (5 * 60)
40
 
40
 
41
 // Sketch version
41
 // Sketch version
42
-#define FIRMWARE_VERSION "0.3"
42
+#define FIRMWARE_VERSION "0.4"
43
 
43
 
44
 // all given in milliseconds
44
 // all given in milliseconds
45
 #define SERVER_HANDLE_INTERVAL 10
45
 #define SERVER_HANDLE_INTERVAL 10
69
 #define INFLUXDB_PORT 8086
69
 #define INFLUXDB_PORT 8086
70
 #define INFLUXDB_DATABASE "giessomat"
70
 #define INFLUXDB_DATABASE "giessomat"
71
 
71
 
72
+#define DOOR_LOCK_PIN 4223
73
+#define DOOR_LOCK_ON_TIME 100 /* in ms */
74
+#define DOOR_LOCK_PIN_MAX_DIGITS 6
75
+
72
 #endif // _CONFIG_H_
76
 #endif // _CONFIG_H_

+ 5
- 3
include/config_pins.h View File

128
 #define PUMP_COUNT 3
128
 #define PUMP_COUNT 3
129
 #define PUMP_PINS 2, 0, 4
129
 #define PUMP_PINS 2, 0, 4
130
 
130
 
131
-// stirrer
132
-#define AUX_COUNT 1
133
-#define AUX_PINS 19
131
+// stirrer, locks
132
+#define STIRRER_COUNT 1
133
+#define LOCK_COUNT 2
134
+#define AUX_COUNT (STIRRER_COUNT + LOCK_COUNT)
135
+#define AUX_PINS 19, 104, 105
134
 
136
 
135
 // bottom, top
137
 // bottom, top
136
 #define SWITCH_COUNT 2
138
 #define SWITCH_COUNT 2

+ 119
- 4
src/Statemachine.cpp View File

22
 #include "WifiStuff.h"
22
 #include "WifiStuff.h"
23
 #include "Statemachine.h"
23
 #include "Statemachine.h"
24
 #include "config.h"
24
 #include "config.h"
25
+#include "config_pins.h"
25
 
26
 
26
 Statemachine::DigitBuffer::DigitBuffer(int _size) {
27
 Statemachine::DigitBuffer::DigitBuffer(int _size) {
27
     size = _size;
28
     size = _size;
74
 
75
 
75
 static const char *state_names[] = {
76
 static const char *state_names[] = {
76
     stringify(init),
77
     stringify(init),
78
+    stringify(door_select),
77
     stringify(menu_a),
79
     stringify(menu_a),
78
     stringify(menu_b),
80
     stringify(menu_b),
79
     stringify(menu_c),
81
     stringify(menu_c),
142
 
144
 
143
 void Statemachine::input(int n) {
145
 void Statemachine::input(int n) {
144
     if (state == init) {
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
         switch_to(menu_a);
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
     } else if ((state == menu_a) || (state == menu_b) || (state == menu_c)) {
234
     } else if ((state == menu_a) || (state == menu_b) || (state == menu_c)) {
147
         if (n == 1) {
235
         if (n == 1) {
148
             switch_to(auto_mode_a);
236
             switch_to(auto_mode_a);
154
             switch_to(menu_valves);
242
             switch_to(menu_valves);
155
         } else if (n == 5) {
243
         } else if (n == 5) {
156
             switch_to(menu_aux);
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
         } else if (n == -1) {
249
         } else if (n == -1) {
158
             switch_to(init);
250
             switch_to(init);
159
         } else if (n == -2) {
251
         } else if (n == -2) {
210
                 switch_to(error);
302
                 switch_to(error);
211
             }
303
             }
212
         } else if (n == 4) {
304
         } else if (n == 4) {
213
-            plants.startAux(0);
305
+            for (int i = 0; i < STIRRER_COUNT; i++) {
306
+                plants.startAux(i);
307
+            }
214
             selected_id = 1;
308
             selected_id = 1;
215
             selected_time = AUTO_STIRR_RUNTIME;
309
             selected_time = AUTO_STIRR_RUNTIME;
216
             start_time = millis();
310
             start_time = millis();
933
     
1027
     
934
     if (s == init) {
1028
     if (s == init) {
935
         String a = String(F("- Giess-o-mat V")) + FIRMWARE_VERSION + String(F(" -"));
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
         print(a.c_str(),
1039
         print(a.c_str(),
938
               "Usage:  Enter number",
1040
               "Usage:  Enter number",
939
               "* Delete prev. digit",
1041
               "* Delete prev. digit",
940
               "# Execute input num.",
1042
               "# Execute input num.",
941
               -1);
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
     } else if (s == menu_a) {
1054
     } else if (s == menu_a) {
943
         print("----- Menu 1/3 -----",
1055
         print("----- Menu 1/3 -----",
944
               "1: Manual Operation",
1056
               "1: Manual Operation",
954
     } else if (s == menu_c) {
1066
     } else if (s == menu_c) {
955
         print("----- Menu 3/3 -----",
1067
         print("----- Menu 3/3 -----",
956
               "5: Aux. Outputs",
1068
               "5: Aux. Outputs",
1069
+#if (LOCK_COUNT > 0) && !defined(DOOR_LOCK_PIN)
1070
+              "6: Door Locks",
1071
+#else
957
               "",
1072
               "",
1073
+#endif
958
               "#: Go to page 1/3...",
1074
               "#: Go to page 1/3...",
959
               -1);
1075
               -1);
960
     } else if (state == automation_mode) {
1076
     } else if (state == automation_mode) {
1037
         String a = String("(Input 1 to ") + String(plants.countPlants()) + String(")");
1153
         String a = String("(Input 1 to ") + String(plants.countPlants()) + String(")");
1038
         String b = String(F("Plant: ")) + menu_entered_digits;
1154
         String b = String(F("Plant: ")) + menu_entered_digits;
1039
 
1155
 
1040
-
1041
         print("--- Select Plant ---",
1156
         print("--- Select Plant ---",
1042
               "Leave empty if done!",
1157
               "Leave empty if done!",
1043
               a.c_str(),
1158
               a.c_str(),
1273
         String a = String("after ") + String((stop_time - start_time) / 1000UL) + String("s.");
1388
         String a = String("after ") + String((stop_time - start_time) / 1000UL) + String("s.");
1274
 
1389
 
1275
         print("------- Done -------",
1390
         print("------- Done -------",
1276
-              "Stirring finished",
1391
+              "Aux. run finished",
1277
               a.c_str(),
1392
               a.c_str(),
1278
               "Hit any key for menu",
1393
               "Hit any key for menu",
1279
               -1);
1394
               -1);

Loading…
Cancel
Save