Improvement to the DebounceInt library providing an easier to use interface much more alike the usual InterrupIn interface

Fork of DebounceInt by napoleon leoni

Revision:
3:3b5c7faadd5c
Parent:
2:bd5a3171ebc4
--- a/DebounceInt2.cpp	Tue Feb 25 06:37:35 2014 +0000
+++ b/DebounceInt2.cpp	Tue Feb 25 07:53:23 2014 +0000
@@ -53,15 +53,25 @@
 // Inputs: *fhandler(void), pointer to handler function which must be void *fhandler(void)                                                                               //
 //**********************************************************************************************//
 
-    void DebounceInt2::rise(t_fhandler fhandler){     //attach interrupt handler for interrupt on rising edge
+    void DebounceInt2::rise(FunctionPointer fhandler){     //attach interrupt handler for interrupt on rising edge
     
         if(!(this->intRise)){//only allocate the pointer and Interrupt in once
             this->intRise= new InterruptIn(this->pin);
         }
-        this->riseHandler=fhandler;
+        this->riseHandler = new FunctionPointer(fhandler);
         this->intRise->rise(this,&DebounceInt2::debouncePinRise); //This attaches our handler which 
                                                                     //includes the debounce functionality                                                                
     }
+
+    template<typename T>
+    void rise(T* tptr, void (T::*mptr)(void)){
+        if(!(this->intRise)){//only allocate the pointer and Interrupt in once
+            this->intRise= new InterruptIn(this->pin);
+        }
+        this->riseHandler = new FunctionPointer(tptr,mptr);
+        this->intRise->rise(this,&DebounceInt2::debouncePinRise);
+    }
+
     
     void DebounceInt2::disableRise(void){         //rise interrupt handler for rising edge
         this->pinIntMask->maskIntR();
@@ -69,16 +79,27 @@
     void DebounceInt2::enableRise(void){          //unmask rise interrupt handler for rising edge
         this->pinIntMask->unMaskIntR();    
     }
-    void DebounceInt2::fall(t_fhandler fhandler){     //attach interrupt handler for interrupt on falling edge
+
+    void DebounceInt2::fall(FunctionPointer fhandler){     //attach interrupt handler for interrupt on falling edge
     
         if(!(this->intFall)){//only allocate the pointer and Interrupt in once
             this->intFall= new InterruptIn(this->pin);
         }
-        this->fallHandler=fhandler;
+        this->fallHandler = new FunctionPointer(fhandler);
         this->intFall->fall(this,&DebounceInt2::debouncePinFall); //This attaches our handler which 
                                                                     //includes the debounce functionality                                                                
     
     }
+
+    template<typename T>
+    void fall(T* tptr, void (T::*mptr)(void)){
+        if(!(this->Fall)){//only allocate the pointer and Interrupt in once
+            this->intFall= new InterruptIn(this->pin);
+        }
+        this->fallHandler = new FunctionPointer(tptr,mptr);
+        this->intFall->fall(this,&DebounceInt2::debouncePinRise);
+    }
+
     void DebounceInt2::disableFall(void){         //mask fall interrupt handler for rising edge
         this->pinIntMask->maskIntF();    
     }
@@ -91,7 +112,7 @@
     void DebounceInt2::debouncePinRise(void){
         this->pinIntMask->maskIntR();
         this->debounceCallBack.attach_us(this,&DebounceInt2::debounceCallbackPinRise,this->delay);
-        this->riseHandler();
+        this->riseHandler->call();
     }
     
 //internal callback used to re-enable (unmask) interrupts on rising edge
@@ -104,7 +125,7 @@
     void DebounceInt2::debouncePinFall(void){
         this->pinIntMask->maskIntF();
         this->debounceCallBack.attach_us(this,&DebounceInt2::debounceCallbackPinFall,this->delay);
-        this->fallHandler();
+        this->fallHandler->call();
     }
     
 //internal callback used to re-enable (unmask) interrupts on falling edge