Skip to content
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

Set direction in constructor? #3

Closed
colinodell opened this issue May 12, 2016 · 3 comments
Closed

Set direction in constructor? #3

colinodell opened this issue May 12, 2016 · 3 comments

Comments

@colinodell
Copy link

Many other GPIO libraries require you to set the direction at the same time the pin is declared for use - either via the constructor or some other initialization function. This makes sense, because you're probably never going to change the direction of a pin during execution without rewiring your project.

Would it make sense to do the same thing with the Pin class? Basically change its constructor to include a $direction parameter? Or alternatively create separate InputPin and OutputPin classes, where the setValue() method is only available on the latter?

I'd be happy to submit a PR for either change if you're interested.

@AndrewCarterUK
Copy link
Contributor

@colinodell - I like this idea, and I think there is an overlap here with the other issue that you created (#4).

At the moment the library is a very thin wrapper over the sysfs GPIO driver, but I think it can become a lot easier to use with some of the changes you mention.

I'd gladly accept a PR on this if you're willing :)

I can see scenarios where you might want a pin to change (if you created plugs for the GPIO and had different modules that might be plugged in or not) - but it wouldn't stop you from making those changes. The calling code could easily just call the factory again asking for a new pin.

@AndrewCarterUK
Copy link
Contributor

AndrewCarterUK commented May 12, 2016

What do you think about having:

PinFactoryInterface::getInputPin(): InputPinInterface;
PinFactoryInterface::getOutputPin(): OutputPinInterface;

Then we could put the suitable methods onto each interface (and have stricter type checking on the interrupt watcher).

@colinodell
Copy link
Author

Yeah that would be perfect!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants