Diff: QEI.cpp
- Revision:
- 3:66f6b5f3a911
- Parent:
- 1:51cd1936ffec
- Child:
- 4:bfe9aec45bb7
--- a/QEI.cpp Sat Aug 17 14:55:49 2019 +0200 +++ b/QEI.cpp Sat Aug 17 21:30:45 2019 +0200 @@ -128,10 +128,10 @@ */ #include "QEI.h" -QEI::QEI(PinName channelA, +QEI::QEI(int pulsesPerRev, + PinName channelA, PinName channelB, PinName index, - int pulsesPerRev, Encoding encoding) : channelA_(channelA), channelB_(channelB), index_(index) { @@ -141,21 +141,17 @@ encoding_ = encoding; channelA_.mode(PullUp); - channelB_.mode(PullUp); //Workout what the current state is. - int chanA = channelA_.read(); - int chanB = channelB_.read(); - - //2-bit state. - currState_ = (chanA << 1) | (chanB); - prevState_ = currState_; + currState_ = channelA_.read(); + + //X2 encoding uses interrupts on only channel A. //X4 encoding uses interrupts on channel A, //and on channel B. - channelA_.rise(this, &QEI::encode); - channelA_.fall(this, &QEI::encode); + channelA_.rise(this, &QEI::pulse); + // channelA_.fall(this, &QEI::pulse); //If we're using X4 encoding, then attach interrupts to channel B too. if (encoding == X4_ENCODING) { @@ -178,7 +174,7 @@ int QEI::getCurrentState(void) { - return currState_; + return channelA_.read();; } @@ -194,6 +190,12 @@ } +void QEI::pulse() { + + pulses_++; + +} + // +-------------+ // | X2 Encoding | // +-------------+