rust-wiringpi
rust-wiringpi copied to clipboard
Allow reading an output pin
While seemingly redundent, having the ability to read an output pin would eliminate needing to store pin state separately by the user. It looks like an OutputPin can be turned into an InputPin, but this seems like rather tedious to do each time a pin needs to be queried for it's state.
The changes back and forth changes the actual pin state, so they are not just semantic. Something I can imagine that could simplify would be something like an RwPin
that switches automatically when a read
or write
call is made. Not too different from RefCell
, and could possibly be optimized in a similar way by the compiler.
Ah, yes that was the thought. If it changes under the hood, although the performance hit is probably not very significant, is already what I'm doing on my own project. I was under the impression wiringpi let you read a pin exported as an output without re-exporting it.
The pin mode will still have to be set, unless that changed recently in wiringpi, and the different *Pin
objects are meant to make it harder to forget, by doing it automatically on creation. The only problem with the current approach, apart from the ergonomics, is that there is no global tracking. If you export a pin as two different types (keeping both), the application may end up in a bad state. I have, so far, just allowed it, but it would not hurt if it could be safer without affecting the performance too much.