Skip to content
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

potential duplicate digital input pin values reported #126

Open
soundanalogous opened this issue Jun 5, 2016 · 1 comment
Open

potential duplicate digital input pin values reported #126

soundanalogous opened this issue Jun 5, 2016 · 1 comment
Assignees

Comments

@soundanalogous
Copy link
Member

soundanalogous commented Jun 5, 2016

This observation is based solely on looking over the code. There is a potential issue in that digital pin reporting is actually managed per 'port' in Firmware, but in firmata.js it's managed at the pin level. If we trace the code execution path, a potential issue emerges:

  1. User calls digitalRead on pin D2. User also calls digitalRead on pin D3 and pin D4.
  2. Each time digitalRead is called (3 times total in this example), reportDigitalPin is called.
  3. In Firmata firmware (StandardFirmata), when the REPORT_DIGITAL message is received, the pin values for all pins in the corresponding digital 'port' are reported, regardless of the last value of any of those pins. This will happen 3 times for all of these pin since they are all on the same port.

One way to prevent this is to prevent reportDigitalPin in firmata.js from being enabled more than once for the same port.

@morganrallen
Copy link

I'm trying to track down a problem with digitalRead and I'm encountering behavior that looks similar to this. I'm calling digitalRead on pins 1-8 asynchronously like...

  • pin = 1..8
    • set pinMode pin
    • setup digitalRead pin
      • (in callback)
      • reportDigitalPin(pin, 0)
    • externally trigger pin HIGH

There's a debug message inside the callback that starts reading out line...

pin 1 change: 0
.....

pin 1 change: 0
pin 2 change: 0

.....

pin 1 change: 0
pin 2 change: 0
pin 3 change: 0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants