Quadrature encoder interface library.

Dependents:   Ex_econdercar_ROS

Fork of QEI by Aaron Berk

Files at this revision

API Documentation at this revision

Comitter:
brainliang
Date:
Sun May 06 05:56:03 2018 +0000
Parent:
0:5c2ad81551aa
Commit message:
asdf

Changed in this revision

QEI.cpp Show annotated file Show diff for this revision Revisions of this file
QEI.h Show annotated file Show diff for this revision Revisions of this file
diff -r 5c2ad81551aa -r a6bd3dee25b5 QEI.cpp
--- a/QEI.cpp	Thu Sep 02 16:48:55 2010 +0000
+++ b/QEI.cpp	Sun May 06 05:56:03 2018 +0000
@@ -191,6 +191,11 @@
 
 }
 
+//获取旋转方向函数
+int QEI::getState(void)
+{
+    return state_;
+}
 // +-------------+
 // | X2 Encoding |
 // +-------------+
@@ -249,14 +254,14 @@
         //11->00->11->00 is counter clockwise rotation or "forward".
         if ((prevState_ == 0x3 && currState_ == 0x0) ||
                 (prevState_ == 0x0 && currState_ == 0x3)) {
-
+            state_ = 1;
             pulses_++;
 
         }
         //10->01->10->01 is clockwise rotation or "backward".
         else if ((prevState_ == 0x2 && currState_ == 0x1) ||
                  (prevState_ == 0x1 && currState_ == 0x2)) {
-
+            state_ = -1;
             pulses_--;
 
         }
@@ -271,6 +276,11 @@
 
             if (change == 0) {
                 change = -1;
+                state_ = -1;
+            }
+            else 
+            {
+                state_ = 1;
             }
 
             pulses_ -= change;
diff -r 5c2ad81551aa -r a6bd3dee25b5 QEI.h
--- a/QEI.h	Thu Sep 02 16:48:55 2010 +0000
+++ b/QEI.h	Sun May 06 05:56:03 2018 +0000
@@ -207,7 +207,8 @@
      * @return Number of revolutions which have occured on the index channel.
      */
     int getRevolutions(void);
-
+    
+    int getState(void);
 private:
 
     /**
@@ -235,7 +236,8 @@
     int          pulsesPerRev_;
     int          prevState_;
     int          currState_;
-
+    int          state_; 
+    
     volatile int pulses_;
     volatile int revolutions_;