Driver for a binary on/off presence device
Diff: Presence.cpp
- Revision:
- 5:1d5ca464ac89
- Parent:
- 0:21320a151be0
- Child:
- 6:b1c665320f0c
--- a/Presence.cpp Wed Dec 10 14:06:35 2014 +0000 +++ b/Presence.cpp Mon Feb 09 16:33:52 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 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