php-linux-gpio/lib/Device/Device.php

114 lines
2.4 KiB
PHP

<?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\Device;
abstract class Device implements GpioAwareInterface
{
protected $name;
protected $gpio;
protected $pins = array();
protected function configure()
{
// call on ->addGpioPin etc here
}
public function setGpio(Gpio $gpio=null)
{
$this->gpio = $gpio;
}
public function getGpio()
{
return $this->gpio;
}
public function setName($name)
{}
public function getName()
{}
public function setDescription($description)
{}
public function getDescription()
{}
/**
* Allocate a GPIO (as defined in hardware) pin to the device.
*
*/
public function addGpioPin($gpio, $name, $description=null)
{
$pin = new GpioPin($gpio);
$pin->setLabel($description);
$this->pins[$name] = $pin;
}
/**
* Allocate a logical (wiring-pi 0-based pin number) pin to the device.
*
*/
public function addLogicalPin($logical, $name, $description=null)
{
$pin = $this->gpio[$logical];
$pin->setLabel($description);
$this->pins[$name] = $pin;
}
/**
* Get all allocated pins
*
*/
public function getPins()
{
return $this->pins;
}
/**
* Get a pin by the name specified when allocating it
*
*/
public function getPin($name)
{
return $this->pins[$name];
}
/**
* Get a pin as a property from its name
*
*/
protected function __get($pin_name)
{
return $this->getPin($pin_name);
}
public function delayMillis($ms)
{}
public function delayMicros($us)
{}
}