InterruptIn style DigitalIn debounced with callbacks for pin state change and pin state hold.
Fork of PinDetect by
Diff: PinDetect.h
- Revision:
- 3:cf12ac7d8d50
- Parent:
- 2:cb3afc45028b
--- a/PinDetect.h Thu Jan 13 11:09:22 2011 +0000 +++ b/PinDetect.h Sun Sep 20 21:22:54 2015 +0000 @@ -140,6 +140,7 @@ int _samplesTillAssert; int _samplesTillHeldReload; int _samplesTillHeld; + bool _holdRepeat; FunctionPointer _callbackAsserted; FunctionPointer _callbackDeasserted; FunctionPointer _callbackAssertedHeld; @@ -157,7 +158,7 @@ _samplesTillAssertReload = PINDETECT_ASSERT_COUNT; _samplesTillHeldReload = PINDETECT_HOLD_COUNT; _assertValue = PINDETECT_PIN_ASSTERED; - + _holdRepeat = false; _in = new DigitalIn( p ); _in->mode( m ); _prevState = _in->read(); @@ -172,13 +173,13 @@ /** PinDetect constructor * - * By default the PinMode is set to PullDown. + * By default the PinMode is set to PullDefault. * * @see http://mbed.org/handbook/DigitalIn * @param p PinName is a valid pin that supports DigitalIn */ PinDetect(PinName p) { - init( p, PullDown ); + init( p, PullDefault ); } /** PinDetect constructor @@ -198,6 +199,13 @@ if ( _in ) delete( _in ); } + /** Set whether hold callback is repeatedly invoked while held. + * + * @param bool true to repeat callback, false to call back only once + */ + void setHoldRepeat(bool repeat) { + _holdRepeat = repeat; + } /** Set the sampling time in microseconds. * * @param int The time between pin samples in microseconds. @@ -484,6 +492,9 @@ _callbackAssertedHeld.call(); else _callbackDeassertedHeld.call(); + if(_holdRepeat) { + _samplesTillHeld = _samplesTillHeldReload; + } } } else {