diff --git a/Firmata.cpp b/Firmata.cpp index 6134ebfa..755048a9 100644 --- a/Firmata.cpp +++ b/Firmata.cpp @@ -95,7 +95,7 @@ FirmataClass::FirmataClass() parser.attach(STRING_DATA, (FirmataParser::stringCallbackFunction)staticStringCallback, (void *)NULL); parser.attach(START_SYSEX, (FirmataParser::sysexCallbackFunction)staticSysexCallback, (void *)NULL); parser.attach(REPORT_FIRMWARE, (FirmataParser::versionCallbackFunction)staticReportFirmwareCallback, this); - parser.attach(REPORT_VERSION, (FirmataParser::systemCallbackFunction)staticReportVersionCallback, this); + parser.attach(REPORT_VERSION, (FirmataParser::versionCallbackFunction)staticReportVersionCallback, this); parser.attach(SYSTEM_RESET, (FirmataParser::systemCallbackFunction)staticSystemResetCallback, (void *)NULL); } diff --git a/Firmata.h b/Firmata.h index cda11a6e..1ba67926 100644 --- a/Firmata.h +++ b/Firmata.h @@ -151,7 +151,7 @@ class FirmataClass inline static void staticStringCallback (void *, const char * c_str) { if ( currentStringCallback ) { currentStringCallback((char *)c_str); } } inline static void staticSysexCallback (void *, uint8_t command, size_t argc, uint8_t *argv) { if ( currentSysexCallback ) { currentSysexCallback(command, (uint8_t)argc, argv); } } inline static void staticReportFirmwareCallback (void * context, size_t, size_t, const char *) { if ( context ) { ((FirmataClass *)context)->printFirmwareVersion(); } } - inline static void staticReportVersionCallback (void * context) { if ( context ) { ((FirmataClass *)context)->printVersion(); } } + inline static void staticReportVersionCallback (void * context, size_t, size_t, const char *) { if ( context ) { ((FirmataClass *)context)->printVersion(); } } inline static void staticSystemResetCallback (void *) { if ( currentSystemResetCallback ) { currentSystemResetCallback(); } } }; diff --git a/FirmataMarshaller.cpp b/FirmataMarshaller.cpp index 2b1f45a9..3e5a84d7 100644 --- a/FirmataMarshaller.cpp +++ b/FirmataMarshaller.cpp @@ -179,6 +179,8 @@ const { if ( (Stream *)NULL == FirmataStream ) { return; } FirmataStream->write(REPORT_VERSION); + FirmataStream->write(PROTOCOL_MAJOR_VERSION); + FirmataStream->write(PROTOCOL_MINOR_VERSION); } /** diff --git a/FirmataParser.cpp b/FirmataParser.cpp index 415e6e07..1198ab04 100644 --- a/FirmataParser.cpp +++ b/FirmataParser.cpp @@ -61,7 +61,7 @@ FirmataParser::FirmataParser(uint8_t * const dataBuffer, size_t dataBufferSize) currentStringCallback((stringCallbackFunction)NULL), currentSysexCallback((sysexCallbackFunction)NULL), currentReportFirmwareCallback((versionCallbackFunction)NULL), - currentReportVersionCallback((systemCallbackFunction)NULL), + currentReportVersionCallback((versionCallbackFunction)NULL), currentSystemResetCallback((systemCallbackFunction)NULL) { allowBufferUpdate = ((uint8_t *)NULL == dataBuffer); @@ -130,6 +130,9 @@ void FirmataParser::parse(uint8_t inputData) if (currentReportDigitalCallback) (*currentReportDigitalCallback)(currentReportDigitalCallbackContext, multiByteChannel, dataBuffer[0]); break; + case REPORT_VERSION: + if (currentReportVersionCallback) + (*currentReportVersionCallback)(currentReportVersionCallbackContext, dataBuffer[0], dataBuffer[1], (const char *)NULL); } executeMultiByteCommand = 0; } @@ -163,8 +166,8 @@ void FirmataParser::parse(uint8_t inputData) systemReset(); break; case REPORT_VERSION: - if (currentReportVersionCallback) - (*currentReportVersionCallback)(currentReportVersionCallbackContext); + waitForData = 2; // two data bytes needed + executeMultiByteCommand = command; break; } } @@ -244,12 +247,13 @@ void FirmataParser::attach(uint8_t command, callbackFunction newFunction, void * } /** - * Attach a version callback function (supported option: REPORT_FIRMWARE). + * Attach a version callback function (supported options are: REPORT_FIRMWARE, REPORT_VERSION). * @param command The ID of the command to attach a callback function to. * @param newFunction A reference to the callback function to attach. * @param context An optional context to be provided to the callback function (NULL by default). * @note The context parameter is provided so you can pass a parameter, by reference, to * your callback function. + * @note The description value in the REPORT_VERSION callback will always be NULL */ void FirmataParser::attach(uint8_t command, versionCallbackFunction newFunction, void * context) { @@ -258,11 +262,15 @@ void FirmataParser::attach(uint8_t command, versionCallbackFunction newFunction, currentReportFirmwareCallback = newFunction; currentReportFirmwareCallbackContext = context; break; + case REPORT_VERSION: + currentReportVersionCallback = newFunction; + currentReportVersionCallbackContext = context; + break; } } /** - * Attach a system callback function (supported options are: SYSTEM_RESET, REPORT_VERSION). + * Attach a system callback function (supported option: SYSTEM_RESET). * @param command The ID of the command to attach a callback function to. * @param newFunction A reference to the callback function to attach. * @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, void FirmataParser::attach(uint8_t command, systemCallbackFunction newFunction, void * context) { switch (command) { - case REPORT_VERSION: - currentReportVersionCallback = newFunction; - currentReportVersionCallbackContext = context; - break; case SYSTEM_RESET: currentSystemResetCallback = newFunction; currentSystemResetCallbackContext = context; @@ -341,6 +345,8 @@ void FirmataParser::detach(uint8_t command) attach(command, (versionCallbackFunction)NULL, NULL); break; case REPORT_VERSION: + attach(command, (versionCallbackFunction)NULL, NULL); + break; case SYSTEM_RESET: attach(command, (systemCallbackFunction)NULL, NULL); break; diff --git a/FirmataParser.h b/FirmataParser.h index 1790b521..a7f210c7 100644 --- a/FirmataParser.h +++ b/FirmataParser.h @@ -90,7 +90,7 @@ class FirmataParser stringCallbackFunction currentStringCallback; sysexCallbackFunction currentSysexCallback; versionCallbackFunction currentReportFirmwareCallback; - systemCallbackFunction currentReportVersionCallback; + versionCallbackFunction currentReportVersionCallback; systemCallbackFunction currentSystemResetCallback; /* private methods ------------------------------ */