Quadrature encoder interface library.
Fork of QEI by
Diff: QEI.cpp
- Revision:
- 1:a6bd3dee25b5
- Parent:
- 0:5c2ad81551aa
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;