Skip to content
This repository was archived by the owner on Feb 28, 2024. It is now read-only.

Commit 29acab4

Browse files
Merge pull request #82 from svollenweider/master
Fix GPIO pins go high on startup and add X1 encoding in encoder class
2 parents a9845d2 + 291acc8 commit 29acab4

File tree

3 files changed

+41
-4
lines changed

3 files changed

+41
-4
lines changed

Diff for: src/utility/QEI/QEI.cpp

+26-3
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,9 @@ QEI::QEI(PinName channelA,
152152
//X4 encoding uses interrupts on channel A,
153153
//and on channel B.
154154
channelA_.rise(mbed::callback(this, &QEI::encode));
155-
channelA_.fall(mbed::callback(this, &QEI::encode));
155+
if(encoding != X1_ENCODING){
156+
channelA_.fall(mbed::callback(this, &QEI::encode));
157+
}
156158

157159
//If we're using X4 encoding, then attach interrupts to channel B too.
158160
if (encoding == X4_ENCODING) {
@@ -191,6 +193,20 @@ int QEI::getRevolutions(void) {
191193

192194
}
193195

196+
// +-------------+
197+
// | X1 Encoding |
198+
// +-------------+
199+
//
200+
// When observing states two patterns will appear:
201+
//
202+
// Counter clockwise rotation:
203+
//
204+
// 10 -> 10 -> 10 -> 10 -> ...
205+
//
206+
// Clockwise rotation:
207+
//
208+
// 11 -> 11 -> 11 -> ...
209+
//
194210
// +-------------+
195211
// | X2 Encoding |
196212
// +-------------+
@@ -243,8 +259,15 @@ void QEI::encode(void) {
243259

244260
//2-bit state.
245261
currState_ = (chanA << 1) | (chanB);
246-
247-
if (encoding_ == X2_ENCODING) {
262+
263+
if(encoding_ == X1_ENCODING){
264+
if(currState_ == 0x3){
265+
pulses_++;
266+
}
267+
if(currState_ == 0x2){
268+
pulses_--;
269+
}
270+
} else if (encoding_ == X2_ENCODING) {
248271

249272
//11->00->11->00 is counter clockwise rotation or "forward".
250273
if ((prevState_ == 0x3 && currState_ == 0x0) ||

Diff for: src/utility/QEI/QEI.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ class QEI {
148148
public:
149149

150150
typedef enum Encoding {
151-
151+
X1_ENCODING,
152152
X2_ENCODING,
153153
X4_ENCODING
154154

Diff for: src/utility/ioexpander/ArduinoIOExpander.cpp

+14
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,20 @@ void ArduinoIOExpanderClass::initPins()
103103
{
104104

105105
if (_tca.getAddress() == IO_ADD) {
106+
PinStatus status = SWITCH_OFF;
107+
set(IO_WRITE_CH_PIN_00, status);
108+
set(IO_WRITE_CH_PIN_01, status);
109+
set(IO_WRITE_CH_PIN_02, status);
110+
set(IO_WRITE_CH_PIN_03, status);
111+
set(IO_WRITE_CH_PIN_04, status);
112+
set(IO_WRITE_CH_PIN_05, status);
113+
set(IO_WRITE_CH_PIN_06, status);
114+
set(IO_WRITE_CH_PIN_07, status);
115+
set(IO_WRITE_CH_PIN_08, status);
116+
set(IO_WRITE_CH_PIN_09, status);
117+
set(IO_WRITE_CH_PIN_10, status);
118+
set(IO_WRITE_CH_PIN_11, status);
119+
106120
pinMode(IO_WRITE_CH_PIN_00, OUTPUT);
107121
pinMode(IO_WRITE_CH_PIN_01, OUTPUT);
108122
pinMode(IO_WRITE_CH_PIN_02, OUTPUT);

0 commit comments

Comments
 (0)