Added comments to device classes

This commit is contained in:
Chris 2014-06-12 16:11:35 +02:00
parent 551b9529cc
commit 3713efa6cc
2 changed files with 27 additions and 5 deletions

View File

@ -55,6 +55,10 @@ abstract class Device implements GpioAwareInterface
public function getDescription() public function getDescription()
{} {}
/**
* Allocate a GPIO (as defined in hardware) pin to the device.
*
*/
public function addGpioPin($gpio, $name, $description=null) public function addGpioPin($gpio, $name, $description=null)
{ {
$pin = new GpioPin($gpio); $pin = new GpioPin($gpio);
@ -62,6 +66,10 @@ abstract class Device implements GpioAwareInterface
$this->pins[$name] = $pin; $this->pins[$name] = $pin;
} }
/**
* Allocate a logical (wiring-pi 0-based pin number) pin to the device.
*
*/
public function addLogicalPin($logical, $name, $description=null) public function addLogicalPin($logical, $name, $description=null)
{ {
$pin = $this->gpio[$logical]; $pin = $this->gpio[$logical];
@ -69,15 +77,32 @@ abstract class Device implements GpioAwareInterface
$this->pins[$name] = $pin; $this->pins[$name] = $pin;
} }
/**
* Get all allocated pins
*
*/
public function getPins() public function getPins()
{ {
return $this->pins; return $this->pins;
} }
/**
* Get a pin by the name specified when allocating it
*
*/
public function getPin($name) public function getPin($name)
{ {
return $this->pins[$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 delayMillis($ms)
{} {}
@ -85,8 +110,4 @@ abstract class Device implements GpioAwareInterface
public function delayMicros($us) public function delayMicros($us)
{} {}
public function __get($pin_name)
{
return $this->getPin($pin_name);
}
} }

View File

@ -32,6 +32,7 @@ class Pcd8544Device extends Device
->addLogicalPin(1, "sce", "chip select") ->addLogicalPin(1, "sce", "chip select")
->addLogicalPin(2, "scl", "clock") ->addLogicalPin(2, "scl", "clock")
->addLogicalPin(3, "sda", "data") ->addLogicalPin(3, "sda", "data")
->addLogicalPin(4, "res", "reset")
->addLogicalPin(9, "bl", "backlight") ->addLogicalPin(9, "bl", "backlight")
; ;
} }
@ -43,6 +44,6 @@ class Pcd8544Device extends Device
public function setBacklightState($state) public function setBacklightState($state)
{ {
$this->bl->write((int)$state); $this->bl->setValue((bool)$state);
} }
} }