Added exceptions to gpio class
This commit is contained in:
parent
64d338cf90
commit
cdb8edd4e0
3
composer.lock
generated
3
composer.lock
generated
@ -1,7 +1,8 @@
|
|||||||
{
|
{
|
||||||
"_readme": [
|
"_readme": [
|
||||||
"This file locks the dependencies of your project to a known state",
|
"This file locks the dependencies of your project to a known state",
|
||||||
"Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file"
|
"Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
|
||||||
|
"This file is @generated automatically"
|
||||||
],
|
],
|
||||||
"hash": "6ede4cbc5ab4ef05b58811c306b5376f",
|
"hash": "6ede4cbc5ab4ef05b58811c306b5376f",
|
||||||
"packages": [
|
"packages": [
|
||||||
|
@ -23,7 +23,7 @@ $led = $gpio[0]
|
|||||||
->setLabel("red led")
|
->setLabel("red led")
|
||||||
->dumpStatus(true);
|
->dumpStatus(true);
|
||||||
|
|
||||||
$btn = $gpio[1]
|
$btn1 = $gpio[1]
|
||||||
->setDirection("input")
|
->setDirection("input")
|
||||||
->setValue(0)
|
->setValue(0)
|
||||||
->setEdge("rising")
|
->setEdge("rising")
|
||||||
@ -31,7 +31,7 @@ $btn = $gpio[1]
|
|||||||
->setLabel("button 1")
|
->setLabel("button 1")
|
||||||
->dumpStatus(true);
|
->dumpStatus(true);
|
||||||
|
|
||||||
$gpio[2]
|
$btn2 = $gpio[2]
|
||||||
->setDirection("input")
|
->setDirection("input")
|
||||||
->setValue(0)
|
->setValue(0)
|
||||||
->setEdge("rising")
|
->setEdge("rising")
|
||||||
|
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;
|
namespace NoccyLabs\Gpio;
|
||||||
|
|
||||||
|
use NoccyLabs\Gpio\Exception\HardwareException;
|
||||||
|
|
||||||
class Gpio implements \ArrayAccess
|
class Gpio implements \ArrayAccess
|
||||||
{
|
{
|
||||||
protected $gpio = array();
|
protected $gpio = array();
|
||||||
|
|
||||||
/** @var NoccyLabs\Gpio\GpioMapperInterface */
|
/** @var NoccyLabs\Gpio\GpioMapperInterface */
|
||||||
protected $mapper;
|
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()
|
public function refresh()
|
||||||
{
|
{
|
||||||
|
@ -137,7 +137,7 @@ class GpioPin
|
|||||||
public function dumpStatus($ansi=false)
|
public function dumpStatus($ansi=false)
|
||||||
{
|
{
|
||||||
if ($ansi) {
|
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".
|
$direction = "\e[36;1m".
|
||||||
($this->direction=="input"?(CS::chr(0x2190)):(CS::chr(0x2192))).
|
($this->direction=="input"?(CS::chr(0x2190)):(CS::chr(0x2192))).
|
||||||
"\e[0m ".$this->direction;
|
"\e[0m ".$this->direction;
|
||||||
|
Loading…
Reference in New Issue
Block a user