@@ -98,35 +98,35 @@ void FirmataParser::parse(uint8_t inputData)
98
98
switch (executeMultiByteCommand) {
99
99
case ANALOG_MESSAGE:
100
100
if (currentAnalogCallback) {
101
- (*currentAnalogCallback)(this ,
101
+ (*currentAnalogCallback)(currentAnalogCallbackContext ,
102
102
multiByteChannel,
103
103
(dataBuffer[0 ] << 7 )
104
104
+ dataBuffer[1 ]);
105
105
}
106
106
break ;
107
107
case DIGITAL_MESSAGE:
108
108
if (currentDigitalCallback) {
109
- (*currentDigitalCallback)(this ,
109
+ (*currentDigitalCallback)(currentDigitalCallbackContext ,
110
110
multiByteChannel,
111
111
(dataBuffer[0 ] << 7 )
112
112
+ dataBuffer[1 ]);
113
113
}
114
114
break ;
115
115
case SET_PIN_MODE:
116
116
if (currentPinModeCallback)
117
- (*currentPinModeCallback)(this , dataBuffer[1 ], dataBuffer[0 ]);
117
+ (*currentPinModeCallback)(currentPinModeCallbackContext , dataBuffer[1 ], dataBuffer[0 ]);
118
118
break ;
119
119
case SET_DIGITAL_PIN_VALUE:
120
120
if (currentPinValueCallback)
121
- (*currentPinValueCallback)(this , dataBuffer[1 ], dataBuffer[0 ]);
121
+ (*currentPinValueCallback)(currentPinValueCallbackContext , dataBuffer[1 ], dataBuffer[0 ]);
122
122
break ;
123
123
case REPORT_ANALOG:
124
124
if (currentReportAnalogCallback)
125
- (*currentReportAnalogCallback)(this , multiByteChannel, dataBuffer[0 ]);
125
+ (*currentReportAnalogCallback)(currentReportAnalogCallbackContext , multiByteChannel, dataBuffer[0 ]);
126
126
break ;
127
127
case REPORT_DIGITAL:
128
128
if (currentReportDigitalCallback)
129
- (*currentReportDigitalCallback)(this , multiByteChannel, dataBuffer[0 ]);
129
+ (*currentReportDigitalCallback)(currentReportDigitalCallbackContext , multiByteChannel, dataBuffer[0 ]);
130
130
break ;
131
131
}
132
132
executeMultiByteCommand = 0 ;
@@ -162,7 +162,7 @@ void FirmataParser::parse(uint8_t inputData)
162
162
break ;
163
163
case REPORT_VERSION:
164
164
if (currentReportVersionCallback)
165
- (*currentReportVersionCallback)(this );
165
+ (*currentReportVersionCallback)(currentReportVersionCallbackContext );
166
166
break ;
167
167
}
168
168
}
@@ -207,7 +207,9 @@ int FirmataParser::setDataBufferOfSize(uint8_t * dataBuffer, size_t dataBufferSi
207
207
* DIGITAL_MESSAGE, REPORT_ANALOG, REPORT DIGITAL, SET_PIN_MODE and SET_DIGITAL_PIN_VALUE).
208
208
* @param command The ID of the command to attach a callback function to.
209
209
* @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.
211
213
*/
212
214
void FirmataParser::attach (uint8_t command, callbackFunction newFunction, void * context)
213
215
{
@@ -244,7 +246,9 @@ void FirmataParser::attach(uint8_t command, callbackFunction newFunction, void *
244
246
* and SYSTEM_RESET).
245
247
* @param command The ID of the command to attach a callback function to.
246
248
* @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.
248
252
*/
249
253
void FirmataParser::attach (uint8_t command, systemCallbackFunction newFunction, void * context)
250
254
{
@@ -268,7 +272,9 @@ void FirmataParser::attach(uint8_t command, systemCallbackFunction newFunction,
268
272
* Attach a callback function for the STRING_DATA command.
269
273
* @param command Must be set to STRING_DATA or it will be ignored.
270
274
* @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.
272
278
*/
273
279
void FirmataParser::attach (uint8_t command, stringCallbackFunction newFunction, void * context)
274
280
{
@@ -284,7 +290,9 @@ void FirmataParser::attach(uint8_t command, stringCallbackFunction newFunction,
284
290
* Attach a generic sysex callback function to sysex command.
285
291
* @param command The ID of the command to attach a callback function to.
286
292
* @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.
288
296
*/
289
297
void FirmataParser::attach (uint8_t command, sysexCallbackFunction newFunction, void * context)
290
298
{
@@ -296,7 +304,9 @@ void FirmataParser::attach(uint8_t command, sysexCallbackFunction newFunction, v
296
304
/* *
297
305
* Attach a buffer overflow callback
298
306
* @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.
300
310
*/
301
311
void FirmataParser::attach (dataBufferOverflowCallbackFunction newFunction, void * context)
302
312
{
@@ -383,7 +393,7 @@ void FirmataParser::processSysexMessage(void)
383
393
switch (dataBuffer[0 ]) { // first byte in buffer is command
384
394
case REPORT_FIRMWARE:
385
395
if (currentReportFirmwareCallback)
386
- (*currentReportFirmwareCallback)(this );
396
+ (*currentReportFirmwareCallback)(currentReportFirmwareCallbackContext );
387
397
break ;
388
398
case STRING_DATA:
389
399
if (currentStringCallback) {
@@ -405,12 +415,12 @@ void FirmataParser::processSysexMessage(void)
405
415
if (dataBuffer[j - 1 ] != ' \0 ' ) {
406
416
bufferDataAtPosition (' \0 ' , j);
407
417
}
408
- (*currentStringCallback)(this , (char *)&dataBuffer[0 ]);
418
+ (*currentStringCallback)(currentStringCallbackContext , (char *)&dataBuffer[0 ]);
409
419
}
410
420
break ;
411
421
default :
412
422
if (currentSysexCallback)
413
- (*currentSysexCallback)(this , dataBuffer[0 ], sysexBytesRead - 1 , dataBuffer + 1 );
423
+ (*currentSysexCallback)(currentSysexCallbackContext , dataBuffer[0 ], sysexBytesRead - 1 , dataBuffer + 1 );
414
424
}
415
425
}
416
426
@@ -434,5 +444,5 @@ void FirmataParser::systemReset(void)
434
444
sysexBytesRead = 0 ;
435
445
436
446
if (currentSystemResetCallback)
437
- (*currentSystemResetCallback)(this );
447
+ (*currentSystemResetCallback)(currentSystemResetCallbackContext );
438
448
}
0 commit comments