Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Feb 28, 2024. It is now read-only.

Update ArduinoIOExpander.cpp#82

Merged
Merged
Show file tree
Hide file tree
Changes fromall 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 deletionssrc/utility/QEI/QEI.cpp
View file
Open in desktop
Original file line numberDiff line numberDiff 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 DownExpand 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 DownExpand 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 deletionsrc/utility/QEI/QEI.h
View file
Open in desktop
Original file line numberDiff line numberDiff 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 deletionssrc/utility/ioexpander/ArduinoIOExpander.cpp
View file
Open in desktop
Original file line numberDiff line numberDiff 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

[8]ページ先頭

©2009-2025 Movatter.jp