Bläddra i källkod

added ability to water multiple plants at once

Thomas Buck 3 år sedan
förälder
incheckning
5c39537cf7
4 ändrade filer med 101 tillägg och 12 borttagningar
  1. 37
    0
      include/BoolField.h
  2. 2
    0
      include/Statemachine.h
  3. 43
    0
      src/BoolField.cpp
  4. 19
    12
      src/Statemachine.cpp

+ 37
- 0
include/BoolField.h Visa fil

@@ -0,0 +1,37 @@
1
+/*
2
+ * Copyright (c) 2021 Thomas Buck <thomas@xythobuz.de>
3
+ *
4
+ * This file is part of Giess-o-mat.
5
+ *
6
+ * Giess-o-mat is free software: you can redistribute it and/or modify
7
+ * it under the terms of the GNU General Public License as published by
8
+ * the Free Software Foundation, either version 3 of the License, or
9
+ * (at your option) any later version.
10
+ *
11
+ * Giess-o-mat is distributed in the hope that it will be useful,
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
+ * GNU General Public License for more details.
15
+ *
16
+ * You should have received a copy of the GNU General Public License
17
+ * along with Giess-o-mat.  If not, see <https://www.gnu.org/licenses/>.
18
+ */
19
+
20
+#ifndef _BOOL_FIELD_H_
21
+#define _BOOL_FIELD_H_
22
+
23
+class BoolField {
24
+public:
25
+    BoolField(int size_);
26
+    ~BoolField(void);
27
+    
28
+    void clear(void);
29
+    void set(int n);
30
+    bool isSet(int n);
31
+    
32
+private:
33
+    int size;
34
+    bool *field;
35
+};
36
+
37
+#endif // _BOOL_FIELD_H_

+ 2
- 0
include/Statemachine.h Visa fil

@@ -21,6 +21,7 @@
21 21
 #define _STATEMACHINE_H_
22 22
 
23 23
 #include <Arduino.h>
24
+#include "BoolField.h"
24 25
 
25 26
 #define stringify( name ) # name
26 27
 
@@ -95,6 +96,7 @@ private:
95 96
     print_fn print;
96 97
     backspace_fn backspace;
97 98
     
99
+    BoolField selected_plants;
98 100
     uint32_t selected_id; // pump or valve id
99 101
     uint32_t selected_time; // runtime
100 102
     unsigned long start_time, stop_time, last_animation_time;

+ 43
- 0
src/BoolField.cpp Visa fil

@@ -0,0 +1,43 @@
1
+/*
2
+ * Copyright (c) 2021 Thomas Buck <thomas@xythobuz.de>
3
+ *
4
+ * This file is part of Giess-o-mat.
5
+ *
6
+ * Giess-o-mat is free software: you can redistribute it and/or modify
7
+ * it under the terms of the GNU General Public License as published by
8
+ * the Free Software Foundation, either version 3 of the License, or
9
+ * (at your option) any later version.
10
+ *
11
+ * Giess-o-mat is distributed in the hope that it will be useful,
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
+ * GNU General Public License for more details.
15
+ *
16
+ * You should have received a copy of the GNU General Public License
17
+ * along with Giess-o-mat.  If not, see <https://www.gnu.org/licenses/>.
18
+ */
19
+
20
+#include "BoolField.h"
21
+
22
+BoolField::BoolField(int size_) {
23
+    size = size_;
24
+    field = new bool[size];
25
+}
26
+
27
+BoolField::~BoolField(void) {
28
+    delete field;
29
+}
30
+
31
+void BoolField::clear(void) {
32
+    for (int i = 0; i < size; i++) {
33
+        field[i] = false;
34
+    }
35
+}
36
+
37
+void BoolField::set(int n) {
38
+    field[n] = true;
39
+}
40
+
41
+bool BoolField::isSet(int n) {
42
+    return field[n];
43
+}

+ 19
- 12
src/Statemachine.cpp Visa fil

@@ -99,7 +99,7 @@ const char *Statemachine::getStateName(void) {
99 99
 }
100 100
 
101 101
 Statemachine::Statemachine(print_fn _print, backspace_fn _backspace)
102
-        : db(7) {
102
+        : db(7), selected_plants(plants.countPlants()) {
103 103
     state = init;
104 104
     old_state = init;
105 105
     print = _print;
@@ -150,6 +150,7 @@ void Statemachine::input(int n) {
150 150
                 switch_to(error);
151 151
             }
152 152
         } else if (n == 3) {
153
+            selected_plants.clear();
153 154
             switch_to(auto_plant);
154 155
         } else if ((n == -1) || (n == -2)) {
155 156
             switch_to(menu);
@@ -192,18 +193,15 @@ void Statemachine::input(int n) {
192 193
             }
193 194
         } else if (n == -2) {
194 195
             if (!db.hasDigits()) {
195
-                return;
196
-            }
197
-            
198
-            selected_id = number_input();
199
-            
200
-            if ((selected_id <= 0) || (selected_id > plants.countPlants())) {
201
-                error_condition = "Invalid plant ID!";
202
-                switch_to(error);
203
-            } else {
204 196
                 auto wl = plants.getWaterlevel();
205 197
                 if ((wl != Plants::empty) && (wl != Plants::invalid)) {
206
-                    plants.startPlant(selected_id - 1);
198
+                    for (int i = 0; i < plants.countPlants(); i++) {
199
+                        if (selected_plants.isSet(i)) {
200
+                            plants.startPlant(i);
201
+                        }
202
+                    }
203
+                    selected_plants.clear();
204
+                    
207 205
                     selected_time = MAX_AUTO_PLANT_RUNTIME;
208 206
                     start_time = millis();
209 207
                     switch_to(auto_plant_run);
@@ -215,6 +213,15 @@ void Statemachine::input(int n) {
215 213
                     state = auto_mode;
216 214
                     switch_to(error);
217 215
                 }
216
+            } else {
217
+                selected_id = number_input();
218
+                if ((selected_id <= 0) || (selected_id > plants.countPlants())) {
219
+                    error_condition = "Invalid plant ID!";
220
+                    switch_to(error);
221
+                } else {
222
+                    selected_plants.set(selected_id - 1);
223
+                    switch_to(auto_plant);
224
+                }
218 225
             }
219 226
         } else {
220 227
             if (db.spaceLeft()) {
@@ -589,7 +596,7 @@ void Statemachine::switch_to(States s) {
589 596
         String a = String("(Input 1 to ") + String(plants.countPlants()) + String(")");
590 597
         
591 598
         print("--- Select Plant ---",
592
-              "Which plant to water",
599
+              "Leave empty if done!",
593 600
               a.c_str(),
594 601
               "Plant: ",
595 602
               3);

Laddar…
Avbryt
Spara