*/ namespace NoccyLabs\Gpio; use NoccyLabs\Gpio\Exception\HardwareException; /** * Watch GPIO for interrupts (hardware or software) * * * */ class GpioWatcher { protected $fd_gpio = array(); protected $fd_pins = array(); public function refresh() { $read = $this->fd_gpio; $write = array(); $except = $read; if (count($read)>0) { stream_select($read, $write, $except, 0); foreach($except as $fd) { $pin = $this->getPinFromFd($fd); $pin->doInterrupt(); } } } public function getPinFromFd($fd) { foreach($this->fd_pins as $pinfd=>$pin) { if ($pinfd == $fd) { return $pin; } } return false; } public function enableInterrupt(GpioPin $pin, $fd) { $this->fd_gpio[] = $fd; $this->fd_pins[$fd] = $pin; } public function disableInterrupt(GpioPin $pin) { } }