-
Notifications
You must be signed in to change notification settings - Fork 585
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
Create New GpioPin and IGpioPin #215
Comments
/cc @krwq |
@shaggygi I actually thought about it a bit and we don't need to change existing design. We will need to add new types of controllers which will map to other controllers. Example would be something like VirtualController where you can:
but if we are ever going to provide a pin abstraction I think this should be a simple struct of IGpioController and a number |
Is there any decision/progress on this proposal? In our application code handling multiple GPIOs in different (unrelated) classes, we see a pattern evolving which would be much easier to implement with IMHO the current API is a bit "C-like"; in .NET we are used to having objects for everything. The only place where I see an advantage for the current API ( |
@UncleSamSwiss this was actually one of the main topics we discussed when coming up with the original API Proposal, and after weighing the pros and cons we decided that a C-like approach would be better here because of several reasons including the life-cycle of objects and other things. For reference, you can take a look at all three of our API discussions which are linked here. For those reasons, we have pretty much all of our API with the existing shape, and moving it back to exposing a GpioPin would be very costly so there would have to be a big enough reason why we would want to do this. Is there a specific scenario where you think GpioPin is a much better approach such that it would make it feasible to change our API shape? |
@joperezr thanks for your explanation. I can understand your reasoning; and of course changing it now would be a huge endeavor. Just to explain my use case, here is more or less a copy&paste of our code (won't compile):
Note: As you can see in the In the This would be much nicer (i.e. more object oriented) if we had an
Looking at the given solution, it would also be possible to provide both APIs, but I guess to the inexperienced developer it would be confusing to have two ways to accomplish the same. |
In your concrete example, yes you have to do two calls instead of one, that said, without knowing a bit more about your service I believe that one other thing you could/should do, is to dispose the controller itself, which will do the cleanup for you. Because the Controllers are disposable, then having a pin object might be dangerous since you could have the case where a pin's controller has been disposed but the pin object itself is not yet, so that might cause weird life cycle problems. BTW, thanks for bringing your scenario up and starting this interesting discussion, I believe that these types of discussions will make our library much better for library and app developers! |
I started using this library expecting a much more |
We've talked about this today and we need to give this more though before we agree to have this. The specific scenarios which need more considerations:
We need some design doc which covers answers for these questions/thoughts |
One possibility I considered in my board concept was to create GpioController(s) that act only on a subset of the available pins. This doesn't solve the performance problem, but it may prevent some errors like accidentally operating on a pin that belongs to something completelly unrelated to the current binding. Would it be possible to open the wiki feature on the repo, or do we have another way of collaboratelly creating design documents? |
An interesting implementation is the one we can find in nanoFrmaework: https://github.com/nanoframework/lib-System.Device.Gpio/tree/develop/System.Device.Gpio |
@pgrawehr for design documents temporarily you can create .md file under i.e. |
@Ellerbach one way to not change current APIs perhaps could be to leave OpenPin/ClosePin and add something like |
How can it be source compatible? it didn't use to return anything and now we would want to return a pin and you'd have to call write on that, instead of the controller. |
Anything existing will continue to work. No change on the GpioController methods except the OpenPin which does return a GpioPin. |
yes, how I see that is GpioPin would automatically call One thing to consider to get more benefit of potential GpioPin would be to allow option for pin to not be managed by controller after openning in order to reduce overhead of having the dictionary |
I upvote for this improvement too. Having GpioPin is so much more convenient and it feels more .NETish. As @Ellerbach suggested, please take a look at the implementation we have on .NET nanoFramework, here. There are a few other improvements that we have there that can be considered like As for "freeing" the Gpio from the controller as @krwq suggested, that's something to consider too. |
ref: #124 |
[Triage] Closing this in favor of: #1671 |
It would be nice to have the ability to provide actual GPIO pin objects to bindings instead of pin numbers. Currently, we usually have to provide a GPIO controller along with pin numbers or just the pin numbers and the binding will create the controller and configure the pins. This is a limitation as the pins are usually all on the same controller where I might want to mix it up between dev board, bindings, etc.
Examples
Referencing #125 (comment)
Also referencing #204 as it appears we would want something similar to PwmPins.
The text was updated successfully, but these errors were encountered: