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

Add a wait_for_edge() function #18

Open
benoitguigal opened this issue Jan 4, 2015 · 3 comments
Open

Add a wait_for_edge() function #18

benoitguigal opened this issue Jan 4, 2015 · 3 comments

Comments

@benoitguigal
Copy link

In the RPi.GPIO library there is an interrupt method called 'wait_for_edge' that block until an event is detected. Is there a way of achieving the same beahavior with pifacecommon ?
http://raspberrypi-aa.github.io/session2/input.html

@Doug-Wyman
Copy link

I am also looking for such a function

@tompreston
Copy link
Member

I've had an idea for this for a very long time - just not got around to implementing it. I'm not even sure if Raspbian is still organised like this but I imagine it would work something like this:

  1. Bring up GPIO25 in userland with echo 25 > /sys/class/gpio/export.

  2. In Python, use epoll to wait on changes:

    with open('/sys/class/gpio/gpio25/value', 'r') as gpio25:
        epoll = select.epoll()
        epoll.register(gpio25, select.EPOLLIN | select.EPOLLET)
        events = epoll.poll()  #  wait for interrupt
        epoll.close()
    

This could be wrapped up into a wait_for_edge function. This is how the C libs work: https://github.com/piface/libmcp23s17/blob/master/src/mcp23s17.c#L189-L203

@tompreston
Copy link
Member

libgpiod is the future of Linux gpio, so when someone gets around to implementing this, it should use that:

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

No branches or pull requests

3 participants