Skip to content
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
769803f
updated readme to add new Firmata client libraries
soundanalogous Nov 18, 2013
ecc1b87
remove duplicate word
nicolaspanel Feb 10, 2014
d8f9a75
add interrupt pins, see http://arduino.cc/en/Reference/attachInterrup…
nicolaspanel Feb 10, 2014
58c0518
create EncoderFirmata header file
nicolaspanel Feb 10, 2014
a40eb12
add private method to report all encoders positions
nicolaspanel Feb 10, 2014
3bcec4a
improve documentation
nicolaspanel Feb 10, 2014
3dc34c1
fix syntax issues
nicolaspanel Feb 10, 2014
ccfe8af
add EncoderFirmata implementation file
nicolaspanel Feb 10, 2014
084b667
implement EncoderFirmata
nicolaspanel Feb 10, 2014
b2b5f62
update IS_PIN_INTERRPUT macros, according to http://www.pjrc.com/teen…
nicolaspanel Feb 10, 2014
3a6aacf
update ConfigurableFirmata to manage Encoders
nicolaspanel Feb 10, 2014
c1fe131
rename encoder utilities folder
nicolaspanel Feb 10, 2014
5ce5007
fix synthax errors and and encoder unit tests
Feb 10, 2014
b27db4c
fix remaining bugs and improve testing coverage
Feb 10, 2014
e3977a1
move function to public to improve tests
nicolaspanel Feb 11, 2014
09f240f
improve tests and check for memory leaks
nicolaspanel Feb 11, 2014
bc5e578
add example.ion file for encoders, including protocol proposal
nicolaspanel Feb 11, 2014
5361118
improve documentation
nicolaspanel Feb 11, 2014
4b7b718
Merge branch 'encoders'
nicolaspanel Feb 11, 2014
8a803dc
improve testing and documentation
Feb 11, 2014
113cbd0
add reference to wire and servo to avoid compilation issue
Feb 11, 2014
72aec53
ConfigurableFirmata.ino compiling. Size : 30kbytes
Feb 11, 2014
26e95e3
Automatic reporting report one encoder at the time (best performences)
nicolaspanel Feb 14, 2014
0b2e630
fix naming issue
nicolaspanel Feb 14, 2014
6861d19
improve full report test
nicolaspanel Feb 14, 2014
be9f18e
Merge branch 'develop'
nicolaspanel Feb 14, 2014
dc237a2
there is discussion on the Arduino dev list about resolving this prob…
nicolaspanel Feb 14, 2014
3d7d8b9
Errors and warnings are commented to avoid out-of-sram error.
nicolaspanel Feb 14, 2014
12624a1
AVR gcc doen't implement a true C++ delete so use free instead
nicolaspanel Feb 14, 2014
415a002
Manage ENCODER pin mode
nicolaspanel Feb 14, 2014
4a29597
determine how much memory each instance
nicolaspanel Feb 14, 2014
fdffde9
rename test
nicolaspanel Feb 14, 2014
35aad7d
fix
nicolaspanel Feb 14, 2014
c8dfb81
update tests
nicolaspanel Feb 14, 2014
7e42f61
tests improvement
nicolaspanel Feb 14, 2014
8fa3f0f
change ENCODER to 11 (0x0B)
nicolaspanel Feb 14, 2014
e63bc82
update total pin modes number
nicolaspanel Feb 15, 2014
d1e7eb5
Use sysex responses instead of MIDI
nicolaspanel Feb 16, 2014
f643b34
fix remaining bugs
nicolaspanel Feb 16, 2014
9037100
Report positions only when at least 1 encoder is attached
nicolaspanel Feb 16, 2014
6730517
fix remaining bugs
nicolaspanel Feb 16, 2014
9a7d6ff
fix remaining bugs
nicolaspanel Feb 16, 2014
ff0a55f
Report encoder position after initialization (Firmata convention, eve…
nicolaspanel Feb 16, 2014
47fc4e6
Move ENCODER_DATA instruction to Firmata.h
nicolaspanel Feb 17, 2014
de3052d
use FakeStream#reset instead of FakeStream#flush to cleanup the stream
Feb 17, 2014
cd1f295
Merge pull request #119 from nicolaspanel/master
ntruchsess Feb 20, 2014
8d5f462
implement reporting for changed positions only
ntruchsess Feb 28, 2014
3d7ec6c
memory optimize reportPositions(), adjust test_encoder.ino to match n…
ntruchsess Feb 28, 2014
355bdf1
Merge pull request #120 from ntruchsess/encoder_report_changedonly
ntruchsess Feb 28, 2014
de0d009
remove makefiles from examples
soundanalogous Mar 9, 2014
07c2fa9
added intel galileo to boards.h
soundanalogous Mar 9, 2014
7a67148
update library properties for new IDE 1.5.6 format
soundanalogous Mar 9, 2014
4d746e8
update version in headers and build script
soundanalogous Mar 9, 2014
2a94af8
update readme
soundanalogous Mar 9, 2014
988d3c2
copy over changes from these commits: 27f7e4276974a6a5c74008490f23ba5…
soundanalogous Mar 9, 2014
572f4b3
remove arduino 1.5.x specific build because original build works for …
soundanalogous Mar 9, 2014
2b6bc1e
add back line to delete temp directory
soundanalogous Mar 9, 2014
b524dfc
missing equal sign in comparison
soundanalogous Mar 9, 2014
9cb7d4f
formatting change
soundanalogous Mar 9, 2014
ef50e73
saving a few bytes
soundanalogous Mar 9, 2014
2764059
Merge pull request #122 from firmata/merge-in-dev
soundanalogous Mar 30, 2014
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
16 changes: 14 additions & 2 deletions Boards.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ Firmata protocol and the actual pin numbers used by the Arduino
functions. Even though such mappings are often simple, pin
numbers received by Firmata protocol should always be used as
input to these macros, and the result of the macro should be
used with with any Arduino function.
used with any Arduino function.

When Firmata is extended to support a new pin mode or feature,
a pair of macros should be added and used for all hardware
Expand Down Expand Up @@ -144,6 +144,7 @@ writePort(port, value, bitmask): Write an 8 bit port.
#define IS_PIN_SERVO(p) (IS_PIN_DIGITAL(p) && (p) - 2 < MAX_SERVOS)
#define IS_PIN_I2C(p) ((p) == 18 || (p) == 19)
#define IS_PIN_SPI(p) ((p) == SS || (p) == MOSI || (p) == MISO || (p) == SCK)
#define IS_PIN_INTERRUPT(p) ((p)==2 || (p)==3)
#define PIN_TO_DIGITAL(p) (p)
#define PIN_TO_ANALOG(p) ((p) - 14)
#define PIN_TO_PWM(p) PIN_TO_DIGITAL(p)
Expand All @@ -160,6 +161,7 @@ writePort(port, value, bitmask): Write an 8 bit port.
#define IS_PIN_SERVO(p) ((p) >= 0 && (p) < MAX_SERVOS)
#define IS_PIN_I2C(p) ((p) == SDA || (p) == SCL)
#define IS_PIN_SPI(p) ((p) == SS || (p) == MOSI || (p) == MISO || (p) == SCK)
#define IS_PIN_INTERRUPT(p) 0
#define PIN_TO_DIGITAL(p) (p)
#define PIN_TO_ANALOG(p) ((p) - FIRST_ANALOG_PIN)
#define PIN_TO_PWM(p) PIN_TO_DIGITAL(p)
Expand All @@ -176,6 +178,7 @@ writePort(port, value, bitmask): Write an 8 bit port.
#define IS_PIN_PWM(p) digitalPinHasPWM(p)
#define IS_PIN_SERVO(p) (IS_PIN_DIGITAL(p) && (p) - 2 < MAX_SERVOS)
#define IS_PIN_I2C(p) ((p) == 18 || (p) == 19)
#define IS_PIN_INTERRUPT(p) ((p)==2 || (p)==3)
#define PIN_TO_DIGITAL(p) (p)
#define PIN_TO_ANALOG(p) ((p) - 14)
#define PIN_TO_PWM(p) PIN_TO_DIGITAL(p)
Expand All @@ -194,6 +197,7 @@ writePort(port, value, bitmask): Write an 8 bit port.
#define IS_PIN_SERVO(p) ((p) >= 2 && (p) - 2 < MAX_SERVOS)
#define IS_PIN_I2C(p) ((p) == 20 || (p) == 21)
#define IS_PIN_SPI(p) ((p) == SS || (p) == MOSI || (p) == MISO || (p) == SCK)
#define IS_PIN_INTERRUPT(p) ((p)==2 || (p)==3 || (p)==18 || (p)==19 || (p)==20 || (p)==21)
#define PIN_TO_DIGITAL(p) (p)
#define PIN_TO_ANALOG(p) ((p) - 54)
#define PIN_TO_PWM(p) PIN_TO_DIGITAL(p)
Expand All @@ -210,6 +214,7 @@ writePort(port, value, bitmask): Write an 8 bit port.
#define IS_PIN_PWM(p) digitalPinHasPWM(p)
#define IS_PIN_SERVO(p) ((p) >= 2 && (p) - 2 < MAX_SERVOS)
#define IS_PIN_I2C(p) ((p) == 20 || (p) == 21) // 70 71
#define IS_PIN_INTERRUPT(p) IS_PIN_DIGITAL(p)
#define PIN_TO_DIGITAL(p) (p)
#define PIN_TO_ANALOG(p) ((p) - 54)
#define PIN_TO_PWM(p) PIN_TO_DIGITAL(p)
Expand All @@ -227,6 +232,7 @@ writePort(port, value, bitmask): Write an 8 bit port.
#define IS_PIN_SERVO(p) ((p) >= 0 && (p) < MAX_SERVOS)
#define IS_PIN_I2C(p) (0)
#define IS_PIN_SPI(p) ((p) == SS || (p) == MOSI || (p) == MISO || (p) == SCK)
#define IS_PIN_INTERRUPT(p) ((p) == 0 || (p) == 1 || (p) == 2 ||(p) == 3 || (p) == 4 || (p) == 6 ||(p) == 7 ||(p) == 16)
#define PIN_TO_DIGITAL(p) (p)
#define PIN_TO_ANALOG(p) (0)
#define PIN_TO_PWM(p) PIN_TO_DIGITAL(p)
Expand All @@ -244,6 +250,7 @@ writePort(port, value, bitmask): Write an 8 bit port.
#define IS_PIN_SERVO(p) ((p) >= 0 && (p) < MAX_SERVOS)
#define IS_PIN_I2C(p) ((p) == 5 || (p) == 6)
#define IS_PIN_SPI(p) ((p) == SS || (p) == MOSI || (p) == MISO || (p) == SCK)
#define IS_PIN_INTERRUPT(p) ((p) == 5 || (p) == 6 || (p) == 7 || (p) == 8)
#define PIN_TO_DIGITAL(p) (p)
#define PIN_TO_ANALOG(p) (((p)<22)?21-(p):11)
#define PIN_TO_PWM(p) PIN_TO_DIGITAL(p)
Expand All @@ -260,6 +267,7 @@ writePort(port, value, bitmask): Write an 8 bit port.
#define IS_PIN_PWM(p) digitalPinHasPWM(p)
#define IS_PIN_SERVO(p) ((p) >= 0 && (p) < MAX_SERVOS)
#define IS_PIN_I2C(p) ((p) == 18 || (p) == 19)
#define IS_PIN_INTERRUPT(p) IS_PIN_DIGITAL(p)
#define PIN_TO_DIGITAL(p) (p)
#define PIN_TO_ANALOG(p) (((p)<=23)?(p)-14:(p)-24)
#define PIN_TO_PWM(p) PIN_TO_DIGITAL(p)
Expand All @@ -277,6 +285,7 @@ writePort(port, value, bitmask): Write an 8 bit port.
#define IS_PIN_SERVO(p) ((p) >= 0 && (p) < MAX_SERVOS)
#define IS_PIN_I2C(p) ((p) == 0 || (p) == 1)
#define IS_PIN_SPI(p) ((p) == SS || (p) == MOSI || (p) == MISO || (p) == SCK)
#define IS_PIN_INTERRUPT(p) ((p) == 0 || (p) == 1 || (p) == 2 ||(p) == 3 ||(p) == 18 ||(p) == 19 ||(p) == 36 ||(p) == 37)
#define PIN_TO_DIGITAL(p) (p)
#define PIN_TO_ANALOG(p) ((p) - 38)
#define PIN_TO_PWM(p) PIN_TO_DIGITAL(p)
Expand All @@ -294,6 +303,7 @@ writePort(port, value, bitmask): Write an 8 bit port.
#define IS_PIN_SERVO(p) ((p) >= 0 && (p) < MAX_SERVOS)
#define IS_PIN_I2C(p) ((p) == 2 || (p) == 3)
#define IS_PIN_SPI(p) ((p) == SS || (p) == MOSI || (p) == MISO || (p) == SCK)
#define IS_PIN_INTERRUPT(p) ((p)==0 || (p)==1 || (p)==2 || (p)==3 || (p)==7)
#define PIN_TO_DIGITAL(p) (p)
#define PIN_TO_ANALOG(p) (p) - 18
#define PIN_TO_PWM(p) PIN_TO_DIGITAL(p)
Expand All @@ -310,6 +320,7 @@ writePort(port, value, bitmask): Write an 8 bit port.
#define IS_PIN_PWM(p) digitalPinHasPWM(p)
#define IS_PIN_SERVO(p) ((p) >= 0 && (p) < MAX_SERVOS)
#define IS_PIN_I2C(p) ((p) == 16 || (p) == 17)
#define IS_PIN_INTERRUPT(p) ((p)==2 || (p)==10 || (p)==11)
#define PIN_TO_DIGITAL(p) (p)
#define PIN_TO_ANALOG(p) ((p) - 24)
#define PIN_TO_PWM(p) PIN_TO_DIGITAL(p)
Expand All @@ -326,6 +337,7 @@ writePort(port, value, bitmask): Write an 8 bit port.
#define IS_PIN_PWM(p) digitalPinHasPWM(p)
#define IS_PIN_SERVO(p) ((p) >= 0 && (p) < MAX_SERVOS)
#define IS_PIN_I2C(p) ((p) == 4 || (p) == 5)
#define IS_PIN_INTERRUPT(p) (0)
#define PIN_TO_DIGITAL(p) (p)
#define PIN_TO_ANALOG(p) ((p) - 36)
#define PIN_TO_PWM(p) PIN_TO_DIGITAL(p)
Expand All @@ -339,7 +351,7 @@ writePort(port, value, bitmask): Write an 8 bit port.

// as long this is not defined for all boards:
#ifndef IS_PIN_SPI
#define IS_PIN_SPI(p) 0
#define IS_PIN_SPI(p) (0)
#endif

/*==============================================================================
Expand Down
12 changes: 11 additions & 1 deletion examples/ConfigurableFirmata/ConfigurableFirmata.ino
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,16 @@ FirmataExt firmataExt;
#include <utility/FirmataScheduler.h>
FirmataScheduler scheduler;

#include <utility/EncoderFirmata.h>
EncoderFirmata encoder;


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

#if defined AnalogInputFirmata_h || defined I2CFirmata_h
#if defined AnalogInputFirmata_h || defined I2CFirmata_h || defined EncoderFirmata_h
#include <utility/FirmataReporting.h>
FirmataReporting reporting;
#endif
Expand Down Expand Up @@ -220,6 +223,9 @@ void setup()
#ifdef FirmataScheduler_h
firmataExt.addFeature(scheduler);
#endif
#ifdef EncoderFirmata_h
firmataExt.addFeature(encoder);
#endif
#endif
/* systemResetCallback is declared here (in ConfigurableFirmata.ino) */
Firmata.attach(SYSTEM_RESET, systemResetCallback);
Expand Down Expand Up @@ -289,6 +295,10 @@ runtasks: scheduler.runTasks();
#ifdef I2CFirmata_h
// report i2c data for all device with read continuous mode enabled
i2c.report();
#endif
#ifdef EncoderFirmata_h
// report encoders positions if reporting enabled.
encoder.report();
#endif
}
#endif
Expand Down
160 changes: 160 additions & 0 deletions examples/SimpleEncoderFirmata/SimpleEncoderFirmata.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
/*
* Firmata is a generic protocol for communicating with microcontrollers
* from software on a host computer. It is intended to work with
* any host computer software package.
*
* To download a host software package, please click on the following link
* to open the download page in your default browser.
*
* http://firmata.org/wiki/Download
*/

