Browse Source

Make sensor inputs invertable

Thomas Buck 2 years ago
parent
commit
08c22aff7e
3 changed files with 44 additions and 2 deletions
  1. 3
    0
      include/config.h
  2. 11
    0
      src/Plants.cpp
  3. 30
    2
      src/WifiStuff.cpp

+ 3
- 0
include/config.h View File

25
 #define LED_CONNECT_BLINK_INTERVAL 250
25
 #define LED_CONNECT_BLINK_INTERVAL 250
26
 #define LED_ERROR_BLINK_INTERVAL 100
26
 #define LED_ERROR_BLINK_INTERVAL 100
27
 
27
 
28
+#define INVERT_SENSOR_BOTTOM
29
+//#define INVERT_SENSOR_TOP
30
+
28
 #define OWN_I2C_ADDRESS 0x42
31
 #define OWN_I2C_ADDRESS 0x42
29
 #define I2C_BUS_SPEED 400000
32
 #define I2C_BUS_SPEED 400000
30
 #define I2C_BUF_SIZE 32
33
 #define I2C_BUF_SIZE 32

+ 11
- 0
src/Plants.cpp View File

1
 #include <Arduino.h>
1
 #include <Arduino.h>
2
+
2
 #include "DebugLog.h"
3
 #include "DebugLog.h"
3
 #include "Plants.h"
4
 #include "Plants.h"
5
+#include "config.h"
6
+#include "config_pins.h"
4
     
7
     
5
 // valves: no of plants + 1 for water inlet
8
 // valves: no of plants + 1 for water inlet
6
 // pumps: no of fertilizers
9
 // pumps: no of fertilizers
49
     bool low = switches.getPin(0);
52
     bool low = switches.getPin(0);
50
     bool high = switches.getPin(1);
53
     bool high = switches.getPin(1);
51
     
54
     
55
+#ifdef INVERT_SENSOR_BOTTOM
56
+    low = !low;
57
+#endif // INVERT_SENSOR_BOTTOM
58
+    
59
+#ifdef INVERT_SENSOR_TOP
60
+    high = !high;
61
+#endif // INVERT_SENSOR_TOP
62
+    
52
     if ((!low) && (!high)) {
63
     if ((!low) && (!high)) {
53
         return empty;
64
         return empty;
54
     } else if (low && (!high)) {
65
     } else if (low && (!high)) {

+ 30
- 2
src/WifiStuff.cpp View File

94
     
94
     
95
     ws += F("\"switches\": [ ");
95
     ws += F("\"switches\": [ ");
96
     for (int i = 0; i < SWITCH_COUNT; i++) {
96
     for (int i = 0; i < SWITCH_COUNT; i++) {
97
+        bool v = get_plants()->getSwitches()->getPin(i);
98
+        
99
+#ifdef INVERT_SENSOR_BOTTOM
100
+        if (i == 0) {
101
+            v = !v;
102
+        }
103
+#endif // INVERT_SENSOR_BOTTOM
104
+        
105
+#ifdef INVERT_SENSOR_TOP
106
+        if (i == 1) {
107
+            v = !v;
108
+        }
109
+#endif // INVERT_SENSOR_TOP
110
+
97
         ws += "\"";
111
         ws += "\"";
98
-        ws += get_plants()->getSwitches()->getPin(i) ? "1" : "0";
112
+        ws += v ? "1" : "0";
99
         ws += "\"";
113
         ws += "\"";
100
         
114
         
101
         if (i < (SWITCH_COUNT - 1)) {
115
         if (i < (SWITCH_COUNT - 1)) {
298
     message += F("<div class='container'>\n");
312
     message += F("<div class='container'>\n");
299
     for (int i = 0; i < SWITCH_COUNT; i++) {
313
     for (int i = 0; i < SWITCH_COUNT; i++) {
300
         message += F("<div class='switch' style='background-color: ");
314
         message += F("<div class='switch' style='background-color: ");
301
-        if (get_plants()->getSwitches()->getPin(i)) {
315
+        bool v = get_plants()->getSwitches()->getPin(i);
316
+        
317
+#ifdef INVERT_SENSOR_BOTTOM
318
+        if (i == 0) {
319
+            v = !v;
320
+        }
321
+#endif // INVERT_SENSOR_BOTTOM
322
+        
323
+#ifdef INVERT_SENSOR_TOP
324
+        if (i == 1) {
325
+            v = !v;
326
+        }
327
+#endif // INVERT_SENSOR_TOP
328
+        
329
+        if (v) {
302
             message += F("red");
330
             message += F("red");
303
         } else {
331
         } else {
304
             message += F("green");
332
             message += F("green");

Loading…
Cancel
Save