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 Demo Team

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers DoorTrip.cpp Source File

DoorTrip.cpp

00001 /*
00002     DoorTrip.cpp -  DoorTrip sensor library
00003     Developed by Andrea Corrado & Eric Gowland
00004     
00005     Connect to a hardware device that is boolean present/not present. Such as PIR, Rangefinder or laser with appropriate signalling.
00006     Also drives LED as DoorTrip indicator.
00007 */
00008 
00009 
00010 #include "mbed.h"
00011 #include "DoorTrip.h"
00012 
00013 
00014 
00015 DoorTrip::DoorTrip(PinName pin, bool true_on_rise, int debounce_time_ms):_myint(pin), _led1(LED1)
00016 {
00017     debounce_ms = debounce_time_ms;
00018     _true_on_rise = true_on_rise;
00019 //    if(true_on_rise) {
00020 //        _myint.rise(this, &DoorTrip::DoorTrip_interrupt_off);
00021 //        _myint.fall(this, &DoorTrip::DoorTrip_interrupt_on);
00022 //    } else {
00023 //        _myint.rise(this, &DoorTrip::DoorTrip_interrupt_on);
00024 //        _myint.fall(this, &DoorTrip::DoorTrip_interrupt_off);
00025 //    }
00026     _detection=false;
00027 //    debounce_timer.start();
00028     _led1=1;
00029 
00030 }
00031 
00032 void DoorTrip::DoorTrip_interrupt_off(){
00033     if(debounce_timer.read_ms() > debounce_ms) {
00034         _detection=false;
00035         _led1=1;
00036     }
00037 }
00038 
00039 void DoorTrip::DoorTrip_interrupt_on() //Detection of motion.
00040 {
00041     //Always trigger detection..
00042     _detection=true;
00043     _led1=0;
00044     debounce_timer.reset(); // Reset counter to 0...
00045 }
00046 
00047 bool DoorTrip::isPresent(){
00048 //    if (debounce_timer.read_ms() > debounce_ms) {
00049         //Poll the pin and update value...
00050         _detection = (_true_on_rise && _myint == 1) || (!_true_on_rise && _myint == 0);
00051         if(_detection) _led1 = 0; else _led1 = 1;
00052 //    }
00053     return !_detection;
00054 }