Преглед на файлове

Added optional GPIO test and fixed pin numbering

Thomas Buck преди 3 години
родител
ревизия
76c9a73d02
променени са 2 файла, в които са добавени 65 реда и са изтрити 6 реда
  1. 9
    6
      include/config_pins.h
  2. 56
    0
      src/WifiStuff.cpp

+ 9
- 6
include/config_pins.h Целия файл

@@ -25,12 +25,15 @@
25 25
 
26 26
 #ifdef FUNCTION_CONTROL
27 27
 
28
+// out 1, out 2, out 3, out 4, in
28 29
 #define VALVE_COUNT 5
29 30
 #define VALVE_PINS 10, 11, 12, 14, 15
30 31
 
32
+// a, b, c
31 33
 #define PUMP_COUNT 3
32 34
 #define PUMP_PINS 16, 17, 18
33 35
 
36
+// bottom, top
34 37
 #define SWITCH_COUNT 2
35 38
 #define SWITCH_PINS 19, 20
36 39
 
@@ -57,17 +60,17 @@
57 60
 
58 61
 #ifdef FUNCTION_CONTROL
59 62
 
60
-// R1 R2 R3 R4  R5 R6 R7 R8
61
-//  4  0  2 15  18  5 17 16
62
-
63
+// out 1, out 2, out 3, out 4, in
63 64
 #define VALVE_COUNT 5
64
-#define VALVE_PINS 4, 0, 2, 15, 18
65
+#define VALVE_PINS 27, 14, 5, 18, 15
65 66
 
67
+// a, b, c
66 68
 #define PUMP_COUNT 3
67
-#define PUMP_PINS 5, 17, 16
69
+#define PUMP_PINS 2, 0, 4
68 70
 
71
+// bottom, top
69 72
 #define SWITCH_COUNT 2
70
-#define SWITCH_PINS 22, 23
73
+#define SWITCH_PINS 26, 25
71 74
 
72 75
 #define I2C_SDA_PIN 21
73 76
 #define I2C_SCL_PIN 22

+ 56
- 0
src/WifiStuff.cpp Целия файл

@@ -37,6 +37,45 @@ String message_buffer_b;
37 37
 String message_buffer_c;
38 38
 String message_buffer_d;
39 39
 
40
+//#define ENABLE_GPIO_TEST
41
+#ifdef ENABLE_GPIO_TEST
42
+
43
+#define GPIO_TEST_INTERVAL 4000
44
+#define GPIO_TEST_DELAY 200
45
+static bool runningGpioTest = false;
46
+static bool gpioTestState = false;
47
+unsigned long lastGpioTime = 0;
48
+
49
+void runGpioTest(bool state) {
50
+    lastGpioTime = millis();
51
+    
52
+    for (int i = 0; i < VALVE_COUNT; i++) {
53
+        get_plants()->getValves()->setPin(i, state);
54
+        delay(GPIO_TEST_DELAY);
55
+    }
56
+    
57
+    for (int i = 0; i < PUMP_COUNT; i++) {
58
+        get_plants()->getPumps()->setPin(i, state);
59
+        if (i < (PUMP_COUNT - 1)) {
60
+            delay(GPIO_TEST_DELAY);
61
+        }
62
+    }
63
+}
64
+
65
+void handleGpioTest() {
66
+    runningGpioTest = !runningGpioTest;
67
+    gpioTestState = runningGpioTest;
68
+    
69
+    String message = F("GPIOs turned ");
70
+    message += runningGpioTest ? "on" : "off";
71
+
72
+    server.send(200, "text/html", message);
73
+    
74
+    runGpioTest(gpioTestState);
75
+}
76
+
77
+#endif // ENABLE_GPIO_TEST
78
+
40 79
 void wifi_set_message_buffer(String a, String b, String c, String d) {
41 80
     message_buffer_a = a;
42 81
     message_buffer_b = b;
@@ -433,6 +472,11 @@ void handleRoot() {
433 472
     message += F("<p>Try <a href='/update'>/update</a> for OTA firmware updates!</p>\n");
434 473
     message += F("<p>Made by <a href='https://xythobuz.de'>xythobuz</a></p>\n");
435 474
     message += F("<p><a href='https://git.xythobuz.de/thomas/giess-o-mat'>Project Repository</a></p>\n");
475
+    
476
+#ifdef ENABLE_GPIO_TEST
477
+    message += F("<p><a href='/gpiotest'>GPIO Test</a></p>\n");
478
+#endif // ENABLE_GPIO_TEST
479
+    
436 480
     message += F("</div></div>\n");
437 481
     
438 482
     message += F("<div class='log'><pre id='logbuf'>\n");
@@ -589,6 +633,11 @@ void wifi_setup() {
589 633
     MDNS.begin(hostname.c_str());
590 634
     updater.setup(&server);
591 635
     server.on("/", handleRoot);
636
+    
637
+#ifdef ENABLE_GPIO_TEST
638
+    server.on("/gpiotest", handleGpioTest);
639
+#endif // ENABLE_GPIO_TEST
640
+    
592 641
     server.begin();
593 642
     MDNS.addService("http", "tcp", 80);
594 643
     
@@ -618,6 +667,13 @@ void wifi_run() {
618 667
     if (millis() >= (6 * 60 * 60 * 1000)) {
619 668
         ESP.restart();
620 669
     }
670
+    
671
+#ifdef ENABLE_GPIO_TEST
672
+    if (runningGpioTest && ((millis() - lastGpioTime) >= GPIO_TEST_INTERVAL)) {
673
+        gpioTestState = !gpioTestState;
674
+        runGpioTest(gpioTestState);
675
+    }
676
+#endif // ENABLE_GPIO_TEST
621 677
 }
622 678
 
623 679
 #endif // PLATFORM_ESP

Loading…
Отказ
Запис