Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
improve documentation
  • Loading branch information
nicolaspanel committed Feb 11, 2014
commit 536111897c62e40943ad0bda50911c73495b8162
75 changes: 8 additions & 67 deletions utility/EncoderFirmata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,12 @@

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

Provide encoder implementation based on Arduino external interrupts
see http://arduino.cc/en/Reference/attachInterrupt for more informations
Provide encoder feature based on PJRC implementation.
See http://www.pjrc.com/teensy/td_libs_Encoder.html for more informations
*/

#include <Firmata.h>
#include "EncoderFirmata.h"
// This optional setting causes Encoder to use more optimized code
// safe only if 'attachInterrupt' is never used in the same time
#define ENCODER_OPTIMIZE_INTERRUPTS
#include "Encoder.h"

/* Constructor */
Expand Down Expand Up @@ -87,37 +84,7 @@ void EncoderFirmata::handleCapability(byte pin)


/* Handle ENCODER_DATA (0x61) sysex commands
1. Attach encoder
* ------------------
* 0 ENCODER_ATTACH (0x00)
* 1 encoder # ([0 - MAX_ENCODERS-1])
* 2 pin A # (first pin)
* 3 pin B # (second pin)
*--------------------
2. Report encoder position
* ------------------
* 0 ENCODER_REPORT_POSITION (0x01)
* 1 encoder # ([0 - MAX_ENCODERS-1])
*--------------------
3. Report encoders positions
* ------------------
* 0 ENCODER_REPORT_POSITIONS (0x02)
*--------------------
4. Reset encoder position to zero
* ------------------
* 0 ENCODER_RESET_POSITION (0x03)
* 1 encoder # ([0 - MAX_ENCODERS-1])
*--------------------
5. Enable/disable reporting ()
* ------------------
* 0 ENCODER_REPORT_AUTO (0x04)
* 1 enable (0x00 => false, true otherwise)
*--------------------
6. Detach encoder
* ------------------
* 0 ENCODER_DETACH (0x05)
* 1 encoder # ([0 - MAX_ENCODERS-1])
*--------------------
* See protocol details in "examples/SimpleEncoderFirmata/SimpleEncoderFirmata.ino"
*/
boolean EncoderFirmata::handleSysex(byte command, byte argc, byte *argv)
{
Expand All @@ -140,7 +107,7 @@ boolean EncoderFirmata::handleSysex(byte command, byte argc, byte *argv)
if (encoderCommand == ENCODER_REPORT_POSITION)
{
encoderNum = argv[1];
reportEncoder(encoderNum);
reportPosition(encoderNum);
return true;
}

Expand Down Expand Up @@ -218,19 +185,8 @@ void EncoderFirmata::resetEncoderPosition(byte encoderNum)
}
}

/* Report encoder's postion (one message per encoder)
*
* MIDI protocol
*---------------------
* 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
*--------------------
*/
void EncoderFirmata::reportEncoder(byte encoderNum)
// Report specify encoder postion using midi protocol
void EncoderFirmata::reportPosition(byte encoderNum)
{
if (isEncoderAttached(encoderNum))
{
Expand All @@ -244,30 +200,15 @@ void EncoderFirmata::reportEncoder(byte encoderNum)
Firmata.write((byte)(absValue >> 21) & 0x7F);
}
}
/* Report encoders postions (one message for all encoders)
*
* Sysex message
*---------------------
* 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)
*--------------------
*/
// Report all attached encoders positions (one message for all encoders)
void EncoderFirmata::reportEncodersPositions()
{
Firmata.write(START_SYSEX);
Firmata.write(ENCODER_DATA);
byte encoder;
for(encoder=0; encoder<MAX_ENCODERS; encoder++)
{
reportEncoder(encoder);
reportPosition(encoder);
}
Firmata.write(END_SYSEX);
}
Expand Down
60 changes: 5 additions & 55 deletions utility/EncoderFirmata.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,59 +17,8 @@
Provide encoder feature based on PJRC implementation.
See http://www.pjrc.com/teensy/td_libs_Encoder.html for more informations

EncoderFirmata handle sysex instructions and is able to automatically report positions.

Sysex queries :
1. Attach encoder
* ------------------
* 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)
*--------------------
2. Report encoder position
* ------------------
* 0 START_SYSEX (0xF0)
* 1 ENCODER_DATA (0x61)
* 2 ENCODER_REPORT_POSITION (0x01)
* 3 encoder # ([0 - MAX_ENCODERS-1])
* 4 END_SYSEX (0xF7)
*--------------------
3. Report encoders positions
* ------------------
* 0 START_SYSEX (0xF0)
* 1 ENCODER_DATA (0x61)
* 2 ENCODER_REPORT_POSITIONS (0x02)
* 3 END_SYSEX (0xF7)
*--------------------
4. Reset encoder position to zero
* ------------------
* 0 START_SYSEX (0xF0)
* 1 ENCODER_DATA (0x61)
* 2 ENCODER_RESET_POSITION (0x03)
* 3 encoder # ([0 - MAX_ENCODERS-1])
* 4 END_SYSEX (0xF7)
*--------------------
5. Enable/disable reporting ()
* ------------------
* 0 START_SYSEX (0xF0)
* 1 ENCODER_DATA (0x61)
* 2 ENCODER_REPORT_AUTO (0x04)
* 3 enable (0x00 => false, true otherwise)
* 4 END_SYSEX (0xF7)
*--------------------
6. Detach encoder
* ------------------
* 0 START_SYSEX (0xF0)
* 1 ENCODER_DATA (0x61)
* 2 ENCODER_DETACH (0x05)
* 3 encoder # ([0 - MAX_ENCODERS-1])
* 4 END_SYSEX (0xF7)
*--------------------

EncoderFirmata handle instructions and is able to automatically report positions.
See protocol details in "examples / SimpleEncoderFirmata / SimpleEncoderFirmata.ino"

*/

Expand All @@ -80,7 +29,7 @@
#include "FirmataFeature.h"

// This optional setting causes Encoder to use more optimized code
// safe only if 'attachInterrupt' is never used in the same time
// safe iif 'attachInterrupt' is never used in the same time
//#define ENCODER_OPTIMIZE_INTERRUPTS // => not compiling
#include "Encoder.h"

Expand All @@ -105,11 +54,12 @@ class EncoderFirmata:public FirmataFeature
boolean handleSysex(byte command, byte argc, byte *argv);
void reset();

// EncoderFirmata implementation
void report();
boolean isEncoderAttached(byte encoderNum);
void attachEncoder(byte encoderNum, byte pinANum, byte pinBNum);
void detachEncoder(byte encoderNum);
void reportEncoder(byte encoderNum);
void reportPosition(byte encoderNum);
void reportEncodersPositions();
void resetEncoderPosition(byte encoderNum);
void toggleAutoReport(bool report);
Expand Down