Improvement to the DebounceInt library providing an easier to use interface much more alike the usual InterrupIn interface
Fork of DebounceInt by
Diff: DebounceInt2.h
- Revision:
- 2:bd5a3171ebc4
- Parent:
- 1:3e9de727a215
- Child:
- 3:3b5c7faadd5c
diff -r 3e9de727a215 -r bd5a3171ebc4 DebounceInt2.h --- a/DebounceInt2.h Tue Feb 25 05:07:21 2014 +0000 +++ b/DebounceInt2.h Tue Feb 25 06:37:35 2014 +0000 @@ -38,29 +38,35 @@ #include "mbed.h" #include "InterruptMask.h" -#ifndef DebounceInt2 -#define DebounceInt2 +#ifndef DebounceInt2Exclude +#define DebounceInt2Exclude #define _DEBOUNCEINTDELAYDEFAULT 50000 //useconds, this number would be about 50 ms -#define _MINDBOUNCEDELAY 5 -class DebounceInt2{ +#define _MINDBOUNCEDELAY 50 + +typedef void (*t_fhandler)(void); + +class DebounceInt2 +{ public://members private://members InterruptMask* pinIntMask; //Internal InterruptMask object unsigned int delay; //this is the debounce delay, during which the interrupt in question is masked Timeout debounceCallBack; - InterruptIn *intRise,*intFall; + InterruptIn* intRise; + InterruptIn* intFall; bool riseAttached,fallAttached; - void *riseHandler(void),*fallHandler(void); + t_fhandler riseHandler,fallHandler; + PinName pin; public://methods DebounceInt2(); //Default constructor, required but not to be used, will yield error and exit. DebounceInt2(PinName pin);//Constructor with PinName, delay will remain default value DebounceInt2(PinName pin,unsigned int delay_us);//Constructor with PinName and specified delay in micro-seconds void setDelay(unsigned int); //method to modify delay for debounce in us - void attachRise(*fhandler); //attach interrupt handler for interrupt on rising edge + void rise(t_fhandler); //attach interrupt handler for interrupt on rising edge void disableRise(void); //rise interrupt handler for rising edge void enableRise(void); //unmask rise interrupt handler for rising edge - void attachFall(*fhandler); //attach interrupt handler for interrupt on falling edge + void fall(t_fhandler); //attach interrupt handler for interrupt on falling edge void disableFall(void); //mask fall interrupt handler for rising edge void enableFall(void); //unmask fall interrupt handler for rising edge