mbed Sensor node for Instrumented Booth over ETH.
Dependencies: EthernetInterface-1 MaxbotixDriver Presence HTU21D_TEMP_HUMID_SENSOR_SAMPLE Resources SHARPIR mbed-rtos mbed-src WDT_K64F nsdl_lib
Fork of Trenton_Switch_LPC1768_ETH by
Door_Trip/DoorTrip.cpp@40:b2e9bc654ca1, 2015-02-11 (annotated)
- Committer:
- andcor02
- Date:
- Wed Feb 11 12:36:45 2015 +0000
- Revision:
- 40:b2e9bc654ca1
Working Set for long distance door
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
andcor02 | 40:b2e9bc654ca1 | 1 | /* |
andcor02 | 40:b2e9bc654ca1 | 2 | DoorTrip.cpp - DoorTrip sensor library |
andcor02 | 40:b2e9bc654ca1 | 3 | Developed by Andrea Corrado & Eric Gowland |
andcor02 | 40:b2e9bc654ca1 | 4 | |
andcor02 | 40:b2e9bc654ca1 | 5 | Connect to a hardware device that is boolean present/not present. Such as PIR, Rangefinder or laser with appropriate signalling. |
andcor02 | 40:b2e9bc654ca1 | 6 | Also drives LED as DoorTrip indicator. |
andcor02 | 40:b2e9bc654ca1 | 7 | */ |
andcor02 | 40:b2e9bc654ca1 | 8 | |
andcor02 | 40:b2e9bc654ca1 | 9 | |
andcor02 | 40:b2e9bc654ca1 | 10 | #include "mbed.h" |
andcor02 | 40:b2e9bc654ca1 | 11 | #include "DoorTrip.h" |
andcor02 | 40:b2e9bc654ca1 | 12 | |
andcor02 | 40:b2e9bc654ca1 | 13 | |
andcor02 | 40:b2e9bc654ca1 | 14 | |
andcor02 | 40:b2e9bc654ca1 | 15 | DoorTrip::DoorTrip(PinName pin, bool true_on_rise, int debounce_time_ms):_myint(pin), _led1(LED1) |
andcor02 | 40:b2e9bc654ca1 | 16 | { |
andcor02 | 40:b2e9bc654ca1 | 17 | debounce_ms = debounce_time_ms; |
andcor02 | 40:b2e9bc654ca1 | 18 | _true_on_rise = true_on_rise; |
andcor02 | 40:b2e9bc654ca1 | 19 | // if(true_on_rise) { |
andcor02 | 40:b2e9bc654ca1 | 20 | // _myint.rise(this, &DoorTrip::DoorTrip_interrupt_off); |
andcor02 | 40:b2e9bc654ca1 | 21 | // _myint.fall(this, &DoorTrip::DoorTrip_interrupt_on); |
andcor02 | 40:b2e9bc654ca1 | 22 | // } else { |
andcor02 | 40:b2e9bc654ca1 | 23 | // _myint.rise(this, &DoorTrip::DoorTrip_interrupt_on); |
andcor02 | 40:b2e9bc654ca1 | 24 | // _myint.fall(this, &DoorTrip::DoorTrip_interrupt_off); |
andcor02 | 40:b2e9bc654ca1 | 25 | // } |
andcor02 | 40:b2e9bc654ca1 | 26 | _detection=false; |
andcor02 | 40:b2e9bc654ca1 | 27 | // debounce_timer.start(); |
andcor02 | 40:b2e9bc654ca1 | 28 | _led1=1; |
andcor02 | 40:b2e9bc654ca1 | 29 | |
andcor02 | 40:b2e9bc654ca1 | 30 | } |
andcor02 | 40:b2e9bc654ca1 | 31 | |
andcor02 | 40:b2e9bc654ca1 | 32 | void DoorTrip::DoorTrip_interrupt_off(){ |
andcor02 | 40:b2e9bc654ca1 | 33 | if(debounce_timer.read_ms() > debounce_ms) { |
andcor02 | 40:b2e9bc654ca1 | 34 | _detection=false; |
andcor02 | 40:b2e9bc654ca1 | 35 | _led1=1; |
andcor02 | 40:b2e9bc654ca1 | 36 | } |
andcor02 | 40:b2e9bc654ca1 | 37 | } |
andcor02 | 40:b2e9bc654ca1 | 38 | |
andcor02 | 40:b2e9bc654ca1 | 39 | void DoorTrip::DoorTrip_interrupt_on() //Detection of motion. |
andcor02 | 40:b2e9bc654ca1 | 40 | { |
andcor02 | 40:b2e9bc654ca1 | 41 | //Always trigger detection.. |
andcor02 | 40:b2e9bc654ca1 | 42 | _detection=true; |
andcor02 | 40:b2e9bc654ca1 | 43 | _led1=0; |
andcor02 | 40:b2e9bc654ca1 | 44 | debounce_timer.reset(); // Reset counter to 0... |
andcor02 | 40:b2e9bc654ca1 | 45 | } |
andcor02 | 40:b2e9bc654ca1 | 46 | |
andcor02 | 40:b2e9bc654ca1 | 47 | bool DoorTrip::isPresent(){ |
andcor02 | 40:b2e9bc654ca1 | 48 | // if (debounce_timer.read_ms() > debounce_ms) { |
andcor02 | 40:b2e9bc654ca1 | 49 | //Poll the pin and update value... |
andcor02 | 40:b2e9bc654ca1 | 50 | _detection = (_true_on_rise && _myint == 1) || (!_true_on_rise && _myint == 0); |
andcor02 | 40:b2e9bc654ca1 | 51 | if(_detection) _led1 = 0; else _led1 = 1; |
andcor02 | 40:b2e9bc654ca1 | 52 | // } |
andcor02 | 40:b2e9bc654ca1 | 53 | return !_detection; |
andcor02 | 40:b2e9bc654ca1 | 54 | } |