/*
Copyright (C) 2006-2008 Hans-Christoph Steiner. All rights reserved.
Copyright (C) 2010-2011 Paul Stoffregen. All rights reserved.
Copyright (C) 2009 Shigeru Kobayashi. All rights reserved.
Copyright (C) 2009-2013 Jeff Hoefs. All rights reserved.
Copyright (C) 2013 Norbert Truchsess. All rights reserved.
Copyright (C) 2014 Nicolas Panel. All rights reserved.

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

See file LICENSE.txt for further informations on licensing terms.

formatted using the GNU C formatting and indenting

* =====================================================
* Encoder PROTOCOL
* =====================================================
*
* Attach encoder query
* -----------------------------------------------------
* 0 START_SYSEX (0xF0)
* 1 ENCODER_DATA (0x61)
* 2 ENCODER_ATTACH (0x00)
* 3 encoder # ([0 - MAX_ENCODERS-1])
* 4 pin A # (first pin)
* 5 pin B # (second pin)
* 6 END_SYSEX (0xF7)
* -----------------------------------------------------
*
* Report encoder's position
* -----------------------------------------------------
* Sysex Query
* ------------------
* 0 START_SYSEX (0xF0)
* 1 ENCODER_DATA (0x61)
* 2 ENCODER_REPORT_POSITION (0x01)
* 3 encoder # ([0 - MAX_ENCODERS-1])
* 4 END_SYSEX (0xF7)
*--------------------
* MIDI Response
* ------------------
* 0 ENCODER_MESSAGE (0x80) | Channel (encoder #, 0-4)
* 1 direction (positive = 0, negative = 1)
* 2 current position, bits 0-6
* 3 current position, bits 7-13
* 4 current position, bits 14-20
* 5 current position, bits 21-27
* -----------------------------------------------------
*
* Report all encoders positions
* -----------------------------------------------------
* Sysex Query
* ------------------
* 0 START_SYSEX (0xF0)
* 1 ENCODER_DATA (0x61)
* 2 ENCODER_REPORT_POSITIONS (0x02)
* 3 END_SYSEX (0xF7)
*--------------------
* Sysex Response
* ------------------
* 0 START_SYSEX (0xF0)
* 1 ENCODER_DATA (0x61)
* 2 first encoder # ([0 - MAX_ENCODERS-1])
* 3 first enc. dir. (positive = 0, negative = 1)
* 4 first enc. position, bits 0-6
* 5 first enc. position, bits 7-13
* 6 first enc. position, bits 14-20
* 7 first enc. position, bits 21-27
* ...
* N END_SYSEX (0xF7)
* -----------------------------------------------------
*
* Reset encoder position to zero (Sysex Query)
* -----------------------------------------------------
* 0 START_SYSEX (0xF0)
* 1 ENCODER_DATA (0x61)
* 2 ENCODER_RESET_POSITION (0x03)
* 3 encoder # ([0 - MAX_ENCODERS-1])
* 4 END_SYSEX (0xF7)
* -----------------------------------------------------
*
* Enable/disable reporting (Sysex Query)
* -----------------------------------------------------
* 0 START_SYSEX (0xF0)
* 1 ENCODER_DATA (0x61)
* 2 ENCODER_REPORT_AUTO (0x04)
* 3 enable (0x00 => false, true otherwise)
* 4 END_SYSEX (0xF7)
* -----------------------------------------------------
*
* Detach encoder (Sysex Query)
* -----------------------------------------------------
* 0 START_SYSEX (0xF0)
* 1 ENCODER_DATA (0x61)
* 2 ENCODER_DETACH (0x05)
* 3 encoder # ([0 - MAX_ENCODERS-1])
* 4 END_SYSEX (0xF7)
*--------------------
*/

#include <Firmata.h>
#include <utility/FirmataExt.h>
#include <utility/FirmataReporting.h>
#include <utility/EncoderFirmata.h>

FirmataExt firmataExt;
FirmataReporting reporting;
EncoderFirmata encoder;

/*==============================================================================
* FUNCTIONS
*============================================================================*/
void systemResetCallback()
{
firmataExt.reset();
}

/*==============================================================================
* SETUP()
*============================================================================*/
void setup()
{
Firmata.setFirmwareVersion(FIRMATA_MAJOR_VERSION, FIRMATA_MINOR_VERSION);
firmataExt.addFeature(reporting);
firmataExt.addFeature(encoder);
/* systemResetCallback is declared here (in ConfigurableFirmata.ino) */
Firmata.attach(SYSTEM_RESET, systemResetCallback);
Firmata.begin(57600);
systemResetCallback(); // reset to default config
}

/*==============================================================================
* LOOP()
*============================================================================*/
void loop()
{
/* STREAMREAD - processing incoming messagse as soon as possible, while still
* checking digital inputs. */
while(Firmata.available()) {
Firmata.processInput();
}

if (reporting.elapsed()) {
encoder.report();
}
}
Loading