napoleon leoni / DebounceIntRTOS

Fork of DebounceInt by napoleon leoni

Revision:
1:519b4ce3b082
Parent:
0:afa153f7249f
--- a/DebounceInt.cpp	Tue Feb 18 16:52:49 2014 +0000
+++ b/DebounceInt.cpp	Tue Feb 25 19:55:04 2014 +0000
@@ -23,26 +23,29 @@
     // Inputs:
     // PinName pin: Expected Proper Mbed Pin (e.g. p12), program will exit otherwise
         this->pinIntMask = new InterruptMask(pin);
-        this->setDelay(_DEBOUNCEINTDELAYDEFAULT);    
+        this->debounceCallBackRise = new RtosTimer(&DebounceInt::wrapperDebouncePinRise, osTimerOnce, this);
+        this->debounceCallBackFall = new RtosTimer(&DebounceInt::wrapperDebouncePinFall, osTimerOnce, this);
+        this->setDelay(_DEBOUNCEINTDELAYDEFAULT);
     }
-
+    
+    
 //Constructor with PinName and specified delay in micro-seconds
-    DebounceInt::DebounceInt(PinName pin,unsigned int delay_us){
+    DebounceInt::DebounceInt(PinName pin,unsigned int delay_ms){
     // Inputs:
     // PinName pin: Expected Proper Mbed Pin (e.g. p12), program will exit otherwise
     // unsigned int delay: Expected positive delay, will force delay to be larger
     // than minimum delay _MINDBOUNCEDELAY
         this->pinIntMask = new InterruptMask(pin);        
-        this->setDelay(delay_us);
+        this->setDelay(delay_ms);
     }
 
 //method to modify delay for debounce in us
-    void DebounceInt::setDelay(unsigned int delay_us){
+    void DebounceInt::setDelay(unsigned int delay_ms){
     // Inputs:
     // unsigned int delay: Expected positive delay, will force delay to be larger
     // than minimum delay _MINDBOUNCEDELAY
-        if(delay_us>(_MINDBOUNCEDELAY) ){
-            this->delay=delay_us;
+        if(delay_ms>(_MINDBOUNCEDELAY) ){
+            this->delay=delay_ms;
         } else { 
             this->delay=_MINDBOUNCEDELAY;
         }
@@ -51,9 +54,19 @@
 //method to be called within Interrupt Service Routine to debounce GPIO pin on rising edge
     void DebounceInt::debouncePinRise(void){
         this->pinIntMask->maskIntR();
-        this->debounceCallBack.attach_us(this,&DebounceInt::debounceCallbackPinRise,this->delay);
+        this->debounceCallBackRise->start(this->delay);
     }
     
+    void DebounceInt::wrapperDebouncePinRise(void const *ptr2Object){
+        DebounceInt* instance = (DebounceInt*) ptr2Object;    
+        instance->debounceCallbackPinRise();
+    }
+
+    void DebounceInt::wrapperDebouncePinFall(void const *ptr2Object){
+        DebounceInt* instance = (DebounceInt*) ptr2Object;    
+        instance->debounceCallbackPinFall();
+    }
+
 //internal callback used to re-enable (unmask) interrupts on rising edge
     void DebounceInt::debounceCallbackPinRise(void){
         this->pinIntMask->ClrInt();
@@ -63,7 +76,7 @@
 //method to be called within Interrupt Service Routine to debounce GPIO pin on falling edge
     void DebounceInt::debouncePinFall(void){
         this->pinIntMask->maskIntF();
-        this->debounceCallBack.attach_us(this,&DebounceInt::debounceCallbackPinFall,this->delay);
+        this->debounceCallBackFall->start(this->delay);
     }
     
 //internal callback used to re-enable (unmask) interrupts on falling edge