Improved sysfs file access code

This commit is contained in:
2014-06-12 02:35:19 +02:00
parent 2304372129
commit b53cabec90
5 changed files with 162 additions and 27 deletions

View File

@ -23,6 +23,18 @@ use NoccyLabs\Gpio\Exception\HardwareException;
class Gpio implements \ArrayAccess
{
// Direction
const DIR_IN = "in";
const DIR_OUT = "out";
// Values
const VAL_HIGH = 1;
const VAL_LOW = 0;
// Edges
const EDGE_NONE = "none";
const EDGE_RISING = "rising";
const EDGE_FALLING = "faling";
const EDGE_BOTH = "both";
protected $gpio = array();
/** @var NoccyLabs\Gpio\GpioMapperInterface */
@ -51,7 +63,29 @@ class Gpio implements \ArrayAccess
$pin->doInterrupt();
}
}
public function getPinFromFd($fd)
{
foreach($this->fd_pins as $pinfd=>$pin) {
if ($pinfd == $fd) { return $pin; }
}
return false;
}
protected $fd_gpio = array();
protected $fd_pins = array();
public function enableInterrupt(GpioPin $pin, $fd)
{
$this->fd_gpio[] = $fd;
$this->fd_pins[$fd] = $pin;
}
public function disableInterrupt(GpioPin $pin)
{
}
public function setMapper(GpioMapperInterface $mapper=null)
@ -64,7 +98,7 @@ class Gpio implements \ArrayAccess
{
if ($this->mapper) { $index = $this->mapper->mapLogicalToGpioPin($index); }
if (empty($this->gpio[$index])) {
$this->gpio[$index] = new GpioPin($index);
$this->gpio[$index] = new GpioPin($index, $this);
}
return $this->gpio[$index];
}