Added exceptions to gpio class
This commit is contained in:
9
lib/Exception/HardwareException.php
Normal file
9
lib/Exception/HardwareException.php
Normal file
@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace NoccyLabs\Gpio\Exception;
|
||||
|
||||
use NoccyLabs\Gpio\GpioPin;
|
||||
|
||||
class HardwareException extends \Exception
|
||||
{
|
||||
}
|
12
lib/Gpio.php
12
lib/Gpio.php
@ -19,12 +19,24 @@
|
||||
|
||||
namespace NoccyLabs\Gpio;
|
||||
|
||||
use NoccyLabs\Gpio\Exception\HardwareException;
|
||||
|
||||
class Gpio implements \ArrayAccess
|
||||
{
|
||||
protected $gpio = array();
|
||||
|
||||
/** @var NoccyLabs\Gpio\GpioMapperInterface */
|
||||
protected $mapper;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
if (!file_exists("/sys/gpio")) {
|
||||
throw new HardwareException("gpio sysfs is not available");
|
||||
}
|
||||
if (!is_writable("/sys/gpio/export")) {
|
||||
throw new HardwareException("gpio sysfs is not writable");
|
||||
}
|
||||
}
|
||||
|
||||
public function refresh()
|
||||
{
|
||||
|
@ -137,7 +137,7 @@ class GpioPin
|
||||
public function dumpStatus($ansi=false)
|
||||
{
|
||||
if ($ansi) {
|
||||
$status = "\e[43;37;1m GPIO{$this->pin} \e[0m\n";
|
||||
$status = "\e[44;37;1m GPIO{$this->pin} \e[0m\n";
|
||||
$direction = "\e[36;1m".
|
||||
($this->direction=="input"?(CS::chr(0x2190)):(CS::chr(0x2192))).
|
||||
"\e[0m ".$this->direction;
|
||||
|
Reference in New Issue
Block a user