Skip to content

Commit 5361118

Browse files
committed
improve documentation
1 parent bc5e578 commit 5361118

File tree

2 files changed

+13
-122
lines changed

2 files changed

+13
-122
lines changed

utility/EncoderFirmata.cpp

Lines changed: 8 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,12 @@
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
*/
12289
boolean 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)
263204
void 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
}

utility/EncoderFirmata.h

Lines changed: 5 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -17,59 +17,8 @@
1717
Provide encoder feature based on PJRC implementation.
1818
See http://www.pjrc.com/teensy/td_libs_Encoder.html for more informations
1919
20-
EncoderFirmata handle sysex instructions and is able to automatically report positions.
21-
22-
Sysex queries :
23-
1. Attach encoder
24-
* ------------------
25-
* 0 START_SYSEX (0xF0)
26-
* 1 ENCODER_DATA (0x61)
27-
* 2 ENCODER_ATTACH (0x00)
28-
* 3 encoder # ([0 - MAX_ENCODERS-1])
29-
* 4 pin A # (first pin)
30-
* 5 pin B # (second pin)
31-
* 6 END_SYSEX (0xF7)
32-
*--------------------
33-
2. Report encoder position
34-
* ------------------
35-
* 0 START_SYSEX (0xF0)
36-
* 1 ENCODER_DATA (0x61)
37-
* 2 ENCODER_REPORT_POSITION (0x01)
38-
* 3 encoder # ([0 - MAX_ENCODERS-1])
39-
* 4 END_SYSEX (0xF7)
40-
*--------------------
41-
3. Report encoders positions
42-
* ------------------
43-
* 0 START_SYSEX (0xF0)
44-
* 1 ENCODER_DATA (0x61)
45-
* 2 ENCODER_REPORT_POSITIONS (0x02)
46-
* 3 END_SYSEX (0xF7)
47-
*--------------------
48-
4. Reset encoder position to zero
49-
* ------------------
50-
* 0 START_SYSEX (0xF0)
51-
* 1 ENCODER_DATA (0x61)
52-
* 2 ENCODER_RESET_POSITION (0x03)
53-
* 3 encoder # ([0 - MAX_ENCODERS-1])
54-
* 4 END_SYSEX (0xF7)
55-
*--------------------
56-
5. Enable/disable reporting ()
57-
* ------------------
58-
* 0 START_SYSEX (0xF0)
59-
* 1 ENCODER_DATA (0x61)
60-
* 2 ENCODER_REPORT_AUTO (0x04)
61-
* 3 enable (0x00 => false, true otherwise)
62-
* 4 END_SYSEX (0xF7)
63-
*--------------------
64-
6. Detach encoder
65-
* ------------------
66-
* 0 START_SYSEX (0xF0)
67-
* 1 ENCODER_DATA (0x61)
68-
* 2 ENCODER_DETACH (0x05)
69-
* 3 encoder # ([0 - MAX_ENCODERS-1])
70-
* 4 END_SYSEX (0xF7)
71-
*--------------------
72-
20+
EncoderFirmata handle instructions and is able to automatically report positions.
21+
See protocol details in "examples / SimpleEncoderFirmata / SimpleEncoderFirmata.ino"
7322
7423
*/
7524

@@ -80,7 +29,7 @@
8029
#include "FirmataFeature.h"
8130

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

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

57+
// EncoderFirmata implementation
10858
void report();
10959
boolean isEncoderAttached(byte encoderNum);
11060
void attachEncoder(byte encoderNum, byte pinANum, byte pinBNum);
11161
void detachEncoder(byte encoderNum);
112-
void reportEncoder(byte encoderNum);
62+
void reportPosition(byte encoderNum);
11363
void reportEncodersPositions();
11464
void resetEncoderPosition(byte encoderNum);
11565
void toggleAutoReport(bool report);

0 commit comments

Comments
 (0)