Debounce InterruptIn
Dependents: led_sigfox Allumag_lampe_sigfox Case_study_02_Turnstile B18_MP3_PLAYER ... more
Revision 14:da09706b92f5, committed 2014-02-18
- Comitter:
- kandangath
- Date:
- Tue Feb 18 17:26:42 2014 +0000
- Parent:
- 13:09b53a088a9c
- Child:
- 15:948e85b22efe
- Commit message:
- Also poll pin value at the end of the debounce period
Changed in this revision
DebouncedInterrupt.cpp | Show annotated file Show diff for this revision Revisions of this file |
DebouncedInterrupt.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/DebouncedInterrupt.cpp Tue Feb 18 16:51:44 2014 +0000 +++ b/DebouncedInterrupt.cpp Tue Feb 18 17:26:42 2014 +0000 @@ -8,10 +8,13 @@ DebouncedInterrupt::DebouncedInterrupt(PinName pin) { _in = new InterruptIn(pin); + _din = new DigitalIn(pin); } DebouncedInterrupt::~DebouncedInterrupt() { + delete _in; + delete _din; } void DebouncedInterrupt::attach(void (*fptr)(void), @@ -51,7 +54,9 @@ { _last_bounce_count = _bounce_count; _bounce_count = 0; - fCallback(); + if(_din) { + fCallback(); + } } void DebouncedInterrupt::_onInterrupt()
--- a/DebouncedInterrupt.h Tue Feb 18 16:51:44 2014 +0000 +++ b/DebouncedInterrupt.h Tue Feb 18 17:26:42 2014 +0000 @@ -36,6 +36,7 @@ private: unsigned int _debounce_us; InterruptIn *_in; + DigitalIn *_din; // Diagnostics volatile unsigned int _bounce_count;