firmata / arduino

Firmata firmware for Arduino
GNU Lesser General Public License v2.1
1.54k stars 515 forks source link

No way to get current state of input pin #129

Closed curzona closed 9 years ago

curzona commented 10 years ago

As of Firmata 2.3 the only way to get the current state of an input pin is to wait until it changes.

Pin state query/response does not return current state of an input pin: "For input modes, typically the state is zero. However, for digital inputs, the state is the status of the pullup resistor."

soundanalogous commented 10 years ago

That is correct. There is not way to know other than storing the pin value in the client code (since the start state is known and you get notified of changes). A change was made in the configurable branch that reports analog or digital pin values when the corresponding pin (analog) or port (digital) is enabled.

There has been some discussion querying pin values and setting individual pin values. See these threads:

curzona commented 10 years ago

@soundanalogous Thanks for the fast response.

With StandardFirmata if I open test_firmata after the pin was configured as an input and is currently high the GUI shows low. Until the pin value changes the GUI will show the wrong value. The changes to force outputPort when reportDigital is enabled does not fix this issue.

soundanalogous commented 10 years ago

Those changes were not made in StandardFirmata.

I don't maintain the test_firmata application. No one does any more as far as I know so I would not view that as reliable. You should test against Firmata client libraries in active development such as johnny-five or perl-firmata.

curzona commented 10 years ago

I had added the changes into StandardFirmata after looking at the link your provided.

curzona commented 10 years ago

Correct me if I'm wrong but the only way the client will know the start state of the pin is if the client is the one that configured them? Which may not be true if auto reset on serial connection is disabled.

soundanalogous commented 10 years ago

You're correct. You can send the system reset command as well but that is not always ideal. I think the best solution here is to add the value to the pin state response in addition to the state (where state for digital is pull up resistor state and value would be the pin value). That would be a backwards compatible update.

ntruchsess commented 10 years ago

That is incorrect, with current ConfigurableFirmata you can allways query the current state of current configured input pins by sending a report-digital-message. You don't need to configure the pin (set pin mode) or 'be the client that did that' to get the appropriate response.

soundanalogous commented 10 years ago

The report-digital-message functionality is what he added to his local copy of StandardFirmata but that did not function as expected when using the firmata_test application. See comments 2 and 3 above. May be an issue with the firmata_test application however since it is no longer maintained (to my knowledge at least).

ntruchsess commented 10 years ago

In context of firmata_test-application your are right, of course, I propably missed that. That application doesn't send out report-digital without configuring the pin.

soundanalogous commented 10 years ago

If I implement in StandardFirmata the ability to report the analog value when an analog pin is enabled and digital pin value (by 8-pin port) when a digital port is enabled (as was already implemented in the configurable branch), will that be sufficient here or is there still a use case to report an individual pin value via a pin state query?