Skip to content

Commit 9eedf91

Browse files
merging in configurable_dev branch and updating TONE pin mode ID
2 parents ca646cc + 355bdf1 commit 9eedf91

File tree

17 files changed

+1892
-9
lines changed

17 files changed

+1892
-9
lines changed

Boards.h

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ Firmata protocol and the actual pin numbers used by the Arduino
7272
functions. Even though such mappings are often simple, pin
7373
numbers received by Firmata protocol should always be used as
7474
input to these macros, and the result of the macro should be
75-
used with with any Arduino function.
75+
used with any Arduino function.
7676
7777
When Firmata is extended to support a new pin mode or feature,
7878
a pair of macros should be added and used for all hardware
@@ -144,6 +144,7 @@ writePort(port, value, bitmask): Write an 8 bit port.
144144
#define IS_PIN_SERVO(p) (IS_PIN_DIGITAL(p) && (p) - 2 < MAX_SERVOS)
145145
#define IS_PIN_I2C(p) ((p) == 18 || (p) == 19)
146146
#define IS_PIN_SPI(p) ((p) == SS || (p) == MOSI || (p) == MISO || (p) == SCK)
147+
#define IS_PIN_INTERRUPT(p) ((p)==2 || (p)==3)
147148
#define PIN_TO_DIGITAL(p) (p)
148149
#define PIN_TO_ANALOG(p) ((p) - 14)
149150
#define PIN_TO_PWM(p) PIN_TO_DIGITAL(p)
@@ -160,6 +161,7 @@ writePort(port, value, bitmask): Write an 8 bit port.
160161
#define IS_PIN_SERVO(p) ((p) >= 0 && (p) < MAX_SERVOS)
161162
#define IS_PIN_I2C(p) ((p) == SDA || (p) == SCL)
162163
#define IS_PIN_SPI(p) ((p) == SS || (p) == MOSI || (p) == MISO || (p) == SCK)
164+
#define IS_PIN_INTERRUPT(p) 0
163165
#define PIN_TO_DIGITAL(p) (p)
164166
#define PIN_TO_ANALOG(p) ((p) - FIRST_ANALOG_PIN)
165167
#define PIN_TO_PWM(p) PIN_TO_DIGITAL(p)
@@ -176,6 +178,7 @@ writePort(port, value, bitmask): Write an 8 bit port.
176178
#define IS_PIN_PWM(p) digitalPinHasPWM(p)
177179
#define IS_PIN_SERVO(p) (IS_PIN_DIGITAL(p) && (p) - 2 < MAX_SERVOS)
178180
#define IS_PIN_I2C(p) ((p) == 18 || (p) == 19)
181+
#define IS_PIN_INTERRUPT(p) ((p)==2 || (p)==3)
179182
#define PIN_TO_DIGITAL(p) (p)
180183
#define PIN_TO_ANALOG(p) ((p) - 14)
181184
#define PIN_TO_PWM(p) PIN_TO_DIGITAL(p)
@@ -194,6 +197,7 @@ writePort(port, value, bitmask): Write an 8 bit port.
194197
#define IS_PIN_SERVO(p) ((p) >= 2 && (p) - 2 < MAX_SERVOS)
195198
#define IS_PIN_I2C(p) ((p) == 20 || (p) == 21)
196199
#define IS_PIN_SPI(p) ((p) == SS || (p) == MOSI || (p) == MISO || (p) == SCK)
200+
#define IS_PIN_INTERRUPT(p) ((p)==2 || (p)==3 || (p)==18 || (p)==19 || (p)==20 || (p)==21)
197201
#define PIN_TO_DIGITAL(p) (p)
198202
#define PIN_TO_ANALOG(p) ((p) - 54)
199203
#define PIN_TO_PWM(p) PIN_TO_DIGITAL(p)
@@ -210,6 +214,7 @@ writePort(port, value, bitmask): Write an 8 bit port.
210214
#define IS_PIN_PWM(p) digitalPinHasPWM(p)
211215
#define IS_PIN_SERVO(p) ((p) >= 2 && (p) - 2 < MAX_SERVOS)
212216
#define IS_PIN_I2C(p) ((p) == 20 || (p) == 21) // 70 71
217+
#define IS_PIN_INTERRUPT(p) IS_PIN_DIGITAL(p)
213218
#define PIN_TO_DIGITAL(p) (p)
214219
#define PIN_TO_ANALOG(p) ((p) - 54)
215220
#define PIN_TO_PWM(p) PIN_TO_DIGITAL(p)
@@ -227,6 +232,7 @@ writePort(port, value, bitmask): Write an 8 bit port.
227232
#define IS_PIN_SERVO(p) ((p) >= 0 && (p) < MAX_SERVOS)
228233
#define IS_PIN_I2C(p) (0)
229234
#define IS_PIN_SPI(p) ((p) == SS || (p) == MOSI || (p) == MISO || (p) == SCK)
235+
#define IS_PIN_INTERRUPT(p) ((p) == 0 || (p) == 1 || (p) == 2 ||(p) == 3 || (p) == 4 || (p) == 6 ||(p) == 7 ||(p) == 16)
230236
#define PIN_TO_DIGITAL(p) (p)
231237
#define PIN_TO_ANALOG(p) (0)
232238
#define PIN_TO_PWM(p) PIN_TO_DIGITAL(p)
@@ -244,6 +250,7 @@ writePort(port, value, bitmask): Write an 8 bit port.
244250
#define IS_PIN_SERVO(p) ((p) >= 0 && (p) < MAX_SERVOS)
245251
#define IS_PIN_I2C(p) ((p) == 5 || (p) == 6)
246252
#define IS_PIN_SPI(p) ((p) == SS || (p) == MOSI || (p) == MISO || (p) == SCK)
253+
#define IS_PIN_INTERRUPT(p) ((p) == 5 || (p) == 6 || (p) == 7 || (p) == 8)
247254
#define PIN_TO_DIGITAL(p) (p)
248255
#define PIN_TO_ANALOG(p) (((p)<22)?21-(p):11)
249256
#define PIN_TO_PWM(p) PIN_TO_DIGITAL(p)
@@ -260,6 +267,7 @@ writePort(port, value, bitmask): Write an 8 bit port.
260267
#define IS_PIN_PWM(p) digitalPinHasPWM(p)
261268
#define IS_PIN_SERVO(p) ((p) >= 0 && (p) < MAX_SERVOS)
262269
#define IS_PIN_I2C(p) ((p) == 18 || (p) == 19)
270+
#define IS_PIN_INTERRUPT(p) IS_PIN_DIGITAL(p)
263271
#define PIN_TO_DIGITAL(p) (p)
264272
#define PIN_TO_ANALOG(p) (((p)<=23)?(p)-14:(p)-24)
265273
#define PIN_TO_PWM(p) PIN_TO_DIGITAL(p)
@@ -277,6 +285,7 @@ writePort(port, value, bitmask): Write an 8 bit port.
277285
#define IS_PIN_SERVO(p) ((p) >= 0 && (p) < MAX_SERVOS)
278286
#define IS_PIN_I2C(p) ((p) == 0 || (p) == 1)
279287
#define IS_PIN_SPI(p) ((p) == SS || (p) == MOSI || (p) == MISO || (p) == SCK)
288+
#define IS_PIN_INTERRUPT(p) ((p) == 0 || (p) == 1 || (p) == 2 ||(p) == 3 ||(p) == 18 ||(p) == 19 ||(p) == 36 ||(p) == 37)
280289
#define PIN_TO_DIGITAL(p) (p)
281290
#define PIN_TO_ANALOG(p) ((p) - 38)
282291
#define PIN_TO_PWM(p) PIN_TO_DIGITAL(p)
@@ -294,6 +303,7 @@ writePort(port, value, bitmask): Write an 8 bit port.
294303
#define IS_PIN_SERVO(p) ((p) >= 0 && (p) < MAX_SERVOS)
295304
#define IS_PIN_I2C(p) ((p) == 2 || (p) == 3)
296305
#define IS_PIN_SPI(p) ((p) == SS || (p) == MOSI || (p) == MISO || (p) == SCK)
306+
#define IS_PIN_INTERRUPT(p) ((p)==0 || (p)==1 || (p)==2 || (p)==3 || (p)==7)
297307
#define PIN_TO_DIGITAL(p) (p)
298308
#define PIN_TO_ANALOG(p) (p) - 18
299309
#define PIN_TO_PWM(p) PIN_TO_DIGITAL(p)
@@ -310,6 +320,7 @@ writePort(port, value, bitmask): Write an 8 bit port.
310320
#define IS_PIN_PWM(p) digitalPinHasPWM(p)
311321
#define IS_PIN_SERVO(p) ((p) >= 0 && (p) < MAX_SERVOS)
312322
#define IS_PIN_I2C(p) ((p) == 16 || (p) == 17)
323+
#define IS_PIN_INTERRUPT(p) ((p)==2 || (p)==10 || (p)==11)
313324
#define PIN_TO_DIGITAL(p) (p)
314325
#define PIN_TO_ANALOG(p) ((p) - 24)
315326
#define PIN_TO_PWM(p) PIN_TO_DIGITAL(p)
@@ -326,6 +337,7 @@ writePort(port, value, bitmask): Write an 8 bit port.
326337
#define IS_PIN_PWM(p) digitalPinHasPWM(p)
327338
#define IS_PIN_SERVO(p) ((p) >= 0 && (p) < MAX_SERVOS)
328339
#define IS_PIN_I2C(p) ((p) == 4 || (p) == 5)
340+
#define IS_PIN_INTERRUPT(p) (0)
329341
#define PIN_TO_DIGITAL(p) (p)
330342
#define PIN_TO_ANALOG(p) ((p) - 36)
331343
#define PIN_TO_PWM(p) PIN_TO_DIGITAL(p)
@@ -339,7 +351,7 @@ writePort(port, value, bitmask): Write an 8 bit port.
339351

340352
// as long this is not defined for all boards:
341353
#ifndef IS_PIN_SPI
342-
#define IS_PIN_SPI(p) 0
354+
#define IS_PIN_SPI(p) (0)
343355
#endif
344356

345357
/*==============================================================================

Firmata.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
* software can test whether it will be compatible with the currently
2121
* installed firmware. */
2222
#define FIRMATA_MAJOR_VERSION 2 // for non-compatible changes
23-
#define FIRMATA_MINOR_VERSION 5 // for backwards compatible changes
23+
#define FIRMATA_MINOR_VERSION 6 // for backwards compatible changes
2424
#define FIRMATA_BUGFIX_VERSION 0 // for bugfix releases
2525

2626
#define MAX_DATA_BYTES 64 // max number of data bytes in incoming messages
@@ -41,7 +41,8 @@
4141

4242
// extended command set using sysex (0-127/0x00-0x7F)
4343
/* 0x00-0x0F reserved for user-defined commands */
44-
#define TONE_DATA 0x5F // send a tone or noTone command
44+
#define TONE_DATA 0x5F // send a tone or noTone command
45+
#define ENCODER_DATA 0x61 // reply with encoders current positions
4546
#define SERVO_CONFIG 0x70 // set max angle, minPulse, maxPulse, freq
4647
#define STRING_DATA 0x71 // a string message with 14-bits per char
4748
#define STEPPER_DATA 0x72 // control a stepper motor
@@ -62,6 +63,7 @@
6263
#define SCHEDULER_DATA 0x7B // send a createtask/deletetask/addtotask/schedule/querytasks/querytask request to the scheduler
6364
#define SYSEX_NON_REALTIME 0x7E // MIDI Reserved for non-realtime messages
6465
#define SYSEX_REALTIME 0x7F // MIDI Reserved for realtime messages
66+
6567
// these are DEPRECATED to make the naming more consistent
6668
#define FIRMATA_STRING 0x71 // same as STRING_DATA
6769
#define SYSEX_I2C_REQUEST 0x76 // same as I2C_REQUEST
@@ -78,9 +80,10 @@
7880
#define I2C 0x06 // pin included in I2C setup
7981
#define ONEWIRE 0x07 // pin configured for 1-wire
8082
#define STEPPER 0x08 // pin configured for stepper motor
81-
#define TONE 0x09 // pin configured for tone function
83+
#define ENCODER 0x09 // pin configured for encoders
84+
#define TONE 0x0A // pin configured for tone function
8285
#define IGNORE 0x7F // pin configured to be ignored by digitalWrite and capabilityResponse
83-
#define TOTAL_PIN_MODES 11
86+
#define TOTAL_PIN_MODES 12
8487

