From 4bb3eba50f61cc7f57d0ad279ab310ea5368a88d Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Tue, 22 Nov 2011 20:02:31 +0000 Subject: [PATCH] added ajar sensor to door firmware --- firmware/tuer.pde | 40 +++++++++++++++++++++++++++++++++------- track-presence.py | 2 +- 2 files changed, 34 insertions(+), 8 deletions(-) diff --git a/firmware/tuer.pde b/firmware/tuer.pde index 0f2246c..c4bfcb4 100644 --- a/firmware/tuer.pde +++ b/firmware/tuer.pde @@ -20,6 +20,8 @@ byte next_led = 0; #define LIMIT_OPENED_PIN 18 // A4: limit switch for open #define LIMIT_CLOSED_PIN 19 // A5: limit switch for close +#define AJAR_PIN 14 // input pin for reed relais (door ajar/shut) + #define MANUAL_OPEN_PIN 12 // keys for manual open and close #define MANUAL_CLOSE_PIN 13 // #define DEBOUNCE_DELAY 6250 // * 16us = 100ms @@ -77,6 +79,22 @@ boolean is_closed() //**********// +void init_ajar() +{ + pinMode(AJAR_PIN, INPUT); // set pin to input + digitalWrite(AJAR_PIN, HIGH); // turn on pullup resistors +} + +boolean get_ajar_status() // shut = true, ajar = false +{ + if(digitalRead(AJAR_PIN)) + return false; + + return true; +} + +//**********// + void init_manual() { pinMode(MANUAL_OPEN_PIN, INPUT); // set pin to input @@ -369,7 +387,11 @@ ISR(TIMER1_COMPA_vect) Serial.print("opened"); else if(is_closed()) Serial.print("closed"); - Serial.println(", idle"); + Serial.print(", idle"); + if(get_ajar_status()) + Serial.println(", shut"); + else + Serial.println(", ajar"); return; } else if(current_state == ERROR) { @@ -493,13 +515,16 @@ void print_status() Serial.print("<->"); switch(current_state) { - case IDLE: Serial.println(", idle"); break; - case OPENING: Serial.println(", opening"); break; - case CLOSING: Serial.println(", closing"); break; - case WAIT: Serial.println(", waiting"); break; - default: Serial.println(", "); break; + case IDLE: Serial.print(", idle"); break; + case OPENING: Serial.print(", opening"); break; + case CLOSING: Serial.print(", closing"); break; + case WAIT: Serial.print(", waiting"); break; + default: Serial.print(", "); break; } - + if(get_ajar_status()) + Serial.println(", shut"); + else + Serial.println(", ajar"); } //**********// @@ -507,6 +532,7 @@ void print_status() void setup() { init_limits(); + init_ajar(); init_stepper(); init_leds(); init_heartbeat(); diff --git a/track-presence.py b/track-presence.py index 47d7577..03b1447 100755 --- a/track-presence.py +++ b/track-presence.py @@ -214,7 +214,7 @@ door_socklock=threading.Lock() def trackDoorStatusThread(uwscfg, status_tracker,connection_listener): global door_sockhandle, door_socklock, threads_running #socket.setdefaulttimeout(10.0) #affects all new Socket Connections (urllib as well) - RE_STATUS = re.compile(r'Status: (\w+), idle',re.I) + RE_STATUS = re.compile(r'Status: (\w+), idle.*',re.I) RE_REQUEST = re.compile(r'Request: (\w+) (?:(Card|Phone) )?(.+)',re.I) RE_ERROR = re.compile(r'Error: (.+)',re.I) while threads_running: -- 1.7.10.4