Skip to content

Commit fbe73f2

Browse files
committed
version callbacks
1 parent 0d9e533 commit fbe73f2

File tree

5 files changed

+20
-12
lines changed

5 files changed

+20
-12
lines changed

Diff for: Firmata.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ FirmataClass::FirmataClass()
9595
parser.attach(STRING_DATA, (FirmataParser::stringCallbackFunction)staticStringCallback, (void *)NULL);
9696
parser.attach(START_SYSEX, (FirmataParser::sysexCallbackFunction)staticSysexCallback, (void *)NULL);
9797
parser.attach(REPORT_FIRMWARE, (FirmataParser::versionCallbackFunction)staticReportFirmwareCallback, this);
98-
parser.attach(REPORT_VERSION, (FirmataParser::systemCallbackFunction)staticReportVersionCallback, this);
98+
parser.attach(REPORT_VERSION, (FirmataParser::versionCallbackFunction)staticReportVersionCallback, this);
9999
parser.attach(SYSTEM_RESET, (FirmataParser::systemCallbackFunction)staticSystemResetCallback, (void *)NULL);
100100
}
101101

Diff for: Firmata.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ class FirmataClass
151151
inline static void staticStringCallback (void *, const char * c_str) { if ( currentStringCallback ) { currentStringCallback((char *)c_str); } }
152152
inline static void staticSysexCallback (void *, uint8_t command, size_t argc, uint8_t *argv) { if ( currentSysexCallback ) { currentSysexCallback(command, (uint8_t)argc, argv); } }
153153
inline static void staticReportFirmwareCallback (void * context, size_t, size_t, const char *) { if ( context ) { ((FirmataClass *)context)->printFirmwareVersion(); } }
154-
inline static void staticReportVersionCallback (void * context) { if ( context ) { ((FirmataClass *)context)->printVersion(); } }
154+
inline static void staticReportVersionCallback (void * context, size_t, size_t, const char *) { if ( context ) { ((FirmataClass *)context)->printVersion(); } }
155155
inline static void staticSystemResetCallback (void *) { if ( currentSystemResetCallback ) { currentSystemResetCallback(); } }
156156
};
157157

Diff for: FirmataMarshaller.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,8 @@ const
179179
{
180180
if ( (Stream *)NULL == FirmataStream ) { return; }
181181
FirmataStream->write(REPORT_VERSION);
182+
FirmataStream->write(PROTOCOL_MAJOR_VERSION);
183+
FirmataStream->write(PROTOCOL_MINOR_VERSION);
182184
}
183185

184186
/**

Diff for: FirmataParser.cpp

+15-9
Original file line numberDiff line numberDiff line change
@@ -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
*/
254258
void 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,
272280
void 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;

Diff for: FirmataParser.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ class FirmataParser
9090
stringCallbackFunction currentStringCallback;
9191
sysexCallbackFunction currentSysexCallback;
9292
versionCallbackFunction currentReportFirmwareCallback;
93-
systemCallbackFunction currentReportVersionCallback;
93+
versionCallbackFunction currentReportVersionCallback;
9494
systemCallbackFunction currentSystemResetCallback;
9595

9696
/* private methods ------------------------------ */

0 commit comments

Comments
 (0)