Skip to content

prevent analog reporting during system reset #186

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 7, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions examples/StandardFirmata/StandardFirmata.ino
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ struct i2c_device_info {
/* for i2c read continuous more */
i2c_device_info query[MAX_QUERIES];

boolean isResetting = false;

byte i2cRxData[32];
boolean isI2CEnabled = false;
signed char queryIndex = -1;
Expand Down Expand Up @@ -349,10 +351,14 @@ void reportAnalogCallback(byte analogPin, int value)
analogInputsToReport = analogInputsToReport & ~ (1 << analogPin);
} else {
analogInputsToReport = analogInputsToReport | (1 << analogPin);
// Send pin value immediately. This is helpful when connected via
// ethernet, wi-fi or bluetooth so pin states can be known upon
// reconnecting.
Firmata.sendAnalog(analogPin, analogRead(analogPin));
// prevent during system reset or all analog pin values will be reported
// which may report noise for unconnected analog pins
if (!isResetting) {
// Send pin value immediately. This is helpful when connected via
// ethernet, wi-fi or bluetooth so pin states can be known upon
// reconnecting.
Firmata.sendAnalog(analogPin, analogRead(analogPin));
}
}
}
// TODO: save status to EEPROM here, if changed
Expand Down Expand Up @@ -610,6 +616,7 @@ void disableI2CPins() {

void systemResetCallback()
{
isResetting = true;
// initialize a defalt state
// TODO: option to load config from EEPROM instead of default
if (isI2CEnabled) {
Expand Down Expand Up @@ -650,6 +657,7 @@ void systemResetCallback()
outputPort(i, readPort(i, portConfigInputs[i]), true);
}
*/
isResetting = false;
}

void setup()
Expand Down
19 changes: 13 additions & 6 deletions examples/StandardFirmataYun/StandardFirmataYun.ino
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ struct i2c_device_info {
/* for i2c read continuous more */
i2c_device_info query[MAX_QUERIES];

boolean isResetting = false;

byte i2cRxData[32];
boolean isI2CEnabled = false;
signed char queryIndex = -1;
Expand Down Expand Up @@ -355,13 +357,16 @@ void reportAnalogCallback(byte analogPin, int value)
if (analogPin < TOTAL_ANALOG_PINS) {
if (value == 0) {
analogInputsToReport = analogInputsToReport & ~ (1 << analogPin);
}
else {
} else {
analogInputsToReport = analogInputsToReport | (1 << analogPin);
// Send pin value immediately. This is helpful when connected via
// ethernet, wi-fi or bluetooth so pin states can be known upon
// reconnecting.
Firmata.sendAnalog(analogPin, analogRead(analogPin));
// prevent during system reset or all analog pin values will be reported
// which may report noise for unconnected analog pins
if (!isResetting) {
// Send pin value immediately. This is helpful when connected via
// ethernet, wi-fi or bluetooth so pin states can be known upon
// reconnecting.
Firmata.sendAnalog(analogPin, analogRead(analogPin));
}
}
}
// TODO: save status to EEPROM here, if changed
Expand Down Expand Up @@ -621,6 +626,7 @@ void disableI2CPins() {

void systemResetCallback()
{
isResetting = true;
// initialize a defalt state
// TODO: option to load config from EEPROM instead of default
if (isI2CEnabled) {
Expand Down Expand Up @@ -662,6 +668,7 @@ void systemResetCallback()
outputPort(i, readPort(i, portConfigInputs[i]), true);
}
*/
isResetting = false;
}

void setup()
Expand Down
3 changes: 3 additions & 0 deletions extras/revisions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ FIRMATA 2.4.1 - Feb 7, 2015
[core library]
* Fixed off-by-one bug in setFirmwareNameAndVersion (Brian Schmalz)

[StandardFirmata]
* Prevent analog values from being reported during system reset

FIRMATA 2.4.0 - Dec 21, 2014

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