Implemented the tick handler

This commit is contained in:
2014-06-12 18:14:51 +02:00
parent e37e63980c
commit d7cfbcaf28
4 changed files with 110 additions and 5 deletions

View File

@ -57,11 +57,13 @@ class Gpio implements \ArrayAccess
$read = $this->fd_gpio;
$write = array();
$except = $read;
select($read, $write, $except, 0);
foreach($except as $fd) {
$pin = $this->getPinFromFd($fd);
$pin->doInterrupt();
if (count($read)>0) {
stream_select($read, $write, $except, 0);
foreach($except as $fd) {
$pin = $this->getPinFromFd($fd);
$pin->doInterrupt();
}
}
}

46
lib/GpioTickHandler.php Normal file
View File

@ -0,0 +1,46 @@
<?php
/*
* Copyright (C) 2014, NoccyLabs
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
namespace NoccyLabs\Gpio;
declare(ticks=5);
class GpioTickHandler
{
protected $gpio = array();
public function __construct()
{
register_tick_function(array($this,"onTick"));
}
public function registerGpio(Gpio $gpio)
{
$this->gpio[] = $gpio;
return $this;
}
public function onTick()
{
foreach($this->gpio as $g) {
$g->refresh();
}
}
}