Driver for a binary on/off presence device
Diff: Presence.cpp
- Revision:
- 2:4ab67ace383b
- Parent:
- 0:21320a151be0
- Child:
- 3:c255f4943339
--- a/Presence.cpp Wed Dec 10 14:06:35 2014 +0000 +++ b/Presence.cpp Mon Feb 09 10:36:29 2015 +0000 @@ -24,7 +24,7 @@ // _myint.fall(this, &Presence::presence_interrupt_off); // } _detection=false; -// debounce_timer.start(); + debounce_timer.start(); _led1=1; } @@ -45,10 +45,12 @@ } 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