Skip to content

Commit 57bbd49

Browse files
added init method to simplify systemReset function and enable FirmataSerial->flush() to be called
1 parent f1f9a7c commit 57bbd49

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

Firmata.cpp

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ void FirmataClass::endSysex(void)
4949
FirmataClass::FirmataClass()
5050
{
5151
firmwareVersionCount = 0;
52-
systemReset();
52+
init();
5353
}
5454

5555
//******************************************************************************
@@ -400,33 +400,35 @@ void FirmataClass::detach(byte command)
400400
//* Private Methods
401401
//******************************************************************************
402402

403-
404-
405-
// resets the system state upon a SYSTEM_RESET message from the host software
406-
void FirmataClass::systemReset(void)
403+
// initialize to a known state
404+
void FirmataClass::init(void)
407405
{
408406
byte i;
409407

410408
waitForData = 0; // this flag says the next serial input will be data
411409
executeMultiByteCommand = 0; // execute this after getting multi-byte data
412410
multiByteChannel = 0; // channel data for multiByteCommands
413411

414-
415412
for(i=0; i<MAX_DATA_BYTES; i++) {
416413
storedInputData[i] = 0;
417414
}
418415

419416
parsingSysex = false;
420-
sysexBytesRead = 0;
417+
sysexBytesRead = 0;
418+
}
419+
420+
// resets the system state upon a SYSTEM_RESET message from the host software
421+
void FirmataClass::systemReset(void)
422+
{
423+
init();
421424

422425
if(currentSystemResetCallback)
423426
(*currentSystemResetCallback)();
424427

425-
//flush(); //TODO uncomment when Firmata is a subclass of HardwareSerial
428+
FirmataSerial->flush();
426429
}
427430

428431

429-
430432
// =============================================================================
431433
// used for flashing the pin for the version number
432434
void FirmataClass::pin13strobe(int count, int onInterval, int offInterval)

Firmata.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ class FirmataClass
140140
sysexCallbackFunction currentSysexCallback;
141141

142142
/* private methods ------------------------------ */
143+
void init(void);
143144
void processSysexMessage(void);
144145
void systemReset(void);
145146
void pin13strobe(int count, int onInterval, int offInterval);

0 commit comments

Comments
 (0)