Skip to content

Commit dea0bfa

Browse files
Merge pull request firmata#186 from firmata/analog-reporting-fix
prevent analog reporting during system reset
2 parents f5969b9 + 1d58e89 commit dea0bfa

File tree

3 files changed

+28
-10
lines changed

3 files changed

+28
-10
lines changed

examples/StandardFirmata/StandardFirmata.ino

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

80+
boolean isResetting = false;
81+
8082
byte i2cRxData[32];
8183
boolean isI2CEnabled = false;
8284
signed char queryIndex = -1;
@@ -349,10 +351,14 @@ void reportAnalogCallback(byte analogPin, int value)
349351
analogInputsToReport = analogInputsToReport & ~ (1 << analogPin);
350352
} else {
351353
analogInputsToReport = analogInputsToReport | (1 << analogPin);
352-
// Send pin value immediately. This is helpful when connected via
353-
// ethernet, wi-fi or bluetooth so pin states can be known upon
354-
// reconnecting.
355-
Firmata.sendAnalog(analogPin, analogRead(analogPin));
354+
// prevent during system reset or all analog pin values will be reported
355+
// which may report noise for unconnected analog pins
356+
if (!isResetting) {
357+
// Send pin value immediately. This is helpful when connected via
358+
// ethernet, wi-fi or bluetooth so pin states can be known upon
359+
// reconnecting.
360+
Firmata.sendAnalog(analogPin, analogRead(analogPin));
361+
}
356362
}
357363
}
358364
// TODO: save status to EEPROM here, if changed
@@ -610,6 +616,7 @@ void disableI2CPins() {
610616

611617
void systemResetCallback()
612618
{
619+
isResetting = true;
613620
// initialize a defalt state
614621
// TODO: option to load config from EEPROM instead of default
615622
if (isI2CEnabled) {
@@ -650,6 +657,7 @@ void systemResetCallback()
650657
outputPort(i, readPort(i, portConfigInputs[i]), true);
651658
}
652659
*/
660+
isResetting = false;
653661
}
654662

655663
void setup()

examples/StandardFirmataYun/StandardFirmataYun.ino

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ struct i2c_device_info {
7878
/* for i2c read continuous more */
7979
i2c_device_info query[MAX_QUERIES];
8080

81+
boolean isResetting = false;
82+
8183
byte i2cRxData[32];
8284
boolean isI2CEnabled = false;
8385
signed char queryIndex = -1;
@@ -355,13 +357,16 @@ void reportAnalogCallback(byte analogPin, int value)
355357
if (analogPin < TOTAL_ANALOG_PINS) {
356358
if (value == 0) {
357359
analogInputsToReport = analogInputsToReport & ~ (1 << analogPin);
358-
}
359-
else {
360+
} else {
360361
analogInputsToReport = analogInputsToReport | (1 << analogPin);
361-
// Send pin value immediately. This is helpful when connected via
362-
// ethernet, wi-fi or bluetooth so pin states can be known upon
363-
// reconnecting.
364-
Firmata.sendAnalog(analogPin, analogRead(analogPin));
362+
// prevent during system reset or all analog pin values will be reported
363+
// which may report noise for unconnected analog pins
364+
if (!isResetting) {
365+
// Send pin value immediately. This is helpful when connected via
366+
// ethernet, wi-fi or bluetooth so pin states can be known upon
367+
// reconnecting.
368+
Firmata.sendAnalog(analogPin, analogRead(analogPin));
369+
}
365370
}
366371
}
367372
// TODO: save status to EEPROM here, if changed
@@ -621,6 +626,7 @@ void disableI2CPins() {
621626

622627
void systemResetCallback()
623628
{
629+
isResetting = true;
624630
// initialize a defalt state
625631
// TODO: option to load config from EEPROM instead of default
626632
if (isI2CEnabled) {
@@ -662,6 +668,7 @@ void systemResetCallback()
662668
outputPort(i, readPort(i, portConfigInputs[i]), true);
663669
}
664670
*/
671+
isResetting = false;
665672
}
666673

667674
void setup()

extras/revisions.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ FIRMATA 2.4.1 - Feb 7, 2015
33
[core library]
44
* Fixed off-by-one bug in setFirmwareNameAndVersion (Brian Schmalz)
55

6+
[StandardFirmata]
7+
* Prevent analog values from being reported during system reset
8+
69
FIRMATA 2.4.0 - Dec 21, 2014
710

811
Changes from 2.3.6 to 2.4 that may impact existing Firmata client implementations:

0 commit comments

Comments
 (0)