summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--martin/door/src/main.cpp23
1 files changed, 18 insertions, 5 deletions
diff --git a/martin/door/src/main.cpp b/martin/door/src/main.cpp
index 38146e4..5b1efad 100644
--- a/martin/door/src/main.cpp
+++ b/martin/door/src/main.cpp
@@ -2,6 +2,7 @@
2#include <WiFiManager.h> 2#include <WiFiManager.h>
3#include <ESP8266mDNS.h> 3#include <ESP8266mDNS.h>
4#include <ESP8266WebServer.h> 4#include <ESP8266WebServer.h>
5#include <ping.h>
5 6
6#include "cc1101.h" 7#include "cc1101.h"
7#include "hcs200.h" 8#include "hcs200.h"
@@ -17,6 +18,10 @@ CC1101 radio(D0 /* GDO0 */, D2 /* GDO2 */, D8 /* SS */);
17//#define HCS200_TEST 18//#define HCS200_TEST
18HCS200 hcs200; 19HCS200 hcs200;
19 20
21const int ping_delay = 60000;
22long ping_last = 0;
23ping_option ping_opt;
24
20void setup() 25void setup()
21{ 26{
22 Serial.begin(9600); 27 Serial.begin(9600);
@@ -62,12 +67,16 @@ void setup()
62 }); 67 });
63 http_service.begin(); 68 http_service.begin();
64 69
70 memset(&ping_opt, 0, sizeof(struct ping_option));
71 ping_opt.count = 1;
72 ping_opt.ip = WiFi.localIP();
73
65 Serial.println("Started listening"); 74 Serial.println("Started listening");
66} 75}
67 76
68void ICACHE_RAM_ATTR on_hcs200_isr() 77void ICACHE_RAM_ATTR on_hcs200_isr()
69{ 78{
70 hcs200.on_isr(digitalRead(PIN_HCS200_DATA)); 79 hcs200.on_isr(digitalRead(PIN_HCS200_DATA) == HIGH);
71} 80}
72 81
73bool hcs200_get_keycode(HCS200_Keycode &keycode) 82bool hcs200_get_keycode(HCS200_Keycode &keycode)
@@ -82,6 +91,7 @@ bool hcs200_get_keycode(HCS200_Keycode &keycode)
82 if (hcs200.decode(keycode)) 91 if (hcs200.decode(keycode))
83 break; 92 break;
84 delay(1); 93 delay(1);
94 yield();
85 } 95 }
86 digitalWrite(PIN_HCS200_ENABLE, LOW); 96 digitalWrite(PIN_HCS200_ENABLE, LOW);
87 detachInterrupt(digitalPinToInterrupt(PIN_HCS200_DATA)); 97 detachInterrupt(digitalPinToInterrupt(PIN_HCS200_DATA));
@@ -114,7 +124,6 @@ void http_door_open()
114 Serial.print("Got keycode: "); 124 Serial.print("Got keycode: ");
115 keycode.print(Serial); 125 keycode.print(Serial);
116 126
117
118 if (http_service.hasArg("power")) 127 if (http_service.hasArg("power"))
119 { 128 {
120 static const uint8_t patable_power_n30[8] = { 0x00, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; 129 static const uint8_t patable_power_n30[8] = { 0x00, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
@@ -215,13 +224,17 @@ void loop()
215 MDNS.update(); 224 MDNS.update();
216 http_service.handleClient(); 225 http_service.handleClient();
217 226
218#if 0 227 if (millis() - ping_last > ping_delay)
228 {
229 ping_start(&ping_opt);
230 ping_last = millis();
231 }
232
219 if (Serial.available() > 0) 233 if (Serial.available() > 0)
220 { 234 {
221 while (Serial.read() >= 0) {} 235 while (Serial.read() >= 0) {}
222 serial_door_open(Serial); 236 //serial_door_open(Serial);
223 } 237 }
224#endif
225 238
226 delay(1); 239 delay(1);
227} 240}