Fork of mRotaryEncoder for mdeb-os. uses newer version of PinDetect. Testprogram: https://os.mbed.com/users/charly/code/mRotaryEncoder_HelloWorld-os/
Dependents: mRotaryEncoder_HelloWorld-os TMC2209-Test2
Diff: mRotaryEncoder.h
- Revision:
- 12:1925aac090b7
- Parent:
- 11:24b34deae975
diff -r 24b34deae975 -r 1925aac090b7 mRotaryEncoder.h --- a/mRotaryEncoder.h Tue Mar 03 12:20:55 2020 +0000 +++ b/mRotaryEncoder.h Tue Mar 16 20:19:04 2021 +0000 @@ -46,8 +46,8 @@ * @param pinSW Pin for push-button switch * @param pullmode mode for pinA pinB and pinSW like DigitalIn.mode * @param debounceTime_us time in micro-seconds to wait for bouncing of mechanical switches to end - * @param detectRise Detect rise event as new rotation - * @param detectFall Detect fall event as new rotation + * @param detectRise Detect rise event as new rotation. default 1 + * @param detectFall Detect fall event as new rotation. default 1 */ mRotaryEncoder(PinName pinA, PinName pinB, PinName pinSW, PinMode pullMode=PullUp, int debounceTime_us=1000, int detectRise=1, int detectFall=1); @@ -80,74 +80,75 @@ * * keep this function short, as no interrrupts can occour within * - * @param fptr Pointer to callback-function + * @param cb callback-function */ - void attachSW(void (*fptr)(void)) { - m_pinSW->attach_deasserted(fptr); + void attachSW(Callback<void()> cb) { + m_pinSW->attach_deasserted(cb); } - template<typename T> +// template<typename T> /** attach an object member function to be called when switch is pressed * * @param tptr pointer to object * @param mprt pointer ro member function * */ - void attachSW(T* tptr, void (T::*mptr)(void)) { +/* void attachSW(T* tptr, void (T::*mptr)(void)) { if ((mptr != NULL) && (tptr != NULL)) { m_pinSW->attach_deasserted(tptr, mptr); } } - +*/ /** callback-System for rotation of shaft * * attach a function to be called when the shaft is rotated * keep this function short, as no interrrupts can occour within * - * @param fprt Pointer to callback-function + * @param cb callback-function */ - void attachROT(void (*fptr)(void)) { - rotIsr.attach(fptr); + void attachROT(Callback<void()> cb) { + rotIsr = cb; } - template<typename T> +// template<typename T> /** attach an object member function to be called when shaft is rotated * * @param tptr pointer to object * @param mprt pointer ro member function * */ - void attachROT(T* tptr, void (T::*mptr)(void)) { +/* void attachROT(T* tptr, void (T::*mptr)(void)) { if ((mptr != NULL) && (tptr != NULL)) { rotIsr.attach(tptr, mptr); } } - +*/ /** callback-System for rotation of shaft CW * * attach a function to be called when the shaft is rotated clockwise * keep this function short, as no interrrupts can occour within * - * @param fprt Pointer to callback-function + * @param cb callback-function */ - void attachROTCW(void (*fptr)(void)) { - rotCWIsr.attach(fptr); + void attachROTCW(Callback<void()> cb) { + rotCWIsr = cb; } - template<typename T> +// template<typename T> /** attach an object member function to be called when shaft is rotated clockwise * * @param tptr pointer to object * @param mprt pointer ro member function * */ - void attachROTCW(T* tptr, void (T::*mptr)(void)) { +/* void attachROTCW(T* tptr, void (T::*mptr)(void)) { if ((mptr != NULL) && (tptr != NULL)) { rotCWIsr.attach(tptr, mptr); } } +*/ /** callback-System for rotation of shaft CCW * @@ -156,23 +157,24 @@ * * @param fprt Pointer to callback-function */ - void attachROTCCW(void (*fptr)(void)) { - rotCCWIsr.attach(fptr); + void attachROTCCW(Callback<void()> cb) { + rotCCWIsr = cb; } - template<typename T> +// template<typename T> /** attach an object member function to be called when shaft is rotated CCW * * @param tptr pointer to object * @param mprt pointer ro member function * */ - void attachROTCCW(T* tptr, void (T::*mptr)(void)) { +/* void attachROTCCW(T* tptr, void (T::*mptr)(void)) { if ((mptr != NULL) && (tptr != NULL)) { rotCCWIsr.attach(tptr, mptr); } } +*/ private: PinDetect *m_pinA; @@ -195,16 +197,16 @@ /** * rotated any direction */ - FunctionPointer rotIsr; + Callback<void()> rotIsr; /** * clockwise rotated */ - FunctionPointer rotCWIsr; + Callback<void()> rotCWIsr; /** * counterclockwise rotated */ - FunctionPointer rotCCWIsr; + Callback<void()> rotCCWIsr; };