Pārlūkot izejas kodu

Make sensor inputs invertable

Thomas Buck 3 gadus atpakaļ
vecāks
revīzija
08c22aff7e
3 mainītis faili ar 44 papildinājumiem un 2 dzēšanām
  1. 3
    0
      include/config.h
  2. 11
    0
      src/Plants.cpp
  3. 30
    2
      src/WifiStuff.cpp

+ 3
- 0
include/config.h Parādīt failu

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

+ 11
- 0
src/Plants.cpp Parādīt failu

@@ -1,6 +1,9 @@
1 1
 #include <Arduino.h>
2
+
2 3
 #include "DebugLog.h"
3 4
 #include "Plants.h"
5
+#include "config.h"
6
+#include "config_pins.h"
4 7
     
5 8
 // valves: no of plants + 1 for water inlet
6 9
 // pumps: no of fertilizers
@@ -49,6 +52,14 @@ Plants::Waterlevel Plants::getWaterlevel(void) {
49 52
     bool low = switches.getPin(0);
50 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 63
     if ((!low) && (!high)) {
53 64
         return empty;
54 65
     } else if (low && (!high)) {

+ 30
- 2
src/WifiStuff.cpp Parādīt failu

@@ -94,8 +94,22 @@ void wifi_send_status_broadcast(void) {
94 94
     
95 95
     ws += F("\"switches\": [ ");
96 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 111
         ws += "\"";
98
-        ws += get_plants()->getSwitches()->getPin(i) ? "1" : "0";
112
+        ws += v ? "1" : "0";
99 113
         ws += "\"";
100 114
         
101 115
         if (i < (SWITCH_COUNT - 1)) {
@@ -298,7 +312,21 @@ void handleRoot() {
298 312
     message += F("<div class='container'>\n");
299 313
     for (int i = 0; i < SWITCH_COUNT; i++) {
300 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 330
             message += F("red");
303 331
         } else {
304 332
             message += F("green");

Notiek ielāde…
Atcelt
Saglabāt