vsergeev / python-periphery

A pure Python 2/3 library for peripheral I/O (GPIO, LED, PWM, SPI, I2C, MMIO, Serial) in Linux.
MIT License
531 stars 142 forks source link

gpio interrupts? #12

Closed jhonoryza closed 6 years ago

jhonoryza commented 6 years ago

is this library support gpio interrupts handling ??

ftp2010 commented 6 years ago

I need use interrupts ,too .

vsergeev commented 6 years ago

Yes, you can set up an edge interrupt with the edge property, and poll for the event with the poll() method.

Example:

gpio = GPIO(10, "in")
gpio.edge = "rising"
gpio.poll()  # Blocks until rising event occurs

See the documentation here: http://python-periphery.readthedocs.io/en/latest/gpio.html#periphery.GPIO.poll

The GPIO class also exposes the underlying file descriptor with the fd property, which you can use in a I/O multiplexing API like select(), poll(), or epoll(), but be aware that you may need to "rewind" the file after an event occurs. See the implementation of poll() in the codebase for more details on this.