Browse Source

added ability to water multiple plants at once

Thomas Buck 3 years ago
parent
commit
5c39537cf7
4 changed files with 101 additions and 12 deletions
  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 View File

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 View File

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

+ 43
- 0
src/BoolField.cpp View File

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 View File

99
 }
99
 }
100
 
100
 
101
 Statemachine::Statemachine(print_fn _print, backspace_fn _backspace)
101
 Statemachine::Statemachine(print_fn _print, backspace_fn _backspace)
102
-        : db(7) {
102
+        : db(7), selected_plants(plants.countPlants()) {
103
     state = init;
103
     state = init;
104
     old_state = init;
104
     old_state = init;
105
     print = _print;
105
     print = _print;
150
                 switch_to(error);
150
                 switch_to(error);
151
             }
151
             }
152
         } else if (n == 3) {
152
         } else if (n == 3) {
153
+            selected_plants.clear();
153
             switch_to(auto_plant);
154
             switch_to(auto_plant);
154
         } else if ((n == -1) || (n == -2)) {
155
         } else if ((n == -1) || (n == -2)) {
155
             switch_to(menu);
156
             switch_to(menu);
192
             }
193
             }
193
         } else if (n == -2) {
194
         } else if (n == -2) {
194
             if (!db.hasDigits()) {
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
                 auto wl = plants.getWaterlevel();
196
                 auto wl = plants.getWaterlevel();
205
                 if ((wl != Plants::empty) && (wl != Plants::invalid)) {
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
                     selected_time = MAX_AUTO_PLANT_RUNTIME;
205
                     selected_time = MAX_AUTO_PLANT_RUNTIME;
208
                     start_time = millis();
206
                     start_time = millis();
209
                     switch_to(auto_plant_run);
207
                     switch_to(auto_plant_run);
215
                     state = auto_mode;
213
                     state = auto_mode;
216
                     switch_to(error);
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
         } else {
226
         } else {
220
             if (db.spaceLeft()) {
227
             if (db.spaceLeft()) {
589
         String a = String("(Input 1 to ") + String(plants.countPlants()) + String(")");
596
         String a = String("(Input 1 to ") + String(plants.countPlants()) + String(")");
590
         
597
         
591
         print("--- Select Plant ---",
598
         print("--- Select Plant ---",
592
-              "Which plant to water",
599
+              "Leave empty if done!",
593
               a.c_str(),
600
               a.c_str(),
594
               "Plant: ",
601
               "Plant: ",
595
               3);
602
               3);

Loading…
Cancel
Save