1414
1515 See file LICENSE.txt for further informations on licensing terms.
1616
17- Provide encoder implementation based on Arduino external interrupts
18- see http://arduino.cc/en/Reference/attachInterrupt for more informations
17+ Provide encoder feature based on PJRC implementation.
18+ See http://www.pjrc.com/teensy/td_libs_Encoder.html for more informations
1919*/
2020
2121#include < Firmata.h>
2222#include " EncoderFirmata.h"
23- // This optional setting causes Encoder to use more optimized code
24- // safe only if 'attachInterrupt' is never used in the same time
25- #define ENCODER_OPTIMIZE_INTERRUPTS
2623#include " Encoder.h"
2724
2825/* Constructor */
@@ -87,37 +84,7 @@ void EncoderFirmata::handleCapability(byte pin)
8784
8885
8986/* Handle ENCODER_DATA (0x61) sysex commands
90- 1. Attach encoder
91- * ------------------
92- * 0 ENCODER_ATTACH (0x00)
93- * 1 encoder # ([0 - MAX_ENCODERS-1])
94- * 2 pin A # (first pin)
95- * 3 pin B # (second pin)
96- *--------------------
97- 2. Report encoder position
98- * ------------------
99- * 0 ENCODER_REPORT_POSITION (0x01)
100- * 1 encoder # ([0 - MAX_ENCODERS-1])
101- *--------------------
102- 3. Report encoders positions
103- * ------------------
104- * 0 ENCODER_REPORT_POSITIONS (0x02)
105- *--------------------
106- 4. Reset encoder position to zero
107- * ------------------
108- * 0 ENCODER_RESET_POSITION (0x03)
109- * 1 encoder # ([0 - MAX_ENCODERS-1])
110- *--------------------
111- 5. Enable/disable reporting ()
112- * ------------------
113- * 0 ENCODER_REPORT_AUTO (0x04)
114- * 1 enable (0x00 => false, true otherwise)
115- *--------------------
116- 6. Detach encoder
117- * ------------------
118- * 0 ENCODER_DETACH (0x05)
119- * 1 encoder # ([0 - MAX_ENCODERS-1])
120- *--------------------
87+ * See protocol details in "examples/SimpleEncoderFirmata/SimpleEncoderFirmata.ino"
12188*/
12289boolean EncoderFirmata::handleSysex (byte command, byte argc, byte *argv)
12390{
@@ -140,7 +107,7 @@ boolean EncoderFirmata::handleSysex(byte command, byte argc, byte *argv)
140107 if (encoderCommand == ENCODER_REPORT_POSITION)
141108 {
142109 encoderNum = argv[1 ];
143- reportEncoder (encoderNum);
110+ reportPosition (encoderNum);
144111 return true ;
145112 }
146113
@@ -218,19 +185,8 @@ void EncoderFirmata::resetEncoderPosition(byte encoderNum)
218185 }
219186}
220187
221- /* Report encoder's postion (one message per encoder)
222- *
223- * MIDI protocol
224- *---------------------
225- * 0 ENCODER_MESSAGE (0x80) | Channel (encoder #, 0-4)
226- * 1 direction (positive = 0, negative = 1)
227- * 2 current position, bits 0-6
228- * 3 current position, bits 7-13
229- * 4 current position, bits 14-20
230- * 5 current position, bits 21-27
231- *--------------------
232- */
233- void EncoderFirmata::reportEncoder (byte encoderNum)
188+ // Report specify encoder postion using midi protocol
189+ void EncoderFirmata::reportPosition (byte encoderNum)
234190{
235191 if (isEncoderAttached (encoderNum))
236192 {
@@ -244,30 +200,15 @@ void EncoderFirmata::reportEncoder(byte encoderNum)
244200 Firmata.write ((byte)(absValue >> 21 ) & 0x7F );
245201 }
246202}
247- /* Report encoders postions (one message for all encoders)
248- *
249- * Sysex message
250- *---------------------
251- * 0 START_SYSEX (0xF0)
252- * 1 ENCODER_DATA (0x61)
253- * 2 first encoder # ([0 - MAX_ENCODERS-1])
254- * 3 first enc. dir. (positive = 0, negative = 1)
255- * 4 first enc. position, bits 0-6
256- * 5 first enc. position, bits 7-13
257- * 6 first enc. position, bits 14-20
258- * 7 first enc. position, bits 21-27
259- * ...
260- * N END_SYSEX (0xF7)
261- *--------------------
262- */
203+ // Report all attached encoders positions (one message for all encoders)
263204void EncoderFirmata::reportEncodersPositions ()
264205{
265206 Firmata.write (START_SYSEX);
266207 Firmata.write (ENCODER_DATA);
267208 byte encoder;
268209 for (encoder=0 ; encoder<MAX_ENCODERS; encoder++)
269210 {
270- reportEncoder (encoder);
211+ reportPosition (encoder);
271212 }
272213 Firmata.write (END_SYSEX);
273214}
0 commit comments