8588
extern "C" {
8689
// callback function types

examples/ConfigurableFirmata/ConfigurableFirmata.ino

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
Copyright (C) 2009 Shigeru Kobayashi. All rights reserved.
1616
Copyright (C) 2009-2013 Jeff Hoefs. All rights reserved.
1717
Copyright (C) 2013 Norbert Truchsess. All rights reserved.
18+
Copyright (C) 2014 Nicolas Panel. All rights reserved.
1819
1920
This library is free software; you can redistribute it and/or
2021
modify it under the terms of the GNU Lesser General Public
@@ -108,13 +109,16 @@ FirmataExt firmataExt;
108109
#include <utility/FirmataScheduler.h>
109110
FirmataScheduler scheduler;
110111

112+
#include <utility/EncoderFirmata.h>
113+
EncoderFirmata encoder;
114+
111115

112116
// dependencies. Do not comment out the following lines
113117
#if defined AnalogOutputFirmata_h || defined ServoFirmata_h
114118
#include <utility/AnalogWrite.h>
115119
#endif
116120

117-
#if defined AnalogInputFirmata_h || defined I2CFirmata_h
121+
#if defined AnalogInputFirmata_h || defined I2CFirmata_h || defined EncoderFirmata_h
118122
#include <utility/FirmataReporting.h>
119123
FirmataReporting reporting;
120124
#endif
@@ -226,6 +230,9 @@ void setup()
226230
#ifdef FirmataScheduler_h
227231
firmataExt.addFeature(scheduler);
228232
#endif
233+
#ifdef EncoderFirmata_h
234+
firmataExt.addFeature(encoder);
235+
#endif
229236
#endif
230237
/* systemResetCallback is declared here (in ConfigurableFirmata.ino) */
231238
Firmata.attach(SYSTEM_RESET, systemResetCallback);
@@ -295,6 +302,10 @@ runtasks: scheduler.runTasks();
295302
#ifdef I2CFirmata_h
296303
// report i2c data for all device with read continuous mode enabled
297304
i2c.report();
305+
#endif
306+
#ifdef EncoderFirmata_h
307+
// report encoders positions if reporting enabled.
308+
encoder.report();
298309
#endif
299310
}
300311
#endif
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/*
2+
* Firmata is a generic protocol for communicating with microcontrollers
3+
* from software on a host computer. It is intended to work with
4+
* any host computer software package.
5+
*
6+
* To download a host software package, please click on the following link
7+
* to open the download page in your default browser.
8+
*
9+
* http://firmata.org/wiki/Download
10+
*/
11+
12+
/*
13+
Copyright (C) 2006-2008 Hans-Christoph Steiner. All rights reserved.
14+
Copyright (C) 2010-2011 Paul Stoffregen. All rights reserved.
15+
Copyright (C) 2009 Shigeru Kobayashi. All rights reserved.
16+
Copyright (C) 2009-2013 Jeff Hoefs. All rights reserved.
17+
Copyright (C) 2013 Norbert Truchsess. All rights reserved.
18+
Copyright (C) 2014 Nicolas Panel. All rights reserved.
19+
20+
This library is free software; you can redistribute it and/or
21+
modify it under the terms of the GNU Lesser General Public
22+
License as published by the Free Software Foundation; either
23+
version 2.1 of the License, or (at your option) any later version.
24+
25+
See file LICENSE.txt for further informations on licensing terms.
26+
27+
formatted using the GNU C formatting and indenting
28+
29+
*/
30+
31+
//* Due to arduino issue, Wire and Servo libraries need to be included. Should be fixed in later versions
32+
#include <Wire.h>
33+
#include <Servo.h>
34+
//*/
35+
#include <Firmata.h>
36+
#include <utility/FirmataExt.h>
37+
#include <utility/FirmataReporting.h>
38+
#include <utility/EncoderFirmata.h>
39+
40+
FirmataExt firmataExt;
41+
FirmataReporting reporting;
42+
EncoderFirmata encoder;
43+
44+
/*==============================================================================
45+
* FUNCTIONS
46+
*============================================================================*/
47+
void systemResetCallback()
48+
{
49+
firmataExt.reset();
50+
}
51+
52+
/*==============================================================================
53+
* SETUP()
54+
*============================================================================*/
55+
void setup()
56+
{
57+
Firmata.setFirmwareVersion(FIRMATA_MAJOR_VERSION, FIRMATA_MINOR_VERSION);
58+
firmataExt.addFeature(reporting);
59+
firmataExt.addFeature(encoder);
60+
/* systemResetCallback is declared here (in ConfigurableFirmata.ino) */
61+
Firmata.attach(SYSTEM_RESET, systemResetCallback);
62+
Firmata.begin(57600);
63+
systemResetCallback(); // reset to default config
64+
}
65+
66+
/*==============================================================================
67+
* LOOP()
68+
*============================================================================*/
69+
void loop()
70+
{
71+
/* STREAMREAD - processing incoming messagse as soon as possible, while still
72+
* checking digital inputs. */
73+
while(Firmata.available()) {
74+
Firmata.processInput();
75+
}
76+
77+
if (reporting.elapsed()) {
78+
encoder.report();
79+
}
80+
}

