Parcourir la source

increased version to 0.2, added links, refactored statemachine enum

Thomas Buck il y a 3 ans
Parent
révision
7fa4a40284
5 fichiers modifiés avec 78 ajouts et 75 suppressions
  1. 9
    9
      include/Statemachine.h
  2. 1
    1
      include/config.h
  3. 4
    2
      src/SimpleUpdater.cpp
  4. 60
    60
      src/Statemachine.cpp
  5. 4
    3
      src/WifiStuff.cpp

+ 9
- 9
include/Statemachine.h Voir le fichier

@@ -11,24 +11,24 @@ public:
11 11
         init = 0,
12 12
         menu, // auto, pumps, valves
13 13
         
14
-        menu_auto, // select mode
15
-        menu_auto_fertilizer, // select fertilizer
16
-        menu_auto_fertilizer_running,
17
-        menu_auto_reservoir_running,
18
-        menu_auto_plant, // select plant
19
-        menu_auto_plant_running,
20
-        menu_auto_done,
14
+        auto_mode, // select mode
15
+        auto_fert, // select fertilizer
16
+        auto_fert_run,
17
+        auto_tank_run,
18
+        auto_plant, // select plant
19
+        auto_plant_run,
20
+        auto_done,
21 21
         
22 22
         menu_pumps, // selet pump
23 23
         menu_pumps_time, // set runtime
24 24
         menu_pumps_go, // running
25
-        menu_pumps_running,
25
+        menu_pumps_run,
26 26
         menu_pumps_done,
27 27
         
28 28
         menu_valves, // select valve
29 29
         menu_valves_time, // set runtime
30 30
         menu_valves_go, // running
31
-        menu_valves_running,
31
+        menu_valves_run,
32 32
         menu_valves_done,
33 33
         
34 34
         error

+ 1
- 1
include/config.h Voir le fichier

@@ -15,7 +15,7 @@
15 15
 #define MAX_AUTO_PLANT_RUNTIME 15
16 16
 
17 17
 // Sketch version
18
-#define FIRMWARE_VERSION "0.1"
18
+#define FIRMWARE_VERSION "0.2"
19 19
 
20 20
 // all given in milliseconds
21 21
 #define SERVER_HANDLE_INTERVAL 10

+ 4
- 2
src/SimpleUpdater.cpp Voir le fichier

