Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: mRotaryEncoder.h
- Revision:
- 7:ec80fd9c0c08
- Parent:
- 6:854c349157b0
- Child:
- 8:41c44b127443
--- a/mRotaryEncoder.h	Wed Mar 11 21:08:31 2015 +0000
+++ b/mRotaryEncoder.h	Wed Mar 11 21:45:46 2015 +0000
@@ -74,6 +74,7 @@
     }
 
     /** attach a function to be called when switch is pressed
+    *
     * keep this function short, as no interrrupts can occour within
     *
     * @param fptr Pointer to callback-function
@@ -96,7 +97,8 @@
     }
 
     /**  callback-System for rotation of shaft
-    * attach a function to be called when the shaft is rotaded
+    *
+    *  attach a function to be called when the shaft is rotaded
     *  keep this function short, as no interrrupts can occour within
     *
     * @param fprt Pointer to callback-function
@@ -119,6 +121,55 @@
         }
     }
 
+   /**  callback-System for rotation of shaft CW
+    *
+    *  attach a function to be called when the shaft is rotaded clockwise
+    *  keep this function short, as no interrrupts can occour within
+    *
+    * @param fprt Pointer to callback-function
+    */
+    void attachROTCW(void (*fptr)(void)) {
+        rotCWIsr.attach(fptr);
+    }
+
+
+    template<typename T>
+    /** attach an object member function to be called when shaft is rotaded clockwise
+    *
+    * @param tptr pointer to object
+    * @param mprt pointer ro member function
+    *
+    */
+    void attachROTCW(T* tptr, void (T::*mptr)(void)) {
+        if ((mptr != NULL) && (tptr != NULL)) {
+            rotCWIsr.attach(tptr, mptr);
+        }
+    }
+
+   /**  callback-System for rotation of shaft CCW
+    *
+    *  attach a function to be called when the shaft is rotaded counterclockwise
+    *  keep this function short, as no interrrupts can occour within
+    *
+    * @param fprt Pointer to callback-function
+    */
+    void attachROTCCW(void (*fptr)(void)) {
+        rotCCWIsr.attach(fptr);
+    }
+
+
+    template<typename T>
+    /** attach an object member function to be called when shaft is rotaded CCW
+    *
+    * @param tptr pointer to object
+    * @param mprt pointer ro member function
+    *
+    */
+    void attachROTCCW(T* tptr, void (T::*mptr)(void)) {
+        if ((mptr != NULL) && (tptr != NULL)) {
+            rotCCWIsr.attach(tptr, mptr);
+        }
+    }    
 
 private:
     PinDetect       *m_pinA;
@@ -138,7 +189,12 @@
       * Callback system.
       * @ingroup INTERNALS
       */
+    // rotated any direction
     FunctionPointer rotIsr;
+    // clockwise rotated
+    FunctionPointer rotCWIsr;
+    //counterclockwise rotated
+    FunctionPointer rotCCWIsr;
 
 
 };