@@ -61,7 +61,7 @@ FirmataParser::FirmataParser(uint8_t * const dataBuffer, size_t dataBufferSize)
6161 currentStringCallback((stringCallbackFunction)NULL),
6262 currentSysexCallback((sysexCallbackFunction)NULL),
6363 currentReportFirmwareCallback((versionCallbackFunction)NULL),
64- currentReportVersionCallback((systemCallbackFunction )NULL),
64+ currentReportVersionCallback((versionCallbackFunction )NULL),
6565 currentSystemResetCallback((systemCallbackFunction)NULL)
6666{
6767 allowBufferUpdate = ((uint8_t *)NULL == dataBuffer);
@@ -130,6 +130,9 @@ void FirmataParser::parse(uint8_t inputData)
130130 if (currentReportDigitalCallback)
131131 (*currentReportDigitalCallback)(currentReportDigitalCallbackContext, multiByteChannel, dataBuffer[0 ]);
132132 break ;
133+ case REPORT_VERSION:
134+ if (currentReportVersionCallback)
135+ (*currentReportVersionCallback)(currentReportVersionCallbackContext, dataBuffer[0 ], dataBuffer[1 ], (const char *)NULL );
133136 }
134137 executeMultiByteCommand = 0 ;
135138 }
@@ -163,8 +166,8 @@ void FirmataParser::parse(uint8_t inputData)
163166 systemReset ();
164167 break ;
165168 case REPORT_VERSION:
166- if (currentReportVersionCallback)
167- (*currentReportVersionCallback)(currentReportVersionCallbackContext) ;
169+ waitForData = 2 ; // two data bytes needed
170+ executeMultiByteCommand = command ;
168171 break ;
169172 }
170173 }
@@ -244,12 +247,13 @@ void FirmataParser::attach(uint8_t command, callbackFunction newFunction, void *
244247}
245248
246249/* *
247- * Attach a version callback function (supported option : REPORT_FIRMWARE).
250+ * Attach a version callback function (supported options are : REPORT_FIRMWARE, REPORT_VERSION ).
248251 * @param command The ID of the command to attach a callback function to.
249252 * @param newFunction A reference to the callback function to attach.
250253 * @param context An optional context to be provided to the callback function (NULL by default).
251254 * @note The context parameter is provided so you can pass a parameter, by reference, to
252255 * your callback function.
256+ * @note The description value in the REPORT_VERSION callback will always be NULL
253257 */
254258void FirmataParser::attach (uint8_t command, versionCallbackFunction newFunction, void * context)
255259{
@@ -258,11 +262,15 @@ void FirmataParser::attach(uint8_t command, versionCallbackFunction newFunction,
258262 currentReportFirmwareCallback = newFunction;
259263 currentReportFirmwareCallbackContext = context;
260264 break ;
265+ case REPORT_VERSION:
266+ currentReportVersionCallback = newFunction;
267+ currentReportVersionCallbackContext = context;
268+ break ;
261269 }
262270}
263271
264272/* *
265- * Attach a system callback function (supported options are : SYSTEM_RESET, REPORT_VERSION ).
273+ * Attach a system callback function (supported option : SYSTEM_RESET).
266274 * @param command The ID of the command to attach a callback function to.
267275 * @param newFunction A reference to the callback function to attach.
268276 * @param context An optional context to be provided to the callback function (NULL by default).
@@ -272,10 +280,6 @@ void FirmataParser::attach(uint8_t command, versionCallbackFunction newFunction,
272280void FirmataParser::attach (uint8_t command, systemCallbackFunction newFunction, void * context)
273281{
274282 switch (command) {
275- case REPORT_VERSION:
276- currentReportVersionCallback = newFunction;
277- currentReportVersionCallbackContext = context;
278- break ;
279283 case SYSTEM_RESET:
280284 currentSystemResetCallback = newFunction;
281285 currentSystemResetCallbackContext = context;
@@ -341,6 +345,8 @@ void FirmataParser::detach(uint8_t command)
341345 attach (command, (versionCallbackFunction)NULL , NULL );
342346 break ;
343347 case REPORT_VERSION:
348+ attach (command, (versionCallbackFunction)NULL , NULL );
349+ break ;
344350 case SYSTEM_RESET:
345351 attach (command, (systemCallbackFunction)NULL , NULL );
346352 break ;
0 commit comments