InterruptIn style DigitalIn debounced with callbacks for pin state change and pin state hold. Fork of original https://os.mbed.com/users/AjK/code/PinDetect/ and modification for compatibility with MbedOS6+
Diff: PinDetect.h
- Revision:
- 3:911efbcb34b2
- Parent:
- 2:cb3afc45028b
diff -r cb3afc45028b -r 911efbcb34b2 PinDetect.h --- a/PinDetect.h Thu Jan 13 11:09:22 2011 +0000 +++ b/PinDetect.h Thu Jun 09 18:17:18 2022 +0000 @@ -140,10 +140,10 @@ int _samplesTillAssert; int _samplesTillHeldReload; int _samplesTillHeld; - FunctionPointer _callbackAsserted; - FunctionPointer _callbackDeasserted; - FunctionPointer _callbackAssertedHeld; - FunctionPointer _callbackDeassertedHeld; + Callback<void()> _callbackAsserted; + Callback<void()> _callbackDeasserted; + Callback<void()> _callbackAssertedHeld; + Callback<void()> _callbackDeassertedHeld; /** initialise class * @@ -205,7 +205,7 @@ void setSampleFrequency(int i = PINDETECT_SAMPLE_PERIOD) { _sampleTime = i; _prevState = _in->read(); - _ticker->attach_us( this, &PinDetect::isr, _sampleTime ); + _ticker->attach( callback(this, &PinDetect::isr), std::chrono::milliseconds(_sampleTime)); } /** Set the value used as assert. @@ -260,7 +260,7 @@ * @param function A C function pointer */ void attach_asserted(void (*function)(void)) { - _callbackAsserted.attach( function ); + _callbackAsserted = callback(function); } /** Attach a callback object/method @@ -288,7 +288,7 @@ */ template<typename T> void attach_asserted(T *object, void (T::*member)(void)) { - _callbackAsserted.attach( object, member ); + _callbackAsserted= callback(object, member); } /** Attach a callback function @@ -312,7 +312,7 @@ * @param function A C function pointer */ void attach_deasserted(void (*function)(void)) { - _callbackDeasserted.attach( function ); + _callbackDeasserted = callback(function); } /** Attach a callback object/method @@ -340,7 +340,7 @@ */ template<typename T> void attach_deasserted(T *object, void (T::*member)(void)) { - _callbackDeasserted.attach( object, member ); + _callbackDeasserted = callback(object, member); } /** Attach a callback function @@ -364,7 +364,7 @@ * @param function A C function pointer */ void attach_asserted_held(void (*function)(void)) { - _callbackAssertedHeld.attach( function ); + _callbackAssertedHeld = callback(function); } /** Attach a callback object/method @@ -392,7 +392,7 @@ */ template<typename T> void attach_asserted_held(T *object, void (T::*member)(void)) { - _callbackAssertedHeld.attach( object, member ); + _callbackAssertedHeld = callback(object, member); } /** Attach a callback function @@ -416,7 +416,7 @@ * @param function A C function pointer */ void attach_deasserted_held(void (*function)(void)) { - _callbackDeassertedHeld.attach( function ); + _callbackDeassertedHeld = callback(function); } /** Attach a callback object/method @@ -444,7 +444,7 @@ */ template<typename T> void attach_deasserted_held(T *object, void (T::*member)(void)) { - _callbackDeassertedHeld.attach( object, member ); + _callbackDeassertedHeld = callback(object, member); } /** operator int()