Skip to content

Commit 74cb070

Browse files
Merge pull request firmata#187 from firmata/analog-reporting-issue
prevent analog reporting from system reset function
2 parents 45fc6fc + 7e8d21b commit 74cb070

File tree

4 files changed

+20
-6
lines changed

4 files changed

+20
-6
lines changed

Firmata.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,11 @@ boolean FirmataClass::isParsingMessage(void)
294294
{
295295
return (waitForData > 0 || parsingSysex);
296296
}
297+
298+
boolean FirmataClass::isResetting(void)
299+
{
300+
return resetting;
301+
}
297302
//------------------------------------------------------------------------------
298303
// Serial Send Handling
299304

@@ -479,6 +484,7 @@ void FirmataClass::setPinState(byte pin, int state)
479484
// resets the system state upon a SYSTEM_RESET message from the host software
480485
void FirmataClass::systemReset(void)
481486
{
487+
resetting = true;
482488
byte i;
483489

484490
waitForData = 0; // this flag says the next serial input will be data
@@ -494,6 +500,8 @@ void FirmataClass::systemReset(void)
494500

495501
if (currentSystemResetCallback)
496502
(*currentSystemResetCallback)();
503+
504+
resetting = false;
497505
}
498506

499507

Firmata.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ class FirmataClass
113113
void processInput(void);
114114
void parse(unsigned char value);
115115
boolean isParsingMessage(void);
116+
boolean isResetting(void);
116117
/* serial send handling */
117118
void sendAnalog(byte pin, int value);
118119
void sendDigital(byte pin, int value); // TODO implement this
@@ -155,6 +156,8 @@ class FirmataClass
155156
byte pinConfig[TOTAL_PINS]; // configuration of every pin
156157
int pinState[TOTAL_PINS]; // any value that has been written
157158

159+
boolean resetting;
160+
158161
/* callback functions */
159162
callbackFunction currentAnalogCallback;
160163
callbackFunction currentDigitalCallback;

examples/StandardFirmata/StandardFirmata.ino

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,6 @@ struct i2c_device_info {
7777
/* for i2c read continuous more */
7878
i2c_device_info query[MAX_QUERIES];
7979

80-
boolean isResetting = false;
81-
8280
byte i2cRxData[32];
8381
boolean isI2CEnabled = false;
8482
signed char queryIndex = -1;
@@ -353,7 +351,7 @@ void reportAnalogCallback(byte analogPin, int value)
353351
analogInputsToReport = analogInputsToReport | (1 << analogPin);
354352
// prevent during system reset or all analog pin values will be reported
355353
// which may report noise for unconnected analog pins
356-
if (!isResetting) {
354+
if (!Firmata.isResetting()) {
357355
// Send pin value immediately. This is helpful when connected via
358356
// ethernet, wi-fi or bluetooth so pin states can be known upon
359357
// reconnecting.
@@ -616,7 +614,6 @@ void disableI2CPins() {
616614

617615
void systemResetCallback()
618616
{
619-
isResetting = true;
620617
// initialize a defalt state
621618
// TODO: option to load config from EEPROM instead of default
622619
if (isI2CEnabled) {
@@ -657,7 +654,6 @@ void systemResetCallback()
657654
outputPort(i, readPort(i, portConfigInputs[i]), true);
658655
}
659656
*/
660-
isResetting = false;
661657
}
662658

663659
void setup()

utility/AnalogInputFirmata.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,14 @@ void AnalogInputFirmata::reportAnalog(byte analogPin, int value)
4444
analogInputsToReport = analogInputsToReport &~ (1 << analogPin);
4545
} else {
4646
analogInputsToReport = analogInputsToReport | (1 << analogPin);
47-
Firmata.sendAnalog(analogPin, analogRead(analogPin));
47+
// prevent during system reset or all analog pin values will be reported
48+
// which may report noise for unconnected analog pins
49+
if (!Firmata.isResetting()) {
50+
// Send pin value immediately. This is helpful when connected via
51+
// ethernet, wi-fi or bluetooth so pin states can be known upon
52+
// reconnecting.
53+
Firmata.sendAnalog(analogPin, analogRead(analogPin));
54+
}
4855
}
4956
}
5057
// TODO: save status to EEPROM here, if changed

0 commit comments

Comments
 (0)