Description
Because Firmata only reports digital input values on change (via DIGITAL_MESSAGE
), it is currently difficult to read a non-changing digital input. Currently there is only one way a non-changing digital pin value is reported and that is when a user enables reporting for a given port, the values of the pins on that port are reported even if they have not changed. However, depending on how a firmata host library and the user's code is structured, they may miss this value (for example a listener is declared after enabling port reporting). It is also not the most intuitive way to request a non-changing digital input.
There is a proposal open for a way to report digital pin values. That would enable a user to request a specific digital pin value at any time.
The tricky part would be in the Firmata host library implementations. Currently a lot of host libraries use the wiring syntax of digitalRead
to report the existing DIGITAL_MESSAGE
. This only reports digital input changes where as the PIN_VALUE_QUERY
would enable a closer equivalent to the wiring digitalRead
function (aside from the async vs sync issue). One way to update host apis is to use digitalReadOnce
to issue a PIN_VALUE_QUERY
(for a single digital pin). Generally however host libraries would benefit by using DIGITAL_MESSAGE
since it is more efficient (reporting on port basis and only on change) when PIN_VALUE_QUERY
would then be used only for fixed (non-changing) digital inputs as well as the general case of reporting board state after a reconnection event (which was the original intent for the pin value query proposal).