Class mRotaryEncoder for mechanical incremental rotary encoders with pushbuttons. Use debouncing and callback-functions for rotation and pressing of button. This version is for old mbed. New version for mbed-os see https://os.mbed.com/users/charly/code/mRotaryEncoder-os/

Dependencies:   PinDetect

Dependents:   SimplePIDBot FinalProgram VS1053Player SPK-DVIMXR ... more

Files at this revision

API Documentation at this revision

Comitter:
charly
Date:
Wed Mar 11 21:45:46 2015 +0000
Parent:
6:854c349157b0
Child:
8:41c44b127443
Commit message:
Added FunctionPointers and Methodes for clockwise(CW) rotation and counterclockwise(CCW) rotation

Changed in this revision

mRotaryEncoder.cpp Show annotated file Show diff for this revision Revisions of this file
mRotaryEncoder.h Show annotated file Show diff for this revision Revisions of this file
--- a/mRotaryEncoder.cpp	Wed Mar 11 21:08:31 2015 +0000
+++ b/mRotaryEncoder.cpp	Wed Mar 11 21:45:46 2015 +0000
@@ -52,8 +52,10 @@
     if (*m_pinA == 0) {
         if (*m_pinB == 1) {
             m_position++;
+            rotCWIsr.call();
         } else {
             m_position--;
+            rotCCWIsr.call();
         }
     }
     rotIsr.call();                        // call the isr for rotation
@@ -65,8 +67,10 @@
     if (*m_pinA == 1) {
         if (*m_pinB == 1) {
             m_position--;
+            rotCCWIsr.call();
         } else {
             m_position++;
+            rotCWIsr.call();
         }
     }
     rotIsr.call();                        // call the isr for rotation
--- 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;
 
 
 };