2014-06-06 14:00:34 +00:00
|
|
|
Linux Userspace GPIO Library
|
|
|
|
============================
|
|
|
|
|
|
|
|
* Export and Unexport GPIO pins
|
|
|
|
* Interrupt support (*)
|
2014-06-12 12:22:37 +00:00
|
|
|
* Hardware-neutral rewrite of NoccyLabs RaspIO
|
|
|
|
* Compatible with psr/logs LoggerInterface for logging
|
2014-06-06 14:00:34 +00:00
|
|
|
|
|
|
|
## Interrupts
|
|
|
|
|
2014-06-12 12:22:37 +00:00
|
|
|
*NOTE: Not implemented!*
|
|
|
|
|
2014-06-06 14:00:34 +00:00
|
|
|
For interrupts to work, you need to first bind the interrupt handler, and then
|
|
|
|
make sure to call on `Gpio#refresh()` every cycle to poll the interrupt flag on
|
2014-06-12 12:22:37 +00:00
|
|
|
the selected pins. This is because the `select()` function is used.
|
2014-06-06 14:00:34 +00:00
|
|
|
|
|
|
|
$gpio = new Gpio();
|
|
|
|
|
2014-06-12 12:22:37 +00:00
|
|
|
// Set the handler on the Gpio object
|
|
|
|
$gpio->setInterruptHandler($gpio[4], function() { ... });
|
|
|
|
// Or like this on the GpioPin.
|
|
|
|
$gpio[4]
|
|
|
|
->setEdge("rising")
|
|
|
|
->setHandler(function() { ... });
|
2014-06-06 14:00:34 +00:00
|
|
|
|
|
|
|
while (..) {
|
|
|
|
..
|
|
|
|
$gpio->refresh();
|
|
|
|
}
|
|
|
|
|
2014-06-12 12:22:37 +00:00
|
|
|
You can also be risky and use php ticks and timerfuncs (although that might not
|
|
|
|
be portable/supported/efficient/a good idea):
|
|
|
|
|
|
|
|
declare(ticks=5);
|
|
|
|
|
|
|
|
$gpio = new Gpio();
|
|
|
|
|
|
|
|
$gpiotick = new GpioTickHandler();
|
|
|
|
$gpiotick->registerGpio($gpio);
|
|
|
|
|
|
|
|
// The interrupts will now be polled approx every 5th php vm "tick"
|
|
|
|
|
|
|
|
|