@@ -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 */
212214void 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 */
249253void 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 */
273279void 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 */
289297void 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 */
301311void 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}
0 commit comments