Skip to content

Commit 415a002

Browse files
committed
Manage ENCODER pin mode
1 parent 12624a1 commit 415a002

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

Firmata.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
#define I2C 0x06 // pin included in I2C setup
7878
#define ONEWIRE 0x07 // pin configured for 1-wire
7979
#define STEPPER 0x08 // pin configured for stepper motor
80+
#define ENCODER 0x09 // pin configured for encoders
8081
#define IGNORE 0x7F // pin configured to be ignored by digitalWrite and capabilityResponse
8182
#define TOTAL_PIN_MODES 10
8283

utility/EncoderFirmata.cpp

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ void EncoderFirmata::attachEncoder(byte encoderNum, byte pinANum, byte pinBNum)
4545
{
4646
//Firmata.sendString("Encoder Warning: For better performences, you should only use Interrput pins.");
4747
}
48+
if (Firmata.getPinMode(pinANum)==IGNORE || Firmata.getPinMode(pinBNum)==IGNORE)
49+
return false;
50+
Firmata.setPinMode(pinANum, ENCODER);
51+
Firmata.setPinMode(pinBNum, ENCODER);
4852
encoders[encoderNum] = new Encoder(pinANum, pinBNum);
4953
}
5054

@@ -59,18 +63,23 @@ void EncoderFirmata::detachEncoder(byte encoderNum)
5963

6064
boolean EncoderFirmata::handlePinMode(byte pin, int mode)
6165
{
62-
if (IS_PIN_INTERRUPT(pin))
63-
{
64-
// nothing to do, pins states are managed
65-
// in "attach/detachEncoder" methods
66-
return true;
66+
if (mode == ENCODER) {
67+
if (IS_PIN_INTERRUPT(pin))
68+
{
69+
// nothing to do, pins states are managed
70+
// in "attach/detach Encoder" methods
71+
return true;
72+
}
6773
}
6874
return false;
6975
}
7076

7177
void EncoderFirmata::handleCapability(byte pin)
7278
{
73-
// nothing to do
79+
if (IS_PIN_INTERRUPT(pin)) {
80+
Firmata.write(ENCODER);
81+
Firmata.write(28); //28 bits used for absolute position
82+
}
7483
}
7584

7685

0 commit comments

Comments
 (0)