Improved sysfs file access code
This commit is contained in:
36
lib/Gpio.php
36
lib/Gpio.php
@ -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];
|
||||
}
|
||||
|
Reference in New Issue
Block a user