firmata/protocol

[v3.0.0] PIN_STATE_QUERY should also report current resolution

Opened this issue · 6 comments

0  START_SYSEX              (0xF0)
1  pin state response       (0x6E)
2  pin                      (0-127)
3  pin mode (the currently configured mode)
?  pin resolution (the resolution to support the mode) <--------------------- PLEASE ADD THIS
4  pin state, bits 0-6
5  (optional) pin state, bits 7-13
6  (optional) pin state, bits 14-20
... additional optional bytes, as many as needed
N  END_SYSEX                (0xF7)

you can already get the resolution from the capability query

also, I could add it in a backwards compatible way by adding it after byte 6... although I'd have to make pin state a fixed length

I thought capability query would tell the maximum resolution of the pin. I am looking for the current resolution; similar to pin mode.

I would hesitate to add it after byte six. I thought the point to have as big of a value as you need. That would cap you at two bytes - as you said... :-) I didn't read thoroughly until after I typed.

Capability query is the current default resolution for the pin. There is currently no API in the protocol that enables changing the pin resolution (although I have had a proposal open for a number of years). This does get more complex as more boards now have DACs. PWM resolution may be able to change on a per pin basis (for non-Arduino boards). Analog input resolution can currently only be changed globally for Arduino, but perhaps for other platforms it can be changed on individual pins (although Firmata currently only supports Arduino and Particle).

Fair enough. I just thought I would float the idea. I don't really have a use for it now, but as I complete the wiring API, I can see that it will become necessary.

It's a worthwhile suggestion. I'm not sure yet whether it fits better into the pin state queryor if it make more sense as part of the proposed analog config message (which needs to be updated in general), in which case I'd add getters for the analog read and write resolutions (global per board rather than pin-based).