Skip to content

Commit 29b4399

Browse files
committed
Address code review comments/concerns
1 parent 34ecce3 commit 29b4399

File tree

4 files changed

+48
-30
lines changed

4 files changed

+48
-30
lines changed

FirmataMarshaller.cpp

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ void FirmataMarshaller::end(void)
124124
void FirmataMarshaller::reportAnalogDisable(uint8_t pin)
125125
const
126126
{
127-
reportAnalog(pin, false);
127+
reportAnalog(pin, false);
128128
}
129129

130130
/**
@@ -133,13 +133,11 @@ const
133133
* (16384). To increase the pin range or value, see the documentation for the EXTENDED_ANALOG
134134
* message.
135135
* @param pin The analog pin for which to request the value (limited to pins 0 - 15).
136-
* @param stream_enable A zero value will disable the stream, a non-zero will enable the stream
137-
* @note The maximum resulting value is 14-bits (16384).
138136
*/
139137
void FirmataMarshaller::reportAnalogEnable(uint8_t pin)
140138
const
141139
{
142-
reportAnalog(pin, true);
140+
reportAnalog(pin, true);
143141
}
144142

145143
/**
@@ -148,12 +146,11 @@ const
148146
* @param portNumber The port number for which to request the value. Note that this is not the same as a "port" on the
149147
* physical microcontroller. Ports are defined in order per every 8 pins in ascending order
150148
* of the Arduino digital pin numbering scheme. Port 0 = pins D0 - D7, port 1 = pins D8 - D15, etc.
151-
* @param stream_enable A zero value will disable the stream, a non-zero will enable the stream
152149
*/
153150
void FirmataMarshaller::reportDigitalPortDisable(uint8_t portNumber)
154151
const
155152
{
156-
reportDigitalPort(portNumber, false);
153+
reportDigitalPort(portNumber, false);
157154
}
158155

159156
/**
@@ -162,12 +159,11 @@ const
162159
* @param portNumber The port number for which to request the value. Note that this is not the same as a "port" on the
163160
* physical microcontroller. Ports are defined in order per every 8 pins in ascending order
164161
* of the Arduino digital pin numbering scheme. Port 0 = pins D0 - D7, port 1 = pins D8 - D15, etc.
165-
* @param stream_enable A zero value will disable the stream, a non-zero will enable the stream
166162
*/
167163
void FirmataMarshaller::reportDigitalPortEnable(uint8_t portNumber)
168164
const
169165
{
170-
reportDigitalPort(portNumber, true);
166+
reportDigitalPort(portNumber, true);
171167
}
172168

173169
/**
@@ -188,10 +184,21 @@ const
188184
sendValueAsTwo7bitBytes(value);
189185
}
190186

187+
/**
188+
* Send an analog mapping query to the Firmata host application. The resulting sysex message will
189+
* have an ANALOG_MAPPING_RESPONSE command byte, followed by a list of pins [0-n]; where each
190+
* pin will specify its corresponding analog pin number or 0x7F (127) if not applicable.
191+
*/
192+
void FirmataMarshaller::sendAnalogMappingQuery(void)
193+
const
194+
{
195+
sendSysex(ANALOG_MAPPING_QUERY, 0, NULL);
196+
}
197+
191198
/**
192199
* Send a capability query to the Firmata host application. The resulting sysex message will have
193200
* a CAPABILITY_RESPONSE command byte, followed by a list of byte tuples (mode and mode resolution)
194-
* for each pin; where each pin list is terminated by 0x7F (128).
201+
* for each pin; where each pin list is terminated by 0x7F (127).
195202
*/
196203
void FirmataMarshaller::sendCapabilityQuery(void)
197204
const

FirmataMarshaller.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ class FirmataMarshaller
4141
void reportDigitalPortDisable(uint8_t portNumber) const;
4242
void reportDigitalPortEnable(uint8_t portNumber) const;
4343
void sendAnalog(uint8_t pin, uint16_t value) const;
44+
void sendAnalogMappingQuery(void) const;
4445
void sendCapabilityQuery(void) const;
4546
void sendDigital(uint8_t pin, uint8_t value) const;
4647
void sendDigitalPort(uint8_t portNumber, uint16_t portData) const;

