Driver for a binary on/off presence device

Dependents:   mbed-IBooth-ETH

Revision:
3:c255f4943339
Parent:
1:9d2b641a9280
Parent:
2:4ab67ace383b
Child:
4:ac5cfd7e90ea
--- a/Presence.cpp	Wed Feb 04 17:21:13 2015 +0000
+++ b/Presence.cpp	Mon Feb 09 10:55:13 2015 +0000
@@ -24,7 +24,7 @@
 //        _myint.fall(this, &presence::presence_interrupt_off);
 //    }
     _detection=false;
-//    debounce_timer.start();
+    debounce_timer.start();
     _led1=1;
 
 }
@@ -44,11 +44,14 @@
     debounce_timer.reset(); // Reset counter to 0...
 }
 
-bool presence::isPresent(){
-//    if (debounce_timer.read_ms() > debounce_ms) {
-        //Poll the pin and update value...
-        _detection = (_true_on_rise && _myint == 1) || (!_true_on_rise && _myint == 0);
+
+bool Presence::isPresent(){
+    bool new_detection = (_true_on_rise && _myint == 1) || (!_true_on_rise && _myint == 0);
+    if(new_detection)debounce_timer.reset();
+    //Poll the pin and update value...
+    if(!_detection || debounce_timer.read_ms() > debounce_ms) {
+        _detection = new_detection;
         if(_detection) _led1 = 0; else _led1 = 1;
-//    }
+    }
     return _detection;
 }
\ No newline at end of file