From 3713efa6cca9c6edba67387a6cd5df7e4a3f67f7 Mon Sep 17 00:00:00 2001 From: Christopher Vagnetoft Date: Thu, 12 Jun 2014 16:11:35 +0200 Subject: [PATCH] Added comments to device classes --- lib/Device/Device.php | 29 ++++++++++++++++++++++++---- lib/Device/Display/Pcd8544Device.php | 3 ++- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/lib/Device/Device.php b/lib/Device/Device.php index 7ea9952..b65a348 100644 --- a/lib/Device/Device.php +++ b/lib/Device/Device.php @@ -55,6 +55,10 @@ abstract class Device implements GpioAwareInterface 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); @@ -62,6 +66,10 @@ abstract class Device implements GpioAwareInterface $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]; @@ -69,15 +77,32 @@ abstract class Device implements GpioAwareInterface $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) {} @@ -85,8 +110,4 @@ abstract class Device implements GpioAwareInterface public function delayMicros($us) {} - public function __get($pin_name) - { - return $this->getPin($pin_name); - } } diff --git a/lib/Device/Display/Pcd8544Device.php b/lib/Device/Display/Pcd8544Device.php index 601a6da..ee4daee 100644 --- a/lib/Device/Display/Pcd8544Device.php +++ b/lib/Device/Display/Pcd8544Device.php @@ -32,6 +32,7 @@ class Pcd8544Device extends Device ->addLogicalPin(1, "sce", "chip select") ->addLogicalPin(2, "scl", "clock") ->addLogicalPin(3, "sda", "data") + ->addLogicalPin(4, "res", "reset") ->addLogicalPin(9, "bl", "backlight") ; } @@ -43,6 +44,6 @@ class Pcd8544Device extends Device public function setBacklightState($state) { - $this->bl->write((int)$state); + $this->bl->setValue((bool)$state); } }