From e71ba2311448b9b1a79b3dd627a8b69423445b93 Mon Sep 17 00:00:00 2001 From: Jeff Hoefs Date: Sat, 7 Nov 2015 20:36:03 -0800 Subject: [PATCH] safer naming for pin mode definitions --- Firmata.h | 32 +++++---- .../OldStandardFirmata/OldStandardFirmata.ino | 2 +- examples/StandardFirmata/StandardFirmata.ino | 54 +++++++-------- .../StandardFirmataChipKIT.ino | 54 +++++++-------- .../StandardFirmataEthernet.ino | 64 ++++++++--------- .../StandardFirmataEthernetPlus.ino | 64 ++++++++--------- .../StandardFirmataPlus.ino | 68 +++++++++---------- .../StandardFirmataYun/StandardFirmataYun.ino | 54 +++++++-------- 8 files changed, 201 insertions(+), 191 deletions(-) diff --git a/Firmata.h b/Firmata.h index 9e59c11c..28bcefa8 100644 --- a/Firmata.h +++ b/Firmata.h @@ -73,18 +73,27 @@ // pin modes //#define INPUT 0x00 // defined in Arduino.h //#define OUTPUT 0x01 // defined in Arduino.h -#define ANALOG 0x02 // analog pin in analogInput mode -#define PWM 0x03 // digital pin in PWM output mode -#define SERVO 0x04 // digital pin in Servo output mode -#define SHIFT 0x05 // shiftIn/shiftOut mode -#define I2C 0x06 // pin included in I2C setup -#define ONEWIRE 0x07 // pin configured for 1-wire -#define STEPPER 0x08 // pin configured for stepper motor -#define ENCODER 0x09 // pin configured for rotary encoders -#define MODE_SERIAL 0x0A // pin configured for serial communication -#define MODE_INPUT_PULLUP 0x0B // enable internal pull-up resistor for pin -#define IGNORE 0x7F // pin configured to be ignored by digitalWrite and capabilityResponse +#define PIN_MODE_ANALOG 0x02 // analog pin in analogInput mode +#define PIN_MODE_PWM 0x03 // digital pin in PWM output mode +#define PIN_MODE_SERVO 0x04 // digital pin in Servo output mode +#define PIN_MODE_SHIFT 0x05 // shiftIn/shiftOut mode +#define PIN_MODE_I2C 0x06 // pin included in I2C setup +#define PIN_MODE_ONEWIRE 0x07 // pin configured for 1-wire +#define PIN_MODE_STEPPER 0x08 // pin configured for stepper motor +#define PIN_MODE_ENCODER 0x09 // pin configured for rotary encoders +#define PIN_MODE_SERIAL 0x0A // pin configured for serial communication +#define PIN_MODE_PULLUP 0x0B // enable internal pull-up resistor for pin +#define PIN_MODE_IGNORE 0x7F // pin configured to be ignored by digitalWrite and capabilityResponse #define TOTAL_PIN_MODES 13 +// DEPRECATED as of Firmata v2.5 +#define ANALOG 0x02 // same as FIRMATA_MODE_ANALOG +#define PWM 0x03 // same as FIRMATA_MODE_PWM +#define SERVO 0x04 // same as FIRMATA_MODE_SERVO +#define SHIFT 0x05 // same as FIRMATA_MODE_SHIFT +#define I2C 0x06 // same as FIRMATA_MODE_I2C +#define ONEWIRE 0x07 // same as FIRMATA_MODE_ONEWIRE +#define STEPPER 0x08 // same as FIRMATA_MODE_STEPPER +#define ENCODER 0x09 // same as FIRMATA_MODE_ENCODER extern "C" { // callback function types @@ -94,7 +103,6 @@ extern "C" { typedef void (*sysexCallbackFunction)(byte command, byte argc, byte *argv); } - // TODO make it a subclass of a generic Serial/Stream base class class FirmataClass { diff --git a/examples/OldStandardFirmata/OldStandardFirmata.ino b/examples/OldStandardFirmata/OldStandardFirmata.ino index ea987c40..62dd54ea 100644 --- a/examples/OldStandardFirmata/OldStandardFirmata.ino +++ b/examples/OldStandardFirmata/OldStandardFirmata.ino @@ -122,7 +122,7 @@ void setPinModeCallback(byte pin, int mode) { void analogWriteCallback(byte pin, int value) { - setPinModeCallback(pin, PWM); + setPinModeCallback(pin, PIN_MODE_PWM); analogWrite(pin, value); } diff --git a/examples/StandardFirmata/StandardFirmata.ino b/examples/StandardFirmata/StandardFirmata.ino index bfd2ba7a..063fa9dc 100755 --- a/examples/StandardFirmata/StandardFirmata.ino +++ b/examples/StandardFirmata/StandardFirmata.ino @@ -20,7 +20,7 @@ See file LICENSE.txt for further informations on licensing terms. - Last updated by Jeff Hoefs: October 31st, 2015 + Last updated by Jeff Hoefs: November 7th, 2015 */ #include @@ -226,24 +226,24 @@ void checkDigitalInputs(void) */ void setPinModeCallback(byte pin, int mode) { - if (pinConfig[pin] == IGNORE) + if (pinConfig[pin] == PIN_MODE_IGNORE) return; - if (pinConfig[pin] == I2C && isI2CEnabled && mode != I2C) { + if (pinConfig[pin] == PIN_MODE_I2C && isI2CEnabled && mode != PIN_MODE_I2C) { // disable i2c so pins can be used for other functions // the following if statements should reconfigure the pins properly disableI2CPins(); } - if (IS_PIN_DIGITAL(pin) && mode != SERVO) { + if (IS_PIN_DIGITAL(pin) && mode != PIN_MODE_SERVO) { if (servoPinMap[pin] < MAX_SERVOS && servos[servoPinMap[pin]].attached()) { detachServo(pin); } } if (IS_PIN_ANALOG(pin)) { - reportAnalogCallback(PIN_TO_ANALOG(pin), mode == ANALOG ? 1 : 0); // turn on/off reporting + reportAnalogCallback(PIN_TO_ANALOG(pin), mode == PIN_MODE_ANALOG ? 1 : 0); // turn on/off reporting } if (IS_PIN_DIGITAL(pin)) { - if (mode == INPUT || mode == MODE_INPUT_PULLUP) { + if (mode == INPUT || mode == PIN_MODE_PULLUP) { portConfigInputs[pin / 8] |= (1 << (pin & 7)); } else { portConfigInputs[pin / 8] &= ~(1 << (pin & 7)); @@ -251,7 +251,7 @@ void setPinModeCallback(byte pin, int mode) } pinState[pin] = 0; switch (mode) { - case ANALOG: + case PIN_MODE_ANALOG: if (IS_PIN_ANALOG(pin)) { if (IS_PIN_DIGITAL(pin)) { pinMode(PIN_TO_DIGITAL(pin), INPUT); // disable output driver @@ -260,7 +260,7 @@ void setPinModeCallback(byte pin, int mode) digitalWrite(PIN_TO_DIGITAL(pin), LOW); // disable internal pull-ups #endif } - pinConfig[pin] = ANALOG; + pinConfig[pin] = PIN_MODE_ANALOG; } break; case INPUT: @@ -273,10 +273,10 @@ void setPinModeCallback(byte pin, int mode) pinConfig[pin] = INPUT; } break; - case MODE_INPUT_PULLUP: + case PIN_MODE_PULLUP: if (IS_PIN_DIGITAL(pin)) { pinMode(PIN_TO_DIGITAL(pin), INPUT_PULLUP); - pinConfig[pin] = MODE_INPUT_PULLUP; + pinConfig[pin] = PIN_MODE_PULLUP; pinState[pin] = 1; } break; @@ -287,16 +287,16 @@ void setPinModeCallback(byte pin, int mode) pinConfig[pin] = OUTPUT; } break; - case PWM: + case PIN_MODE_PWM: if (IS_PIN_PWM(pin)) { pinMode(PIN_TO_PWM(pin), OUTPUT); analogWrite(PIN_TO_PWM(pin), 0); - pinConfig[pin] = PWM; + pinConfig[pin] = PIN_MODE_PWM; } break; - case SERVO: + case PIN_MODE_SERVO: if (IS_PIN_DIGITAL(pin)) { - pinConfig[pin] = SERVO; + pinConfig[pin] = PIN_MODE_SERVO; if (servoPinMap[pin] == 255 || !servos[servoPinMap[pin]].attached()) { // pass -1 for min and max pulse values to use default values set // by Servo library @@ -304,11 +304,11 @@ void setPinModeCallback(byte pin, int mode) } } break; - case I2C: + case PIN_MODE_I2C: if (IS_PIN_I2C(pin)) { // mark the pin as i2c // the user must call I2C_CONFIG to enable I2C for a device - pinConfig[pin] = I2C; + pinConfig[pin] = PIN_MODE_I2C; } break; default: @@ -337,12 +337,12 @@ void analogWriteCallback(byte pin, int value) { if (pin < TOTAL_PINS) { switch (pinConfig[pin]) { - case SERVO: + case PIN_MODE_SERVO: if (IS_PIN_DIGITAL(pin)) servos[servoPinMap[pin]].write(value); pinState[pin] = value; break; - case PWM: + case PIN_MODE_PWM: if (IS_PIN_PWM(pin)) analogWrite(PIN_TO_PWM(pin), value); pinState[pin] = value; @@ -550,7 +550,7 @@ void sysexCallback(byte command, byte argc, byte *argv) detachServo(pin); } attachServo(pin, minPulse, maxPulse); - setPinModeCallback(pin, SERVO); + setPinModeCallback(pin, PIN_MODE_SERVO); } } break; @@ -579,25 +579,25 @@ void sysexCallback(byte command, byte argc, byte *argv) if (IS_PIN_DIGITAL(pin)) { Firmata.write((byte)INPUT); Firmata.write(1); - Firmata.write((byte)MODE_INPUT_PULLUP); + Firmata.write((byte)PIN_MODE_PULLUP); Firmata.write(1); Firmata.write((byte)OUTPUT); Firmata.write(1); } if (IS_PIN_ANALOG(pin)) { - Firmata.write(ANALOG); + Firmata.write(PIN_MODE_ANALOG); Firmata.write(10); // 10 = 10-bit resolution } if (IS_PIN_PWM(pin)) { - Firmata.write(PWM); + Firmata.write(PIN_MODE_PWM); Firmata.write(8); // 8 = 8-bit resolution } if (IS_PIN_DIGITAL(pin)) { - Firmata.write(SERVO); + Firmata.write(PIN_MODE_SERVO); Firmata.write(14); } if (IS_PIN_I2C(pin)) { - Firmata.write(I2C); + Firmata.write(PIN_MODE_I2C); Firmata.write(1); // TODO: could assign a number to map to SCL or SDA } Firmata.write(127); @@ -638,7 +638,7 @@ void enableI2CPins() for (i = 0; i < TOTAL_PINS; i++) { if (IS_PIN_I2C(i)) { // mark pins as i2c so they are ignore in non i2c data requests - setPinModeCallback(i, I2C); + setPinModeCallback(i, PIN_MODE_I2C); } } @@ -680,7 +680,7 @@ void systemResetCallback() // otherwise, pins default to digital output if (IS_PIN_ANALOG(i)) { // turns off pullup, configures everything - setPinModeCallback(i, ANALOG); + setPinModeCallback(i, PIN_MODE_ANALOG); } else if (IS_PIN_DIGITAL(i)) { // sets the output to 0, configures portConfigInputs setPinModeCallback(i, OUTPUT); @@ -755,7 +755,7 @@ void loop() previousMillis += samplingInterval; /* ANALOGREAD - do all analogReads() at the configured sampling interval */ for (pin = 0; pin < TOTAL_PINS; pin++) { - if (IS_PIN_ANALOG(pin) && pinConfig[pin] == ANALOG) { + if (IS_PIN_ANALOG(pin) && pinConfig[pin] == PIN_MODE_ANALOG) { analogPin = PIN_TO_ANALOG(pin); if (analogInputsToReport & (1 << analogPin)) { Firmata.sendAnalog(analogPin, analogRead(analogPin)); diff --git a/examples/StandardFirmataChipKIT/StandardFirmataChipKIT.ino b/examples/StandardFirmataChipKIT/StandardFirmataChipKIT.ino index 45e84151..fb54da41 100644 --- a/examples/StandardFirmataChipKIT/StandardFirmataChipKIT.ino +++ b/examples/StandardFirmataChipKIT/StandardFirmataChipKIT.ino @@ -21,7 +21,7 @@ See file LICENSE.txt for further informations on licensing terms. - Last updated by Jeff Hoefs: October 31st, 2015 + Last updated by Jeff Hoefs: November 7th, 2015 */ #include // Gives us PWM and Servo on every pin @@ -237,24 +237,24 @@ void servoWrite(byte pin, int value) */ void setPinModeCallback(byte pin, int mode) { - if (pinConfig[pin] == IGNORE) + if (pinConfig[pin] == PIN_MODE_IGNORE) return; - if (pinConfig[pin] == I2C && isI2CEnabled && mode != I2C) { + if (pinConfig[pin] == PIN_MODE_I2C && isI2CEnabled && mode != PIN_MODE_I2C) { // disable i2c so pins can be used for other functions // the following if statements should reconfigure the pins properly disableI2CPins(); } - if (IS_PIN_DIGITAL(pin) && mode != SERVO) { + if (IS_PIN_DIGITAL(pin) && mode != PIN_MODE_SERVO) { if (servoPinMap[pin] < MAX_SERVOS && servos[servoPinMap[pin]].attached()) { detachServo(pin); } } if (IS_PIN_ANALOG(pin)) { - reportAnalogCallback(PIN_TO_ANALOG(pin), mode == ANALOG ? 1 : 0); // turn on/off reporting + reportAnalogCallback(PIN_TO_ANALOG(pin), mode == PIN_MODE_ANALOG ? 1 : 0); // turn on/off reporting } if (IS_PIN_DIGITAL(pin)) { - if (mode == INPUT || mode == MODE_INPUT_PULLUP) { + if (mode == INPUT || mode == PIN_MODE_PULLUP) { portConfigInputs[pin / 8] |= (1 << (pin & 7)); } else { portConfigInputs[pin / 8] &= ~(1 << (pin & 7)); @@ -262,7 +262,7 @@ void setPinModeCallback(byte pin, int mode) } pinState[pin] = 0; switch (mode) { - case ANALOG: + case PIN_MODE_ANALOG: if (IS_PIN_ANALOG(pin)) { if (IS_PIN_DIGITAL(pin)) { pinMode(PIN_TO_DIGITAL(pin), INPUT); // disable output driver @@ -271,7 +271,7 @@ void setPinModeCallback(byte pin, int mode) digitalWrite(PIN_TO_DIGITAL(pin), LOW); // disable internal pull-ups #endif } - pinConfig[pin] = ANALOG; + pinConfig[pin] = PIN_MODE_ANALOG; } break; case INPUT: @@ -284,10 +284,10 @@ void setPinModeCallback(byte pin, int mode) pinConfig[pin] = INPUT; } break; - case MODE_INPUT_PULLUP: + case PIN_MODE_PULLUP: if (IS_PIN_DIGITAL(pin)) { pinMode(PIN_TO_DIGITAL(pin), INPUT_PULLUP); - pinConfig[pin] = MODE_INPUT_PULLUP; + pinConfig[pin] = PIN_MODE_PULLUP; pinState[pin] = 1; } break; @@ -298,16 +298,16 @@ void setPinModeCallback(byte pin, int mode) pinConfig[pin] = OUTPUT; } break; - case PWM: + case PIN_MODE_PWM: if (IS_PIN_PWM(pin)) { pinMode(PIN_TO_PWM(pin), OUTPUT); servoWrite(PIN_TO_PWM(pin), 0); - pinConfig[pin] = PWM; + pinConfig[pin] = PIN_MODE_PWM; } break; - case SERVO: + case PIN_MODE_SERVO: if (IS_PIN_DIGITAL(pin)) { - pinConfig[pin] = SERVO; + pinConfig[pin] = PIN_MODE_SERVO; if (servoPinMap[pin] == 255 || !servos[servoPinMap[pin]].attached()) { // pass -1 for min and max pulse values to use default values set // by Servo library @@ -315,11 +315,11 @@ void setPinModeCallback(byte pin, int mode) } } break; - case I2C: + case PIN_MODE_I2C: if (IS_PIN_I2C(pin)) { // mark the pin as i2c // the user must call I2C_CONFIG to enable I2C for a device - pinConfig[pin] = I2C; + pinConfig[pin] = PIN_MODE_I2C; } break; default: @@ -348,12 +348,12 @@ void analogWriteCallback(byte pin, int value) { if (pin < TOTAL_PINS) { switch (pinConfig[pin]) { - case SERVO: + case PIN_MODE_SERVO: if (IS_PIN_DIGITAL(pin)) servos[servoPinMap[pin]].write(value); pinState[pin] = value; break; - case PWM: + case PIN_MODE_PWM: if (IS_PIN_PWM(pin)) servoWrite(PIN_TO_PWM(pin), value); pinState[pin] = value; @@ -561,7 +561,7 @@ void sysexCallback(byte command, byte argc, byte *argv) detachServo(pin); } attachServo(pin, minPulse, maxPulse); - setPinModeCallback(pin, SERVO); + setPinModeCallback(pin, PIN_MODE_SERVO); } } break; @@ -590,25 +590,25 @@ void sysexCallback(byte command, byte argc, byte *argv) if (IS_PIN_DIGITAL(pin)) { Firmata.write((byte)INPUT); Firmata.write(1); - Firmata.write((byte)MODE_INPUT_PULLUP); + Firmata.write((byte)PIN_MODE_PULLUP); Firmata.write(1); Firmata.write((byte)OUTPUT); Firmata.write(1); } if (IS_PIN_ANALOG(pin)) { - Firmata.write(ANALOG); + Firmata.write(PIN_MODE_ANALOG); Firmata.write(10); // 10 = 10-bit resolution } if (IS_PIN_PWM(pin)) { - Firmata.write(PWM); + Firmata.write(PIN_MODE_PWM); Firmata.write(8); // 8 = 8-bit resolution } if (IS_PIN_DIGITAL(pin)) { - Firmata.write(SERVO); + Firmata.write(PIN_MODE_SERVO); Firmata.write(14); } if (IS_PIN_I2C(pin)) { - Firmata.write(I2C); + Firmata.write(PIN_MODE_I2C); Firmata.write(1); // TODO: could assign a number to map to SCL or SDA } Firmata.write(127); @@ -649,7 +649,7 @@ void enableI2CPins() for (i = 0; i < TOTAL_PINS; i++) { if (IS_PIN_I2C(i)) { // mark pins as i2c so they are ignore in non i2c data requests - setPinModeCallback(i, I2C); + setPinModeCallback(i, PIN_MODE_I2C); } } @@ -689,7 +689,7 @@ void systemResetCallback() // otherwise, pins default to digital output if (IS_PIN_ANALOG(i)) { // turns off pullup, configures everything - setPinModeCallback(i, ANALOG); + setPinModeCallback(i, PIN_MODE_ANALOG); } else if (IS_PIN_DIGITAL(i)) { // sets the output to 0, configures portConfigInputs setPinModeCallback(i, OUTPUT); @@ -761,7 +761,7 @@ void loop() previousMillis += samplingInterval; /* ANALOGREAD - do all analogReads() at the configured sampling interval */ for (pin = 0; pin < TOTAL_PINS; pin++) { - if (IS_PIN_ANALOG(pin) && pinConfig[pin] == ANALOG) { + if (IS_PIN_ANALOG(pin) && pinConfig[pin] == PIN_MODE_ANALOG) { analogPin = PIN_TO_ANALOG(pin); if (analogInputsToReport & (1 << analogPin)) { Firmata.sendAnalog(analogPin, analogRead(analogPin)); diff --git a/examples/StandardFirmataEthernet/StandardFirmataEthernet.ino b/examples/StandardFirmataEthernet/StandardFirmataEthernet.ino index 27f5ab91..9298b8b4 100644 --- a/examples/StandardFirmataEthernet/StandardFirmataEthernet.ino +++ b/examples/StandardFirmataEthernet/StandardFirmataEthernet.ino @@ -20,7 +20,7 @@ See file LICENSE.txt for further informations on licensing terms. - Last updated by Jeff Hoefs: October 31st, 2015 + Last updated by Jeff Hoefs: November 7th, 2015 */ /* @@ -121,9 +121,11 @@ // replace with ethernet shield mac. Must be unique for your network const byte mac[] = {0x90, 0xA2, 0xDA, 0x00, 0x53, 0xE5}; -#if !defined ethernet_h && !defined _YUN_CLIENT_H_ -#error "you must uncomment the includes for your board configuration. See OPTIONS A and B in the NETWORK CONFIGURATION SECTION" -#endif +// Since Arduino 1.6.6 ethernet_h is not recognized, even when Ethernet.h is included so this +// always throws the error. Commenting out until the issue introduced in Arduino 1.6.6 is resolved. +// #if !defined ethernet_h && !defined _YUN_CLIENT_H_ +// #error "you must uncomment the includes for your board configuration. See OPTIONS A and B in the NETWORK CONFIGURATION SECTION" +// #endif #if defined remote_ip && defined remote_host #error "cannot define both remote_ip and remote_host at the same time!" @@ -342,24 +344,24 @@ void checkDigitalInputs(void) */ void setPinModeCallback(byte pin, int mode) { - if (pinConfig[pin] == IGNORE) + if (pinConfig[pin] == PIN_MODE_IGNORE) return; - if (pinConfig[pin] == I2C && isI2CEnabled && mode != I2C) { + if (pinConfig[pin] == PIN_MODE_I2C && isI2CEnabled && mode != PIN_MODE_I2C) { // disable i2c so pins can be used for other functions // the following if statements should reconfigure the pins properly disableI2CPins(); } - if (IS_PIN_DIGITAL(pin) && mode != SERVO) { + if (IS_PIN_DIGITAL(pin) && mode != PIN_MODE_SERVO) { if (servoPinMap[pin] < MAX_SERVOS && servos[servoPinMap[pin]].attached()) { detachServo(pin); } } if (IS_PIN_ANALOG(pin)) { - reportAnalogCallback(PIN_TO_ANALOG(pin), mode == ANALOG ? 1 : 0); // turn on/off reporting + reportAnalogCallback(PIN_TO_ANALOG(pin), mode == PIN_MODE_ANALOG ? 1 : 0); // turn on/off reporting } if (IS_PIN_DIGITAL(pin)) { - if (mode == INPUT || mode == MODE_INPUT_PULLUP) { + if (mode == INPUT || mode == PIN_MODE_PULLUP) { portConfigInputs[pin / 8] |= (1 << (pin & 7)); } else { portConfigInputs[pin / 8] &= ~(1 << (pin & 7)); @@ -367,7 +369,7 @@ void setPinModeCallback(byte pin, int mode) } pinState[pin] = 0; switch (mode) { - case ANALOG: + case PIN_MODE_ANALOG: if (IS_PIN_ANALOG(pin)) { if (IS_PIN_DIGITAL(pin)) { pinMode(PIN_TO_DIGITAL(pin), INPUT); // disable output driver @@ -376,7 +378,7 @@ void setPinModeCallback(byte pin, int mode) digitalWrite(PIN_TO_DIGITAL(pin), LOW); // disable internal pull-ups #endif } - pinConfig[pin] = ANALOG; + pinConfig[pin] = PIN_MODE_ANALOG; } break; case INPUT: @@ -389,10 +391,10 @@ void setPinModeCallback(byte pin, int mode) pinConfig[pin] = INPUT; } break; - case MODE_INPUT_PULLUP: + case PIN_MODE_PULLUP: if (IS_PIN_DIGITAL(pin)) { pinMode(PIN_TO_DIGITAL(pin), INPUT_PULLUP); - pinConfig[pin] = MODE_INPUT_PULLUP; + pinConfig[pin] = PIN_MODE_PULLUP; pinState[pin] = 1; } break; @@ -403,16 +405,16 @@ void setPinModeCallback(byte pin, int mode) pinConfig[pin] = OUTPUT; } break; - case PWM: + case PIN_MODE_PWM: if (IS_PIN_PWM(pin)) { pinMode(PIN_TO_PWM(pin), OUTPUT); analogWrite(PIN_TO_PWM(pin), 0); - pinConfig[pin] = PWM; + pinConfig[pin] = PIN_MODE_PWM; } break; - case SERVO: + case PIN_MODE_SERVO: if (IS_PIN_DIGITAL(pin)) { - pinConfig[pin] = SERVO; + pinConfig[pin] = PIN_MODE_SERVO; if (servoPinMap[pin] == 255 || !servos[servoPinMap[pin]].attached()) { // pass -1 for min and max pulse values to use default values set // by Servo library @@ -420,11 +422,11 @@ void setPinModeCallback(byte pin, int mode) } } break; - case I2C: + case PIN_MODE_I2C: if (IS_PIN_I2C(pin)) { // mark the pin as i2c // the user must call I2C_CONFIG to enable I2C for a device - pinConfig[pin] = I2C; + pinConfig[pin] = PIN_MODE_I2C; } break; default: @@ -453,12 +455,12 @@ void analogWriteCallback(byte pin, int value) { if (pin < TOTAL_PINS) { switch (pinConfig[pin]) { - case SERVO: + case PIN_MODE_SERVO: if (IS_PIN_DIGITAL(pin)) servos[servoPinMap[pin]].write(value); pinState[pin] = value; break; - case PWM: + case PIN_MODE_PWM: if (IS_PIN_PWM(pin)) analogWrite(PIN_TO_PWM(pin), value); pinState[pin] = value; @@ -666,7 +668,7 @@ void sysexCallback(byte command, byte argc, byte *argv) detachServo(pin); } attachServo(pin, minPulse, maxPulse); - setPinModeCallback(pin, SERVO); + setPinModeCallback(pin, PIN_MODE_SERVO); } } break; @@ -695,25 +697,25 @@ void sysexCallback(byte command, byte argc, byte *argv) if (IS_PIN_DIGITAL(pin)) { Firmata.write((byte)INPUT); Firmata.write(1); - Firmata.write((byte)MODE_INPUT_PULLUP); + Firmata.write((byte)PIN_MODE_PULLUP); Firmata.write(1); Firmata.write((byte)OUTPUT); Firmata.write(1); } if (IS_PIN_ANALOG(pin)) { - Firmata.write(ANALOG); + Firmata.write(PIN_MODE_ANALOG); Firmata.write(10); // 10 = 10-bit resolution } if (IS_PIN_PWM(pin)) { - Firmata.write(PWM); + Firmata.write(PIN_MODE_PWM); Firmata.write(8); // 8 = 8-bit resolution } if (IS_PIN_DIGITAL(pin)) { - Firmata.write(SERVO); + Firmata.write(PIN_MODE_SERVO); Firmata.write(14); } if (IS_PIN_I2C(pin)) { - Firmata.write(I2C); + Firmata.write(PIN_MODE_I2C); Firmata.write(1); // TODO: could assign a number to map to SCL or SDA } Firmata.write(127); @@ -754,7 +756,7 @@ void enableI2CPins() for (i = 0; i < TOTAL_PINS; i++) { if (IS_PIN_I2C(i)) { // mark pins as i2c so they are ignore in non i2c data requests - setPinModeCallback(i, I2C); + setPinModeCallback(i, PIN_MODE_I2C); } } @@ -796,7 +798,7 @@ void systemResetCallback() // otherwise, pins default to digital output if (IS_PIN_ANALOG(i)) { // turns off pullup, configures everything - setPinModeCallback(i, ANALOG); + setPinModeCallback(i, PIN_MODE_ANALOG); } else if (IS_PIN_DIGITAL(i)) { // sets the output to 0, configures portConfigInputs setPinModeCallback(i, OUTPUT); @@ -863,7 +865,7 @@ void setup() || 28 == i #endif ) { - pinConfig[i] = IGNORE; + pinConfig[i] = PIN_MODE_IGNORE; } } @@ -903,7 +905,7 @@ void loop() previousMillis += samplingInterval; /* ANALOGREAD - do all analogReads() at the configured sampling interval */ for (pin = 0; pin < TOTAL_PINS; pin++) { - if (IS_PIN_ANALOG(pin) && pinConfig[pin] == ANALOG) { + if (IS_PIN_ANALOG(pin) && pinConfig[pin] == PIN_MODE_ANALOG) { analogPin = PIN_TO_ANALOG(pin); if (analogInputsToReport & (1 << analogPin)) { Firmata.sendAnalog(analogPin, analogRead(analogPin)); diff --git a/examples/StandardFirmataEthernetPlus/StandardFirmataEthernetPlus.ino b/examples/StandardFirmataEthernetPlus/StandardFirmataEthernetPlus.ino index aaf2172d..89a3e204 100644 --- a/examples/StandardFirmataEthernetPlus/StandardFirmataEthernetPlus.ino +++ b/examples/StandardFirmataEthernetPlus/StandardFirmataEthernetPlus.ino @@ -20,7 +20,7 @@ See file LICENSE.txt for further informations on licensing terms. - Last updated by Jeff Hoefs: October 31st, 2015 + Last updated by Jeff Hoefs: November 7th, 2015 */ /* @@ -432,24 +432,24 @@ void checkDigitalInputs(void) */ void setPinModeCallback(byte pin, int mode) { - if (pinConfig[pin] == IGNORE) + if (pinConfig[pin] == PIN_MODE_IGNORE) return; - if (pinConfig[pin] == I2C && isI2CEnabled && mode != I2C) { + if (pinConfig[pin] == PIN_MODE_I2C && isI2CEnabled && mode != PIN_MODE_I2C) { // disable i2c so pins can be used for other functions // the following if statements should reconfigure the pins properly disableI2CPins(); } - if (IS_PIN_DIGITAL(pin) && mode != SERVO) { + if (IS_PIN_DIGITAL(pin) && mode != PIN_MODE_SERVO) { if (servoPinMap[pin] < MAX_SERVOS && servos[servoPinMap[pin]].attached()) { detachServo(pin); } } if (IS_PIN_ANALOG(pin)) { - reportAnalogCallback(PIN_TO_ANALOG(pin), mode == ANALOG ? 1 : 0); // turn on/off reporting + reportAnalogCallback(PIN_TO_ANALOG(pin), mode == PIN_MODE_ANALOG ? 1 : 0); // turn on/off reporting } if (IS_PIN_DIGITAL(pin)) { - if (mode == INPUT || mode == MODE_INPUT_PULLUP) { + if (mode == INPUT || mode == PIN_MODE_PULLUP) { portConfigInputs[pin / 8] |= (1 << (pin & 7)); } else { portConfigInputs[pin / 8] &= ~(1 << (pin & 7)); @@ -457,7 +457,7 @@ void setPinModeCallback(byte pin, int mode) } pinState[pin] = 0; switch (mode) { - case ANALOG: + case PIN_MODE_ANALOG: if (IS_PIN_ANALOG(pin)) { if (IS_PIN_DIGITAL(pin)) { pinMode(PIN_TO_DIGITAL(pin), INPUT); // disable output driver @@ -466,7 +466,7 @@ void setPinModeCallback(byte pin, int mode) digitalWrite(PIN_TO_DIGITAL(pin), LOW); // disable internal pull-ups #endif } - pinConfig[pin] = ANALOG; + pinConfig[pin] = PIN_MODE_ANALOG; } break; case INPUT: @@ -479,10 +479,10 @@ void setPinModeCallback(byte pin, int mode) pinConfig[pin] = INPUT; } break; - case MODE_INPUT_PULLUP: + case PIN_MODE_PULLUP: if (IS_PIN_DIGITAL(pin)) { pinMode(PIN_TO_DIGITAL(pin), INPUT_PULLUP); - pinConfig[pin] = MODE_INPUT_PULLUP; + pinConfig[pin] = PIN_MODE_PULLUP; pinState[pin] = 1; } break; @@ -493,16 +493,16 @@ void setPinModeCallback(byte pin, int mode) pinConfig[pin] = OUTPUT; } break; - case PWM: + case PIN_MODE_PWM: if (IS_PIN_PWM(pin)) { pinMode(PIN_TO_PWM(pin), OUTPUT); analogWrite(PIN_TO_PWM(pin), 0); - pinConfig[pin] = PWM; + pinConfig[pin] = PIN_MODE_PWM; } break; - case SERVO: + case PIN_MODE_SERVO: if (IS_PIN_DIGITAL(pin)) { - pinConfig[pin] = SERVO; + pinConfig[pin] = PIN_MODE_SERVO; if (servoPinMap[pin] == 255 || !servos[servoPinMap[pin]].attached()) { // pass -1 for min and max pulse values to use default values set // by Servo library @@ -510,11 +510,11 @@ void setPinModeCallback(byte pin, int mode) } } break; - case I2C: + case PIN_MODE_I2C: if (IS_PIN_I2C(pin)) { // mark the pin as i2c // the user must call I2C_CONFIG to enable I2C for a device - pinConfig[pin] = I2C; + pinConfig[pin] = PIN_MODE_I2C; } break; default: @@ -543,12 +543,12 @@ void analogWriteCallback(byte pin, int value) { if (pin < TOTAL_PINS) { switch (pinConfig[pin]) { - case SERVO: + case PIN_MODE_SERVO: if (IS_PIN_DIGITAL(pin)) servos[servoPinMap[pin]].write(value); pinState[pin] = value; break; - case PWM: + case PIN_MODE_PWM: if (IS_PIN_PWM(pin)) analogWrite(PIN_TO_PWM(pin), value); pinState[pin] = value; @@ -756,7 +756,7 @@ void sysexCallback(byte command, byte argc, byte *argv) detachServo(pin); } attachServo(pin, minPulse, maxPulse); - setPinModeCallback(pin, SERVO); + setPinModeCallback(pin, PIN_MODE_SERVO); } } break; @@ -785,25 +785,25 @@ void sysexCallback(byte command, byte argc, byte *argv) if (IS_PIN_DIGITAL(pin)) { Firmata.write((byte)INPUT); Firmata.write(1); - Firmata.write((byte)MODE_INPUT_PULLUP); + Firmata.write((byte)PIN_MODE_PULLUP); Firmata.write(1); Firmata.write((byte)OUTPUT); Firmata.write(1); } if (IS_PIN_ANALOG(pin)) { - Firmata.write(ANALOG); + Firmata.write(PIN_MODE_ANALOG); Firmata.write(10); // 10 = 10-bit resolution } if (IS_PIN_PWM(pin)) { - Firmata.write(PWM); + Firmata.write(PIN_MODE_PWM); Firmata.write(8); // 8 = 8-bit resolution } if (IS_PIN_DIGITAL(pin)) { - Firmata.write(SERVO); + Firmata.write(PIN_MODE_SERVO); Firmata.write(14); } if (IS_PIN_I2C(pin)) { - Firmata.write(I2C); + Firmata.write(PIN_MODE_I2C); Firmata.write(1); // TODO: could assign a number to map to SCL or SDA } Firmata.write(127); @@ -856,8 +856,8 @@ void sysexCallback(byte command, byte argc, byte *argv) if (serialPort != NULL) { pins = getSerialPinNumbers(portId); if (pins.rx != 0 && pins.tx != 0) { - setPinModeCallback(pins.rx, MODE_SERIAL); - setPinModeCallback(pins.tx, MODE_SERIAL); + setPinModeCallback(pins.rx, PIN_MODE_SERIAL); + setPinModeCallback(pins.tx, PIN_MODE_SERIAL); // Fixes an issue where some serial devices would not work properly with Arduino Due // because all Arduino pins are set to OUTPUT by default in StandardFirmata. pinMode(pins.rx, INPUT); @@ -890,8 +890,8 @@ void sysexCallback(byte command, byte argc, byte *argv) } serialPort = getPortFromId(portId); if (serialPort != NULL) { - setPinModeCallback(rxPin, MODE_SERIAL); - setPinModeCallback(txPin, MODE_SERIAL); + setPinModeCallback(rxPin, PIN_MODE_SERIAL); + setPinModeCallback(txPin, PIN_MODE_SERIAL); ((SoftwareSerial*)serialPort)->begin(baud); } #endif @@ -993,7 +993,7 @@ void enableI2CPins() for (i = 0; i < TOTAL_PINS; i++) { if (IS_PIN_I2C(i)) { // mark pins as i2c so they are ignore in non i2c data requests - setPinModeCallback(i, I2C); + setPinModeCallback(i, PIN_MODE_I2C); } } @@ -1052,7 +1052,7 @@ void systemResetCallback() // otherwise, pins default to digital output if (IS_PIN_ANALOG(i)) { // turns off pullup, configures everything - setPinModeCallback(i, ANALOG); + setPinModeCallback(i, PIN_MODE_ANALOG); } else if (IS_PIN_DIGITAL(i)) { // sets the output to 0, configures portConfigInputs setPinModeCallback(i, OUTPUT); @@ -1111,7 +1111,7 @@ void setup() || 4 == i // SD-Card on Ethernet-shiedl uses pin 4 for SS || 10 == i // Ethernet-shield uses pin 10 for SS ) { - pinConfig[i] = IGNORE; + pinConfig[i] = PIN_MODE_IGNORE; } } @@ -1151,7 +1151,7 @@ void loop() previousMillis += samplingInterval; /* ANALOGREAD - do all analogReads() at the configured sampling interval */ for (pin = 0; pin < TOTAL_PINS; pin++) { - if (IS_PIN_ANALOG(pin) && pinConfig[pin] == ANALOG) { + if (IS_PIN_ANALOG(pin) && pinConfig[pin] == PIN_MODE_ANALOG) { analogPin = PIN_TO_ANALOG(pin); if (analogInputsToReport & (1 << analogPin)) { Firmata.sendAnalog(analogPin, analogRead(analogPin)); diff --git a/examples/StandardFirmataPlus/StandardFirmataPlus.ino b/examples/StandardFirmataPlus/StandardFirmataPlus.ino index ce292359..9cc57331 100644 --- a/examples/StandardFirmataPlus/StandardFirmataPlus.ino +++ b/examples/StandardFirmataPlus/StandardFirmataPlus.ino @@ -20,7 +20,7 @@ See file LICENSE.txt for further informations on licensing terms. - Last updated by Jeff Hoefs: October 31st, 2015 + Last updated by Jeff Hoefs: November 7th, 2015 */ /* @@ -360,24 +360,24 @@ void checkDigitalInputs(void) */ void setPinModeCallback(byte pin, int mode) { - if (pinConfig[pin] == IGNORE) + if (pinConfig[pin] == PIN_MODE_IGNORE) return; - if (pinConfig[pin] == I2C && isI2CEnabled && mode != I2C) { + if (pinConfig[pin] == PIN_MODE_I2C && isI2CEnabled && mode != PIN_MODE_I2C) { // disable i2c so pins can be used for other functions // the following if statements should reconfigure the pins properly disableI2CPins(); } - if (IS_PIN_DIGITAL(pin) && mode != SERVO) { + if (IS_PIN_DIGITAL(pin) && mode != PIN_MODE_SERVO) { if (servoPinMap[pin] < MAX_SERVOS && servos[servoPinMap[pin]].attached()) { detachServo(pin); } } if (IS_PIN_ANALOG(pin)) { - reportAnalogCallback(PIN_TO_ANALOG(pin), mode == ANALOG ? 1 : 0); // turn on/off reporting + reportAnalogCallback(PIN_TO_ANALOG(pin), mode == PIN_MODE_ANALOG ? 1 : 0); // turn on/off reporting } if (IS_PIN_DIGITAL(pin)) { - if (mode == INPUT || mode == MODE_INPUT_PULLUP) { + if (mode == INPUT || mode == PIN_MODE_PULLUP) { portConfigInputs[pin / 8] |= (1 << (pin & 7)); } else { portConfigInputs[pin / 8] &= ~(1 << (pin & 7)); @@ -385,7 +385,7 @@ void setPinModeCallback(byte pin, int mode) } pinState[pin] = 0; switch (mode) { - case ANALOG: + case PIN_MODE_ANALOG: if (IS_PIN_ANALOG(pin)) { if (IS_PIN_DIGITAL(pin)) { pinMode(PIN_TO_DIGITAL(pin), INPUT); // disable output driver @@ -394,7 +394,7 @@ void setPinModeCallback(byte pin, int mode) digitalWrite(PIN_TO_DIGITAL(pin), LOW); // disable internal pull-ups #endif } - pinConfig[pin] = ANALOG; + pinConfig[pin] = PIN_MODE_ANALOG; } break; case INPUT: @@ -407,10 +407,10 @@ void setPinModeCallback(byte pin, int mode) pinConfig[pin] = INPUT; } break; - case MODE_INPUT_PULLUP: + case PIN_MODE_PULLUP: if (IS_PIN_DIGITAL(pin)) { pinMode(PIN_TO_DIGITAL(pin), INPUT_PULLUP); - pinConfig[pin] = MODE_INPUT_PULLUP; + pinConfig[pin] = PIN_MODE_PULLUP; pinState[pin] = 1; } break; @@ -421,16 +421,16 @@ void setPinModeCallback(byte pin, int mode) pinConfig[pin] = OUTPUT; } break; - case PWM: + case PIN_MODE_PWM: if (IS_PIN_PWM(pin)) { pinMode(PIN_TO_PWM(pin), OUTPUT); analogWrite(PIN_TO_PWM(pin), 0); - pinConfig[pin] = PWM; + pinConfig[pin] = PIN_MODE_PWM; } break; - case SERVO: + case PIN_MODE_SERVO: if (IS_PIN_DIGITAL(pin)) { - pinConfig[pin] = SERVO; + pinConfig[pin] = PIN_MODE_SERVO; if (servoPinMap[pin] == 255 || !servos[servoPinMap[pin]].attached()) { // pass -1 for min and max pulse values to use default values set // by Servo library @@ -438,16 +438,16 @@ void setPinModeCallback(byte pin, int mode) } } break; - case I2C: + case PIN_MODE_I2C: if (IS_PIN_I2C(pin)) { // mark the pin as i2c // the user must call I2C_CONFIG to enable I2C for a device - pinConfig[pin] = I2C; + pinConfig[pin] = PIN_MODE_I2C; } break; - case MODE_SERIAL: + case PIN_MODE_SERIAL: // used for both HW and SW serial - pinConfig[pin] = MODE_SERIAL; + pinConfig[pin] = PIN_MODE_SERIAL; break; default: Firmata.sendString("Unknown pin mode"); // TODO: put error msgs in EEPROM @@ -475,12 +475,12 @@ void analogWriteCallback(byte pin, int value) { if (pin < TOTAL_PINS) { switch (pinConfig[pin]) { - case SERVO: + case PIN_MODE_SERVO: if (IS_PIN_DIGITAL(pin)) servos[servoPinMap[pin]].write(value); pinState[pin] = value; break; - case PWM: + case PIN_MODE_PWM: if (IS_PIN_PWM(pin)) analogWrite(PIN_TO_PWM(pin), value); pinState[pin] = value; @@ -688,7 +688,7 @@ void sysexCallback(byte command, byte argc, byte *argv) detachServo(pin); } attachServo(pin, minPulse, maxPulse); - setPinModeCallback(pin, SERVO); + setPinModeCallback(pin, PIN_MODE_SERVO); } } break; @@ -717,29 +717,29 @@ void sysexCallback(byte command, byte argc, byte *argv) if (IS_PIN_DIGITAL(pin)) { Firmata.write((byte)INPUT); Firmata.write(1); - Firmata.write((byte)MODE_INPUT_PULLUP); + Firmata.write((byte)PIN_MODE_PULLUP); Firmata.write(1); Firmata.write((byte)OUTPUT); Firmata.write(1); } if (IS_PIN_ANALOG(pin)) { - Firmata.write(ANALOG); + Firmata.write(PIN_MODE_ANALOG); Firmata.write(10); // 10 = 10-bit resolution } if (IS_PIN_PWM(pin)) { - Firmata.write(PWM); + Firmata.write(PIN_MODE_PWM); Firmata.write(8); // 8 = 8-bit resolution } if (IS_PIN_DIGITAL(pin)) { - Firmata.write(SERVO); + Firmata.write(PIN_MODE_SERVO); Firmata.write(14); } if (IS_PIN_I2C(pin)) { - Firmata.write(I2C); + Firmata.write(PIN_MODE_I2C); Firmata.write(1); // TODO: could assign a number to map to SCL or SDA } if (IS_PIN_SERIAL(pin)) { - Firmata.write(MODE_SERIAL); + Firmata.write(PIN_MODE_SERIAL); Firmata.write(getSerialPinType(pin)); } Firmata.write(127); @@ -792,8 +792,8 @@ void sysexCallback(byte command, byte argc, byte *argv) if (serialPort != NULL) { pins = getSerialPinNumbers(portId); if (pins.rx != 0 && pins.tx != 0) { - setPinModeCallback(pins.rx, MODE_SERIAL); - setPinModeCallback(pins.tx, MODE_SERIAL); + setPinModeCallback(pins.rx, PIN_MODE_SERIAL); + setPinModeCallback(pins.tx, PIN_MODE_SERIAL); // Fixes an issue where some serial devices would not work properly with Arduino Due // because all Arduino pins are set to OUTPUT by default in StandardFirmata. pinMode(pins.rx, INPUT); @@ -826,8 +826,8 @@ void sysexCallback(byte command, byte argc, byte *argv) } serialPort = getPortFromId(portId); if (serialPort != NULL) { - setPinModeCallback(rxPin, MODE_SERIAL); - setPinModeCallback(txPin, MODE_SERIAL); + setPinModeCallback(rxPin, PIN_MODE_SERIAL); + setPinModeCallback(txPin, PIN_MODE_SERIAL); ((SoftwareSerial*)serialPort)->begin(baud); } #endif @@ -929,7 +929,7 @@ void enableI2CPins() for (i = 0; i < TOTAL_PINS; i++) { if (IS_PIN_I2C(i)) { // mark pins as i2c so they are ignore in non i2c data requests - setPinModeCallback(i, I2C); + setPinModeCallback(i, PIN_MODE_I2C); } } @@ -988,7 +988,7 @@ void systemResetCallback() // otherwise, pins default to digital output if (IS_PIN_ANALOG(i)) { // turns off pullup, configures everything - setPinModeCallback(i, ANALOG); + setPinModeCallback(i, PIN_MODE_ANALOG); } else if (IS_PIN_DIGITAL(i)) { // sets the output to 0, configures portConfigInputs setPinModeCallback(i, OUTPUT); @@ -1063,7 +1063,7 @@ void loop() previousMillis += samplingInterval; /* ANALOGREAD - do all analogReads() at the configured sampling interval */ for (pin = 0; pin < TOTAL_PINS; pin++) { - if (IS_PIN_ANALOG(pin) && pinConfig[pin] == ANALOG) { + if (IS_PIN_ANALOG(pin) && pinConfig[pin] == PIN_MODE_ANALOG) { analogPin = PIN_TO_ANALOG(pin); if (analogInputsToReport & (1 << analogPin)) { Firmata.sendAnalog(analogPin, analogRead(analogPin)); diff --git a/examples/StandardFirmataYun/StandardFirmataYun.ino b/examples/StandardFirmataYun/StandardFirmataYun.ino index 2a23cbcb..d8e181ba 100644 --- a/examples/StandardFirmataYun/StandardFirmataYun.ino +++ b/examples/StandardFirmataYun/StandardFirmataYun.ino @@ -21,7 +21,7 @@ See file LICENSE.txt for further informations on licensing terms. - Last updated by Jeff Hoefs: October 31st, 2015 + Last updated by Jeff Hoefs: November 7th, 2015 */ /* @@ -238,24 +238,24 @@ void checkDigitalInputs(void) */ void setPinModeCallback(byte pin, int mode) { - if (pinConfig[pin] == IGNORE) + if (pinConfig[pin] == PIN_MODE_IGNORE) return; - if (pinConfig[pin] == I2C && isI2CEnabled && mode != I2C) { + if (pinConfig[pin] == PIN_MODE_I2C && isI2CEnabled && mode != PIN_MODE_I2C) { // disable i2c so pins can be used for other functions // the following if statements should reconfigure the pins properly disableI2CPins(); } - if (IS_PIN_DIGITAL(pin) && mode != SERVO) { + if (IS_PIN_DIGITAL(pin) && mode != PIN_MODE_SERVO) { if (servoPinMap[pin] < MAX_SERVOS && servos[servoPinMap[pin]].attached()) { detachServo(pin); } } if (IS_PIN_ANALOG(pin)) { - reportAnalogCallback(PIN_TO_ANALOG(pin), mode == ANALOG ? 1 : 0); // turn on/off reporting + reportAnalogCallback(PIN_TO_ANALOG(pin), mode == PIN_MODE_ANALOG ? 1 : 0); // turn on/off reporting } if (IS_PIN_DIGITAL(pin)) { - if (mode == INPUT || mode == MODE_INPUT_PULLUP) { + if (mode == INPUT || mode == PIN_MODE_PULLUP) { portConfigInputs[pin / 8] |= (1 << (pin & 7)); } else { portConfigInputs[pin / 8] &= ~(1 << (pin & 7)); @@ -263,7 +263,7 @@ void setPinModeCallback(byte pin, int mode) } pinState[pin] = 0; switch (mode) { - case ANALOG: + case PIN_MODE_ANALOG: if (IS_PIN_ANALOG(pin)) { if (IS_PIN_DIGITAL(pin)) { pinMode(PIN_TO_DIGITAL(pin), INPUT); // disable output driver @@ -272,7 +272,7 @@ void setPinModeCallback(byte pin, int mode) digitalWrite(PIN_TO_DIGITAL(pin), LOW); // disable internal pull-ups #endif } - pinConfig[pin] = ANALOG; + pinConfig[pin] = PIN_MODE_ANALOG; } break; case INPUT: @@ -285,10 +285,10 @@ void setPinModeCallback(byte pin, int mode) pinConfig[pin] = INPUT; } break; - case MODE_INPUT_PULLUP: + case PIN_MODE_PULLUP: if (IS_PIN_DIGITAL(pin)) { pinMode(PIN_TO_DIGITAL(pin), INPUT_PULLUP); - pinConfig[pin] = MODE_INPUT_PULLUP; + pinConfig[pin] = PIN_MODE_PULLUP; pinState[pin] = 1; } break; @@ -299,16 +299,16 @@ void setPinModeCallback(byte pin, int mode) pinConfig[pin] = OUTPUT; } break; - case PWM: + case PIN_MODE_PWM: if (IS_PIN_PWM(pin)) { pinMode(PIN_TO_PWM(pin), OUTPUT); analogWrite(PIN_TO_PWM(pin), 0); - pinConfig[pin] = PWM; + pinConfig[pin] = PIN_MODE_PWM; } break; - case SERVO: + case PIN_MODE_SERVO: if (IS_PIN_DIGITAL(pin)) { - pinConfig[pin] = SERVO; + pinConfig[pin] = PIN_MODE_SERVO; if (servoPinMap[pin] == 255 || !servos[servoPinMap[pin]].attached()) { // pass -1 for min and max pulse values to use default values set // by Servo library @@ -316,11 +316,11 @@ void setPinModeCallback(byte pin, int mode) } } break; - case I2C: + case PIN_MODE_I2C: if (IS_PIN_I2C(pin)) { // mark the pin as i2c // the user must call I2C_CONFIG to enable I2C for a device - pinConfig[pin] = I2C; + pinConfig[pin] = PIN_MODE_I2C; } break; default: @@ -349,12 +349,12 @@ void analogWriteCallback(byte pin, int value) { if (pin < TOTAL_PINS) { switch (pinConfig[pin]) { - case SERVO: + case PIN_MODE_SERVO: if (IS_PIN_DIGITAL(pin)) servos[servoPinMap[pin]].write(value); pinState[pin] = value; break; - case PWM: + case PIN_MODE_PWM: if (IS_PIN_PWM(pin)) analogWrite(PIN_TO_PWM(pin), value); pinState[pin] = value; @@ -562,7 +562,7 @@ void sysexCallback(byte command, byte argc, byte *argv) detachServo(pin); } attachServo(pin, minPulse, maxPulse); - setPinModeCallback(pin, SERVO); + setPinModeCallback(pin, PIN_MODE_SERVO); } } break; @@ -591,25 +591,25 @@ void sysexCallback(byte command, byte argc, byte *argv) if (IS_PIN_DIGITAL(pin)) { Firmata.write((byte)INPUT); Firmata.write(1); - Firmata.write((byte)MODE_INPUT_PULLUP); + Firmata.write((byte)PIN_MODE_PULLUP); Firmata.write(1); Firmata.write((byte)OUTPUT); Firmata.write(1); } if (IS_PIN_ANALOG(pin)) { - Firmata.write(ANALOG); + Firmata.write(PIN_MODE_ANALOG); Firmata.write(10); // 10 = 10-bit resolution } if (IS_PIN_PWM(pin)) { - Firmata.write(PWM); + Firmata.write(PIN_MODE_PWM); Firmata.write(8); // 8 = 8-bit resolution } if (IS_PIN_DIGITAL(pin)) { - Firmata.write(SERVO); + Firmata.write(PIN_MODE_SERVO); Firmata.write(14); } if (IS_PIN_I2C(pin)) { - Firmata.write(I2C); + Firmata.write(PIN_MODE_I2C); Firmata.write(1); // TODO: could assign a number to map to SCL or SDA } Firmata.write(127); @@ -650,7 +650,7 @@ void enableI2CPins() for (i = 0; i < TOTAL_PINS; i++) { if (IS_PIN_I2C(i)) { // mark pins as i2c so they are ignore in non i2c data requests - setPinModeCallback(i, I2C); + setPinModeCallback(i, PIN_MODE_I2C); } } @@ -692,7 +692,7 @@ void systemResetCallback() // otherwise, pins default to digital output if (IS_PIN_ANALOG(i)) { // turns off pullup, configures everything - setPinModeCallback(i, ANALOG); + setPinModeCallback(i, PIN_MODE_ANALOG); } else if (IS_PIN_DIGITAL(i)) { // sets the output to 0, configures portConfigInputs setPinModeCallback(i, OUTPUT); @@ -770,7 +770,7 @@ void loop() previousMillis += samplingInterval; /* ANALOGREAD - do all analogReads() at the configured sampling interval */ for (pin = 0; pin < TOTAL_PINS; pin++) { - if (IS_PIN_ANALOG(pin) && pinConfig[pin] == ANALOG) { + if (IS_PIN_ANALOG(pin) && pinConfig[pin] == PIN_MODE_ANALOG) { analogPin = PIN_TO_ANALOG(pin); if (analogInputsToReport & (1 << analogPin)) { Firmata.sendAnalog(analogPin, analogRead(analogPin));