readme.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Most of the time you will be interacting with arduino with a client library on t
1818
* [https://github.com/firmata/pyduino]
1919
* [https://github.com/lupeke/python-firmata]
2020
* [https://github.com/tino/pyFirmata]
21+
* [https://github.com/MrYsLab/PyMata]
2122
* perl
2223
* [https://github.com/ntruchsess/perl-firmata]
2324
* [https://github.com/rcaputo/rx-firmata]
@@ -41,6 +42,10 @@ Most of the time you will be interacting with arduino with a client library on t
4142
* [http://code.google.com/p/as3glue/]
4243
* PHP
4344
* [https://bitbucket.org/ThomasWeinert/carica-firmata]
45+
* Haskell
46+
* [http://hackage.haskell.org/package/hArduino]
47+
* iOS
48+
* [https://github.com/jacobrosenthal/iosfirmata]
4449

4550
Note: The above libraries may support various versions of the Firmata protocol and therefore may not support all features of the latest Firmata spec nor all arduino and arduino-compatible boards. Refer to the respective projects for details.
4651

release.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
mkdir -p temp/Firmata
88
cp -r examples temp/Firmata
99
cp -r extras temp/Firmata
10+
cp -r utility temp/Firmata
1011
cp Boards.h temp/Firmata
1112
cp Firmata.cpp temp/Firmata
1213
cp Firmata.h temp/Firmata
@@ -16,7 +17,7 @@ cd temp
1617
find . -name "*.DS_Store" -type f -delete
1718
zip -r Firmata.zip ./Firmata/
1819
cd ..
19-
mv ./temp/Firmata.zip Firmata-2.4.0.zip
20+
mv ./temp/Firmata.zip Firmata-2.5.0.zip
2021

2122
#package for Arduino 1.5.x
2223
cp library.properties temp/Firmata
@@ -26,9 +27,10 @@ mkdir src
2627
mv Boards.h ./src/
2728
mv Firmata.cpp ./src/
2829
mv Firmata.h ./src/
30+
mv utility ./src/
2931
cd ..
3032
find . -name "*.DS_Store" -type f -delete
3133
zip -r Firmata.zip ./Firmata/
3234
cd ..
33-
mv ./temp/Firmata.zip Arduino-1.5.x-Firmata-2.4.0.zip
35+
mv ./temp/Firmata.zip Arduino-1.5.x-Firmata-2.5.0.zip
3436
rm -r ./temp

0 commit comments

Comments
 (0)