FirmataParser.cpp

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -98,35 +98,35 @@ void FirmataParser::parse(uint8_t inputData)
9898
switch (executeMultiByteCommand) {
9999
case ANALOG_MESSAGE:
100100
if (currentAnalogCallback) {
101-
(*currentAnalogCallback)(this,
101+
(*currentAnalogCallback)(currentAnalogCallbackContext,
102102
multiByteChannel,
103103
(dataBuffer[0] << 7)
104104
+ dataBuffer[1]);
105105
}
106106
break;
107107
case DIGITAL_MESSAGE:
108108
if (currentDigitalCallback) {
109-
(*currentDigitalCallback)(this,
109+
(*currentDigitalCallback)(currentDigitalCallbackContext,
110110
multiByteChannel,
111111
(dataBuffer[0] << 7)
112112
+ dataBuffer[1]);
113113
}
114114
break;
115115
case SET_PIN_MODE:
116116
if (currentPinModeCallback)
117-
(*currentPinModeCallback)(this, dataBuffer[1], dataBuffer[0]);
117+
(*currentPinModeCallback)(currentPinModeCallbackContext, dataBuffer[1], dataBuffer[0]);
118118
break;
119119
case SET_DIGITAL_PIN_VALUE:
120120
if (currentPinValueCallback)
121-
(*currentPinValueCallback)(this, dataBuffer[1], dataBuffer[0]);
121+
(*currentPinValueCallback)(currentPinValueCallbackContext, dataBuffer[1], dataBuffer[0]);
122122
break;
123123
case REPORT_ANALOG:
124124
if (currentReportAnalogCallback)
125-
(*currentReportAnalogCallback)(this, multiByteChannel, dataBuffer[0]);
125+
(*currentReportAnalogCallback)(currentReportAnalogCallbackContext, multiByteChannel, dataBuffer[0]);
126126
break;
127127
case REPORT_DIGITAL:
128128
if (currentReportDigitalCallback)
129-
(*currentReportDigitalCallback)(this, multiByteChannel, dataBuffer[0]);
129+
(*currentReportDigitalCallback)(currentReportDigitalCallbackContext, multiByteChannel, dataBuffer[0]);
130130
break;
131131
}
132132
executeMultiByteCommand = 0;
@@ -162,7 +162,7 @@ void FirmataParser::parse(uint8_t inputData)
162162
break;
163163
case REPORT_VERSION:
164164
if (currentReportVersionCallback)
165-
(*currentReportVersionCallback)(this);
165+
(*currentReportVersionCallback)(currentReportVersionCallbackContext);
166166
break;
167167
}
168168
}
@@ -207,7 +207,9 @@ int FirmataParser::setDataBufferOfSize(uint8_t * dataBuffer, size_t dataBufferSi
207207
* DIGITAL_MESSAGE, REPORT_ANALOG, REPORT DIGITAL, SET_PIN_MODE and SET_DIGITAL_PIN_VALUE).
208208
* @param command The ID of the command to attach a callback function to.
209209
* @param newFunction A reference to the callback function to attach.
210-
* @param context The context for the callback function.
210+
* @param context An optional context to be provided to the callback function (NULL by default).
211+
* @note The context parameter is provided so you can pass a parameter, by reference, to
212+
* your callback function.
211213
*/
212214
void FirmataParser::attach(uint8_t command, callbackFunction newFunction, void * context)
213215
{
@@ -244,7 +246,9 @@ void FirmataParser::attach(uint8_t command, callbackFunction newFunction, void *
244246
* and SYSTEM_RESET).
245247
* @param command The ID of the command to attach a callback function to.
246248
* @param newFunction A reference to the callback function to attach.
247-
* @param context The context for the callback function.
249+
* @param context An optional context to be provided to the callback function (NULL by default).
250+
* @note The context parameter is provided so you can pass a parameter, by reference, to
251+
* your callback function.
248252
*/
249253
void FirmataParser::attach(uint8_t command, systemCallbackFunction newFunction, void * context)
250254
{
@@ -268,7 +272,9 @@ void FirmataParser::attach(uint8_t command, systemCallbackFunction newFunction,
268272
* Attach a callback function for the STRING_DATA command.
269273
* @param command Must be set to STRING_DATA or it will be ignored.
270274
* @param newFunction A reference to the string callback function to attach.
271-
* @param context The context for the callback function.
275+
* @param context An optional context to be provided to the callback function (NULL by default).
276+
* @note The context parameter is provided so you can pass a parameter, by reference, to
277+
* your callback function.
272278
*/
273279
void FirmataParser::attach(uint8_t command, stringCallbackFunction newFunction, void * context)
274280
{
@@ -284,7 +290,9 @@ void FirmataParser::attach(uint8_t command, stringCallbackFunction newFunction,
284290
* Attach a generic sysex callback function to sysex command.
285291
* @param command The ID of the command to attach a callback function to.
286292
* @param newFunction A reference to the sysex callback function to attach.
287-
* @param context The context for the callback function.
293+
* @param context An optional context to be provided to the callback function (NULL by default).
294+
* @note The context parameter is provided so you can pass a parameter, by reference, to
295+
* your callback function.
288296
*/
289297
void FirmataParser::attach(uint8_t command, sysexCallbackFunction newFunction, void * context)
290298
{
@@ -296,7 +304,9 @@ void FirmataParser::attach(uint8_t command, sysexCallbackFunction newFunction, v
296304
/**
297305
* Attach a buffer overflow callback
298306
* @param newFunction A reference to the buffer overflow callback function to attach.
299-
* @param context The context supplied by the end-user, and provided during the execution of the callback
307+
* @param context An optional context to be provided to the callback function (NULL by default).
308+
* @note The context parameter is provided so you can pass a parameter, by reference, to
309+
* your callback function.
300310
*/
301311
void FirmataParser::attach(dataBufferOverflowCallbackFunction newFunction, void * context)
302312
{
@@ -383,7 +393,7 @@ void FirmataParser::processSysexMessage(void)
383393
switch (dataBuffer[0]) { //first byte in buffer is command
384394
case REPORT_FIRMWARE:
385395
if (currentReportFirmwareCallback)
386-
(*currentReportFirmwareCallback)(this);
396+
(*currentReportFirmwareCallback)(currentReportFirmwareCallbackContext);
387397
break;
388398
case STRING_DATA:
389399
if (currentStringCallback) {
@@ -405,12 +415,12 @@ void FirmataParser::processSysexMessage(void)
405415
if (dataBuffer[j - 1] != '\0') {
406416
bufferDataAtPosition('\0', j);
407417
}
408-
(*currentStringCallback)(this, (char *)&dataBuffer[0]);
418+
(*currentStringCallback)(currentStringCallbackContext, (char *)&dataBuffer[0]);
409419
}
410420
break;
411421
default:
412422
if (currentSysexCallback)
413-
(*currentSysexCallback)(this, dataBuffer[0], sysexBytesRead - 1, dataBuffer + 1);
423+
(*currentSysexCallback)(currentSysexCallbackContext, dataBuffer[0], sysexBytesRead - 1, dataBuffer + 1);
414424
}
415425
}
416426

@@ -434,5 +444,5 @@ void FirmataParser::systemReset(void)
434444
sysexBytesRead = 0;
435445

436446
if (currentSystemResetCallback)
437-
(*currentSystemResetCallback)(this);
447+
(*currentSystemResetCallback)(currentSystemResetCallbackContext);
438448
}

FirmataParser.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ class FirmataParser
4040
int setDataBufferOfSize(uint8_t * dataBuffer, size_t dataBufferSize);
4141

4242
/* attach & detach callback functions to messages */
43-
void attach(uint8_t command, callbackFunction newFunction, void * context);
44-
void attach(dataBufferOverflowCallbackFunction newFunction, void * context);
45-
void attach(uint8_t command, stringCallbackFunction newFunction, void * context);
46-
void attach(uint8_t command, sysexCallbackFunction newFunction, void * context);
47-
void attach(uint8_t command, systemCallbackFunction newFunction, void * context);
43+
void attach(uint8_t command, callbackFunction newFunction, void * context = NULL);
44+
void attach(dataBufferOverflowCallbackFunction newFunction, void * context = NULL);
45+
void attach(uint8_t command, stringCallbackFunction newFunction, void * context = NULL);
46+
void attach(uint8_t command, sysexCallbackFunction newFunction, void * context = NULL);
47+
void attach(uint8_t command, systemCallbackFunction newFunction, void * context = NULL);
4848
void detach(uint8_t command);
4949
void detach(dataBufferOverflowCallbackFunction);
5050

0 commit comments

Comments
 (0)