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

Update ArduinoIOExpander.cpp #82

Merged
merged 6 commits into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 26 additions & 3 deletions src/utility/QEI/QEI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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 |
// +-------------+
Expand Down Expand Up @@ -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) ||
Expand Down
2 changes: 1 addition & 1 deletion src/utility/QEI/QEI.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ class QEI {
public:

typedef enum Encoding {

X1_ENCODING,
X2_ENCODING,
X4_ENCODING

Expand Down
14 changes: 14 additions & 0 deletions src/utility/ioexpander/ArduinoIOExpander.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down