diff --git a/src/utility/QEI/QEI.cpp b/src/utility/QEI/QEI.cpp index 22f32e4..db767db 100644 --- a/src/utility/QEI/QEI.cpp +++ b/src/utility/QEI/QEI.cpp @@ -152,7 +152,9 @@ QEI::QEI(PinName channelA, //X4 encoding uses interrupts on channel A, //and on channel B. channelA_.rise(mbed::callback(this, &QEI::encode)); - channelA_.fall(mbed::callback(this, &QEI::encode)); + if(encoding != X1_ENCODING){ + channelA_.fall(mbed::callback(this, &QEI::encode)); + } //If we're using X4 encoding, then attach interrupts to channel B too. if (encoding == X4_ENCODING) { @@ -191,6 +193,20 @@ int QEI::getRevolutions(void) { } +// +-------------+ +// | X1 Encoding | +// +-------------+ +// +// When observing states two patterns will appear: +// +// Counter clockwise rotation: +// +// 10 -> 10 -> 10 -> 10 -> ... +// +// Clockwise rotation: +// +// 11 -> 11 -> 11 -> ... +// // +-------------+ // | X2 Encoding | // +-------------+ @@ -243,8 +259,15 @@ void QEI::encode(void) { //2-bit state. currState_ = (chanA << 1) | (chanB); - - if (encoding_ == X2_ENCODING) { + + if(encoding_ == X1_ENCODING){ + if(currState_ == 0x3){ + pulses_++; + } + if(currState_ == 0x2){ + pulses_--; + } + } else if (encoding_ == X2_ENCODING) { //11->00->11->00 is counter clockwise rotation or "forward". if ((prevState_ == 0x3 && currState_ == 0x0) || diff --git a/src/utility/QEI/QEI.h b/src/utility/QEI/QEI.h index 5ab79d2..8e6fba0 100644 --- a/src/utility/QEI/QEI.h +++ b/src/utility/QEI/QEI.h @@ -148,7 +148,7 @@ class QEI { public: typedef enum Encoding { - + X1_ENCODING, X2_ENCODING, X4_ENCODING diff --git a/src/utility/ioexpander/ArduinoIOExpander.cpp b/src/utility/ioexpander/ArduinoIOExpander.cpp index 1aacf11..461e72e 100644 --- a/src/utility/ioexpander/ArduinoIOExpander.cpp +++ b/src/utility/ioexpander/ArduinoIOExpander.cpp @@ -103,6 +103,20 @@ void ArduinoIOExpanderClass::initPins() { if (_tca.getAddress() == IO_ADD) { + PinStatus status = SWITCH_OFF; + set(IO_WRITE_CH_PIN_00, status); + set(IO_WRITE_CH_PIN_01, status); + set(IO_WRITE_CH_PIN_02, status); + set(IO_WRITE_CH_PIN_03, status); + set(IO_WRITE_CH_PIN_04, status); + set(IO_WRITE_CH_PIN_05, status); + set(IO_WRITE_CH_PIN_06, status); + set(IO_WRITE_CH_PIN_07, status); + set(IO_WRITE_CH_PIN_08, status); + set(IO_WRITE_CH_PIN_09, status); + set(IO_WRITE_CH_PIN_10, status); + set(IO_WRITE_CH_PIN_11, status); + pinMode(IO_WRITE_CH_PIN_00, OUTPUT); pinMode(IO_WRITE_CH_PIN_01, OUTPUT); pinMode(IO_WRITE_CH_PIN_02, OUTPUT);