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

Pin::getEdge/setEdge #4

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

Pin::getEdge/setEdge #4

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

Comments

@colinodell
Copy link

Edge detection is primarily used for interrupt detection - sometimes we only care about interrupts LOW -> HIGH for example. However, it looks like this is being set via the Pin class (and can be done for output pins, which isn't useful). Would it make more sense to set this on the interrupt watcher instead?

@AndrewCarterUK
Copy link
Contributor

Let me give this some thought!

Trying to decide if this is best as a parameter to InterruptWatcher::register(), a parameter to the input pin factory or a method on the input pin.

@AndrewCarterUK
Copy link
Contributor

I think my main concern about having this is an InterruptWatcher::register() parameter or factory parameter is that it implies it wont change.

I'm leaning towards methods on an InputPin class.

@colinodell
Copy link
Author

I feel it's more logical to define the edge you're interested in detecting at the same time you're registering the callback to handle occurrences of that edge.

For example, let's say I want a callback to fire whenever a button is pressed. I'd want to listen for any FALLING (or RISING) events and do some action. However, hooking that same callback up to a pin set to BOTH means the callback would fire twice. If I forget to set the pin's edge beforehand, or if it's modified at some other point in time, my callback isn't going to work as expected.

For Arduino, setting the edge is done when registering the interrupt callback: https://www.arduino.cc/en/Reference/AttachInterrupt

RPi.GPIO does the same thing with their wait_for_edge() function: https://sourceforge.net/p/raspberry-gpio-python/wiki/Inputs/

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

No branches or pull requests

2 participants