dsf

Dependents:   Ex_3Dprinter_copy

Fork of QEI by Aaron Berk

Files at this revision

API Documentation at this revision

Comitter:
brainliang
Date:
Tue May 08 01:19:07 2018 +0000
Parent:
0:5c2ad81551aa
Child:
2:3753789f4288
Commit message:
fads

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
--- a/QEI.cpp	Thu Sep 02 16:48:55 2010 +0000
+++ b/QEI.cpp	Tue May 08 01:19:07 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;
--- a/QEI.h	Thu Sep 02 16:48:55 2010 +0000
+++ b/QEI.h	Tue May 08 01:19:07 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_;