Quadrature encoder interface library.

Dependents:   Ex_econdercar_ROS

Fork of QEI by Aaron Berk

Revision:
1:a6bd3dee25b5
Parent:
0:5c2ad81551aa
--- 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;