Implemented base of GpioMapperInterface with WiringPiMapper

This commit is contained in:
2014-06-06 19:50:17 +02:00
parent d00bcde3ee
commit 633e254958
7 changed files with 445 additions and 36 deletions

View File

@ -1,38 +1,72 @@
<?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;
class Gpio
class Gpio implements \ArrayAccess
{
public function __construct()
{}
protected $gpio = array();
/** @var NoccyLabs\Gpio\GpioMapperInterface */
protected $mapper;
// call export before getpin
public function getPin($pinno)
{}
public function refresh()
{
$read = $this->fd_gpio;
$write = array();
$except = $read;
select($read, $write, $except, 0);
foreach($except as $fd) {
$pin = $this->getPinFromFd($fd);
$pin->doInterrupt();
}
// export the pin
public function exportPin($pinno)
{}
}
// unexport the pin
public function unexportPin($pinno)
{}
public function setMapper(GpioMapperInterface $mapper=null)
{
$this->mapper = $mapper;
return $this;
}
// set handler, pass null to disable interrupts
public function setInterruptHandler(GpioPin $pin, callable $handler=null)
{}
public function offsetGet($index)
{
if ($this->mapper) { $index = $this->mapper->mapLogicalToGpioPin($index); }
if (empty($this->gpio[$index])) {
$this->gpio[$index] = new GpioPin($index);
}
return $this->gpio[$index];
}
// get the interrupt handler for the pin
public function getInterruptHandler(GpioPin $pin)
{}
public function offsetExists($index)
{
return array_key_exists($index, $this->gpio);
}
// set edge
public function setInterruptEdge(GpioPin $pin, $edge)
{}
public function offsetSet($index,$value)
{ throw new \Exception(); }
// get edge
public function getInterruptEdge(GpioPin $pin)
{}
public function offsetUnset($index)
{
unset($this->gpio[$index]);
}
}