@@ -32,11 +32,13 @@ void SimpleUpdater::get(void) {
32 32
         "</head><body>\n"
33 33
         
34 34
         "<h1>SimpleUpdater</h1>\n"
35
+        "<p>Select the update file. If you have built this project with PlatformIO, you can find a firmware.bin in the .pio folder.</p>\n"
35 36
         "<form method='POST' action='#' enctype='multipart/form-data' id='upload_form'>\n"
36 37
         "<input type='file' name='update' accept='.bin'>\n"
37 38
         "<input type='submit' value='Update'>\n"
38
-        "</form>\n"
39
+        "</form><br>\n"
39 40
         "<div id='prg'>progress: 0%</div>\n"
41
+        "<p>After the update is finished, you will automatically be redirected to the main page.</p>\n"
40 42
         "<a href=\"/\">Back to Main Page</a>\n"
41 43
         
42 44
         "<script>\n"
@@ -67,7 +69,7 @@ void SimpleUpdater::get(void) {
67 69
                     "}, 3000);\n"
68 70
                 "},\n"
69 71
                 "error: function(a, b, c) {\n"
70
-                    "$('#prg').html('progress: error! redirecting...');\n"
72
+                    "$('#prg').html('progress: finished! redirecting...');\n"
71 73
                     "setTimeout(function() {\n"
72 74
                         "window.location.href = '/';\n"
73 75
                     "}, 1000);\n"

+ 60
- 60
src/Statemachine.cpp Voir le fichier

@@ -54,22 +54,22 @@ uint32_t Statemachine::DigitBuffer::getNumber(void) {
54 54
 static const char *state_names[] = {
55 55
     stringify(init),
56 56
     stringify(menu),
57
-    stringify(menu_auto),
58
-    stringify(menu_auto_fertilizer),
59
-    stringify(menu_auto_fertilizer_running),
60
-    stringify(menu_auto_reservoir_running),
61
-    stringify(menu_auto_plant),
62
-    stringify(menu_auto_plant_running),
63
-    stringify(menu_auto_done),
57
+    stringify(auto_mode),
58
+    stringify(auto_fert),
59
+    stringify(auto_fert_run),
60
+    stringify(auto_tank_run),
61
+    stringify(auto_plant),
62
+    stringify(auto_plant_run),
63
+    stringify(auto_done),
64 64
     stringify(menu_pumps),
65 65
     stringify(menu_pumps_time),
66 66
     stringify(menu_pumps_go),
67
-    stringify(menu_pumps_running),
67
+    stringify(menu_pumps_run),
68 68
     stringify(menu_pumps_done),
69 69
     stringify(menu_valves),
70 70
     stringify(menu_valves_time),
71 71
     stringify(menu_valves_go),
72
-    stringify(menu_valves_running),
72
+    stringify(menu_valves_run),
73 73
     stringify(menu_valves_done),
74 74
     stringify(error)
75 75
 };
@@ -102,7 +102,7 @@ void Statemachine::input(int n) {
102 102
         switch_to(menu);
103 103
     } else if (state == menu) {
104 104
         if (n == 1) {
105
-            switch_to(menu_auto);
105
+            switch_to(auto_mode);
106 106
         } else if (n == 2) {
107 107
             switch_to(menu_pumps);
108 108
         } else if (n == 3) {
@@ -110,9 +110,9 @@ void Statemachine::input(int n) {
110 110
         } else if ((n == -1) || (n == -2)) {
111 111
             switch_to(init);
112 112
         }
113
-    } else if (state == menu_auto) {
113
+    } else if (state == auto_mode) {
114 114
         if (n == 1) {
115
-            switch_to(menu_auto_fertilizer);
115
+            switch_to(auto_fert);
116 116
         } else if (n == 2) {
117 117
             auto wl = plants.getWaterlevel();
118 118
             if ((wl != Plants::full) && (wl != Plants::invalid)) {
@@ -120,21 +120,21 @@ void Statemachine::input(int n) {
120 120
                 selected_id = plants.countPlants() + 1;
121 121
                 selected_time = MAX_TANK_FILL_TIME;
122 122
                 start_time = millis();
123
-                switch_to(menu_auto_reservoir_running);
123
+                switch_to(auto_tank_run);
124 124
             } else if (wl == Plants::full) {
125 125
                 stop_time = millis();
126
-                switch_to(menu_auto);
126
+                switch_to(auto_mode);
127 127
             } else if (wl == Plants::invalid) {
128 128
                 error_condition = "Invalid sensor state";
129
-                state = menu_auto;
129
+                state = auto_mode;
130 130
                 switch_to(error);
131 131
             }
132 132
         } else if (n == 3) {
133
-            switch_to(menu_auto_plant);
133
+            switch_to(auto_plant);
134 134
         } else if ((n == -1) || (n == -2)) {
135 135
             switch_to(menu);
136 136
         }
137
-    } else if (state == menu_auto_fertilizer) {
137
+    } else if (state == auto_fert) {
138 138
         if ((n >= 1) && (n <= 3)) {
139 139
             auto wl = plants.getWaterlevel();
140 140
             if ((wl != Plants::full) && (wl != Plants::invalid)) {
@@ -142,33 +142,33 @@ void Statemachine::input(int n) {
142 142
                 selected_id = n;
143 143
                 selected_time = AUTO_PUMP_RUNTIME;
144 144
                 start_time = millis();
145
-                switch_to(menu_auto_fertilizer_running);
145
+                switch_to(auto_fert_run);
146 146
             } else if (wl == Plants::full) {
147 147
                 stop_time = millis();
148
-                switch_to(menu_auto);
148
+                switch_to(auto_mode);
149 149
             } else if (wl == Plants::invalid) {
150 150
                 error_condition = "Invalid sensor state";
151
-                state = menu_auto;
151
+                state = auto_mode;
152 152
                 switch_to(error);
153 153
             }
154 154
         } else if ((n == -1) || (n == -2)) {
155
-            switch_to(menu_auto);
155
+            switch_to(auto_mode);
156 156
         }
157
-    } else if (state == menu_auto_fertilizer_running) {
157
+    } else if (state == auto_fert_run) {
158 158
             plants.abort();
159 159
             stop_time = millis();
160
-            switch_to(menu_auto_done);
161
-    } else if (state == menu_auto_reservoir_running) {
160
+            switch_to(auto_done);
161
+    } else if (state == auto_tank_run) {
162 162
             plants.abort();
163 163
             stop_time = millis();
164
-            switch_to(menu_auto_done);
165
-    } else if (state == menu_auto_plant) {
164
+            switch_to(auto_done);
165
+    } else if (state == auto_plant) {
166 166
         if (n == -1) {
167 167
             if (db.hasDigits()) {
168 168
                 backspace();
169 169
                 db.removeDigit();
170 170
             } else {
171
-                switch_to(menu_auto);
171
+                switch_to(auto_mode);
172 172
             }
173 173
         } else if (n == -2) {
174 174
             if (!db.hasDigits()) {
@@ -186,13 +186,13 @@ void Statemachine::input(int n) {
186 186
                     plants.startPlant(selected_id - 1);
187 187
                     selected_time = MAX_AUTO_PLANT_RUNTIME;
188 188
                     start_time = millis();
189
-                    switch_to(menu_auto_plant_running);
189
+                    switch_to(auto_plant_run);
190 190
                 } else if (wl == Plants::empty) {
191 191
                     stop_time = millis();
192
-                    switch_to(menu_auto);
192
+                    switch_to(auto_mode);
193 193
                 } else if (wl == Plants::invalid) {
194 194
                     error_condition = "Invalid sensor state";
195
-                    state = menu_auto;
195
+                    state = auto_mode;
196 196
                     switch_to(error);
197 197
                 }
198 198
             }
@@ -203,12 +203,12 @@ void Statemachine::input(int n) {
203 203
                 backspace();
204 204
             }
205 205
         }
206
-    } else if (state == menu_auto_plant_running) {
206
+    } else if (state == auto_plant_run) {
207 207
             plants.abort();
208 208
             stop_time = millis();
209
-            switch_to(menu_auto_done);
210
-    } else if (state == menu_auto_done) {
211
-        switch_to(menu_auto);
209
+            switch_to(auto_done);
210
+    } else if (state == auto_done) {
211
+        switch_to(auto_mode);
212 212
     } else if (state == menu_pumps) {
213 213
         if (n == -1) {
214 214
             if (db.hasDigits()) {
@@ -273,7 +273,7 @@ void Statemachine::input(int n) {
273 273
             auto wl = plants.getWaterlevel();
274 274
             if ((wl != Plants::full) && (wl != Plants::invalid)) {
275 275
                 plants.startFertilizer(selected_id - 1);
276
-                switch_to(menu_pumps_running);
276
+                switch_to(menu_pumps_run);
277 277
             } else if (wl == Plants::full) {
278 278
                 stop_time = millis();
279 279
                 switch_to(menu_pumps_done);
@@ -285,7 +285,7 @@ void Statemachine::input(int n) {
285 285
         } else {
286 286
             switch_to(menu_pumps_time);
287 287
         }
288
-    } else if (state == menu_pumps_running) {
288
+    } else if (state == menu_pumps_run) {
289 289
             plants.abort();
290 290
             stop_time = millis();
291 291
             switch_to(menu_pumps_done);
@@ -360,7 +360,7 @@ void Statemachine::input(int n) {
360 360
                     plants.startPlant(selected_id - 1);
361 361
                 }
362 362
                 
363
-                switch_to(menu_valves_running);
363
+                switch_to(menu_valves_run);
364 364
             } else if (wl == Plants::full) {
365 365
                 stop_time = millis();
366 366
                 switch_to(menu_valves_done);
@@ -372,7 +372,7 @@ void Statemachine::input(int n) {
372 372
         } else {
373 373
             switch_to(menu_valves_time);
374 374
         }
375
-    } else if (state == menu_valves_running) {
375
+    } else if (state == menu_valves_run) {
376 376
             plants.abort();
377 377
             stop_time = millis();
378 378
             switch_to(menu_valves_done);
@@ -402,13 +402,13 @@ uint32_t Statemachine::number_input(void) {
402 402
 }
403 403
 
404 404
 void Statemachine::act(void) {
405
-    if ((state == menu_pumps_running) || (state == menu_valves_running)) {
405
+    if ((state == menu_pumps_run) || (state == menu_valves_run)) {
406 406
         unsigned long runtime = millis() - start_time;
407 407
         if ((runtime / 1000UL) >= selected_time) {
408 408
             // stop if timeout has been reached
409 409
             plants.abort();
410 410
             stop_time = millis();
411
-            switch_to((state == menu_pumps_running) ? menu_pumps_done : menu_valves_done);
411
+            switch_to((state == menu_pumps_run) ? menu_pumps_done : menu_valves_done);
412 412
         } else if ((millis() - last_animation_time) >= 500) {
413 413
             // update animation if needed
414 414
             last_animation_time = millis();
@@ -416,28 +416,28 @@ void Statemachine::act(void) {
416 416
         }
417 417
     }
418 418
     
419
-    if ((state == menu_pumps_running) || ((state == menu_valves_running) && (selected_id == (plants.countPlants() + 1)))) {
419
+    if ((state == menu_pumps_run) || ((state == menu_valves_run) && (selected_id == (plants.countPlants() + 1)))) {
420 420
         // check water level state
421 421
         auto wl = plants.getWaterlevel();
422 422
         if (wl == Plants::full) {
423 423
             plants.abort();
424 424
             stop_time = millis();
425
-            switch_to((state == menu_pumps_running) ? menu_pumps_done : menu_valves_done);
425
+            switch_to((state == menu_pumps_run) ? menu_pumps_done : menu_valves_done);
426 426
         } else if (wl == Plants::invalid) {
427 427
             plants.abort();
428 428
             error_condition = "Invalid sensor state";
429
-            state = (state == menu_pumps_running) ? menu_pumps : menu_valves;
429
+            state = (state == menu_pumps_run) ? menu_pumps : menu_valves;
430 430
             switch_to(error);
431 431
         }
432 432
     }
433 433
     
434
-    if ((state == menu_auto_fertilizer_running) || (state == menu_auto_reservoir_running)) {
434
+    if ((state == auto_fert_run) || (state == auto_tank_run)) {
435 435
         unsigned long runtime = millis() - start_time;
436 436
         if ((runtime / 1000UL) >= selected_time) {
437 437
             // stop if timeout has been reached
438 438
             plants.abort();
439 439
             stop_time = millis();
440
-            switch_to(menu_auto_done);
440
+            switch_to(auto_done);
441 441
         } else if ((millis() - last_animation_time) >= 500) {
442 442
             // update animation if needed
443 443
             last_animation_time = millis();
@@ -449,22 +449,22 @@ void Statemachine::act(void) {
449 449
         if (wl == Plants::full) {
450 450
             plants.abort();
451 451
             stop_time = millis();
452
-            switch_to(menu_auto_done);
452
+            switch_to(auto_done);
453 453
         } else if (wl == Plants::invalid) {
454 454
             plants.abort();
455 455
             error_condition = "Invalid sensor state";
456
-            state = menu_auto;
456
+            state = auto_mode;
457 457
             switch_to(error);
458 458
         }
459 459
     }
460 460
         
461
-    if (state == menu_auto_plant_running) {
461
+    if (state == auto_plant_run) {
462 462
         unsigned long runtime = millis() - start_time;
463 463
         if ((runtime / 1000UL) >= selected_time) {
464 464
             // stop if timeout has been reached
465 465
             plants.abort();
466 466
             stop_time = millis();
467
-            switch_to(menu_auto_done);
467
+            switch_to(auto_done);
468 468
         } else if ((millis() - last_animation_time) >= 500) {
469 469
             // update animation if needed
470 470
             last_animation_time = millis();
@@ -476,11 +476,11 @@ void Statemachine::act(void) {
476 476
         if (wl == Plants::empty) {
477 477
             plants.abort();
478 478
             stop_time = millis();
479
-            switch_to(menu_auto_done);
479
+            switch_to(auto_done);
480 480
         } else if (wl == Plants::invalid) {
481 481
             plants.abort();
482 482
             error_condition = "Invalid sensor state";
483
-            state = menu_auto;
483
+            state = auto_mode;
484 484
             switch_to(error);
485 485
         }
486 486
     }
@@ -504,19 +504,19 @@ void Statemachine::switch_to(States s) {
504 504
               "2: Fertilizer pumps",
505 505
               "3: Outlet valves",
506 506
               -1);
507
-    } else if (s == menu_auto) {
507
+    } else if (s == auto_mode) {
508 508
         print("------- Auto -------",
509 509
               "1: Add Fertilizer",
510 510
               "2: Fill Reservoir",
511 511
               "3: Water a plant",
512 512
               -1);
513
-    } else if (s == menu_auto_fertilizer) {
513
+    } else if (s == auto_fert) {
514 514
         print("---- Fertilizer ----",
515 515
               "1: Vegetation Phase",
516 516
               "2: Bloom Phase",
517 517
               "3: Special",
518 518
               -1);
519
-    } else if (s == menu_auto_fertilizer_running) {
519
+    } else if (s == auto_fert_run) {
520 520
         unsigned long runtime = millis() - start_time;
521 521
         String a = String("Runtime: ") + String(runtime / 1000UL) + String("s / ") + String(selected_time) + String('s');
522 522
         
@@ -531,7 +531,7 @@ void Statemachine::switch_to(States s) {
531 531
               b.c_str(),
532 532
               "Hit any key to stop!",
533 533
               -1);
534
-    } else if (s == menu_auto_reservoir_running) {
534
+    } else if (s == auto_tank_run) {
535 535
         unsigned long runtime = millis() - start_time;
536 536
         String a = String("Runtime: ") + String(runtime / 1000UL) + String("s / ") + String(selected_time) + String('s');
537 537
         
@@ -546,7 +546,7 @@ void Statemachine::switch_to(States s) {
546 546
               b.c_str(),
547 547
               "Hit any key to stop!",
548 548
               -1);
549
-    } else if (s == menu_auto_plant) {
549
+    } else if (s == auto_plant) {
550 550
         String a = String("(Input 1 to ") + String(plants.countPlants()) + String(")");
551 551
         
552 552
         print("--- Select Plant ---",
@@ -554,7 +554,7 @@ void Statemachine::switch_to(States s) {
554 554
               a.c_str(),
555 555
               "Plant: ",
556 556
               3);
557
-    } else if (s == menu_auto_plant_running) {
557
+    } else if (s == auto_plant_run) {
558 558
         unsigned long runtime = millis() - start_time;
559 559
         String a = String("Runtime: ") + String(runtime / 1000UL) + String("s / ") + String(selected_time) + String('s');
560 560
         
@@ -569,7 +569,7 @@ void Statemachine::switch_to(States s) {
569 569
               b.c_str(),
570 570
               "Hit any key to stop!",
571 571
               -1);
572
-    } else if (s == menu_auto_done) {
572
+    } else if (s == auto_done) {
573 573
         String a = String("after ") + String((stop_time - start_time) / 1000UL) + String("s.");
574 574
         
575 575
         print("------- Done -------",
@@ -602,7 +602,7 @@ void Statemachine::switch_to(States s) {
602 602
               b.c_str(),
603 603
               "           # Confirm",
604 604
               -1);
605
-    } else if (s == menu_pumps_running) {
605
+    } else if (s == menu_pumps_run) {
606 606
         unsigned long runtime = millis() - start_time;
607 607
         String a = String("Runtime: ") + String(runtime / 1000UL) + String("s / ") + String(selected_time) + String('s');
608 608
         
@@ -650,7 +650,7 @@ void Statemachine::switch_to(States s) {
650 650
               b.c_str(),
651 651
               "           # Confirm",
652 652
               -1);
653
-    } else if (s == menu_valves_running) {
653
+    } else if (s == menu_valves_run) {
654 654
         unsigned long runtime = millis() - start_time;
655 655
         String a = String("Runtime: ") + String(runtime / 1000UL) + String("s / ") + String(selected_time) + String('s');
656 656
         

+ 4
- 3
src/WifiStuff.cpp Voir le fichier

@@ -373,9 +373,10 @@ void handleRoot() {
373 373
     
374 374
 #endif
375 375
 
376
-    message += F("<p>\n");
377
-    message += F("Try <a href='/update'>/update</a> for OTA firmware updates!\n");
378
-    message += F("</p></div>\n");
376
+    message += F("<p>Try <a href='/update'>/update</a> for OTA firmware updates!</p>\n");
377
+    message += F("<p>Made by <a href='https://xythobuz.de'>xythobuz</a></p>\n");
378
+    message += F("<p><a href='https://git.xythobuz.de/thomas/giess-o-mat'>Project Repository</a></p>\n");
379
+    message += F("</div>\n");
379 380
     message += F("</div></body>\n");
380 381
     
381 382
     message += F("<script type='text/javascript'>\n");

Chargement…
Annuler
Enregistrer