Armed the gpio class
This commit is contained in:
@ -45,12 +45,12 @@ class GpioPin
|
||||
public function __construct($pin)
|
||||
{
|
||||
$this->pin = (int)$pin;
|
||||
//$this->fd = fopen("/sys/class/gpio/gpio{$pin}/value", "rb");
|
||||
$this->fd = fopen("/sys/class/gpio/gpio{$pin}/value", "rb");
|
||||
}
|
||||
|
||||
public function __destruct()
|
||||
{
|
||||
//fclose($this->fd);
|
||||
fclose($this->fd);
|
||||
}
|
||||
|
||||
public function setDirection($direction)
|
||||
@ -59,7 +59,7 @@ class GpioPin
|
||||
throw new \Exception;
|
||||
}
|
||||
$this->direction = $direction;
|
||||
//file_put_contents("/sys/class/gpio/{$this->pin}/direction", $direction);
|
||||
file_put_contents("/sys/class/gpio/{$this->pin}/direction", $direction);
|
||||
return $this;
|
||||
}
|
||||
|
||||
@ -71,7 +71,7 @@ class GpioPin
|
||||
public function setValue($value)
|
||||
{
|
||||
$this->value = (bool)$value;
|
||||
//file_put_contents("/sys/class/gpio/{$this->pin}/value", (int)$this->value);
|
||||
file_put_contents("/sys/class/gpio/{$this->pin}/value", (int)$this->value);
|
||||
return $this;
|
||||
}
|
||||
|
||||
@ -93,18 +93,16 @@ class GpioPin
|
||||
|
||||
public function export()
|
||||
{
|
||||
/*
|
||||
file_put_contents("/sys/class/gpio/export", $this->pin);
|
||||
if (!file_exists("/sys/class/gpio/gpio{$this->pin}")) {
|
||||
throw new \Exception();
|
||||
}
|
||||
*/
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function unexport()
|
||||
{
|
||||
//file_put_contents("/sys/class/gpio/unexport", $this->pin);
|
||||
file_put_contents("/sys/class/gpio/unexport", $this->pin);
|
||||
return $this;
|
||||
}
|
||||
|
||||
@ -114,7 +112,7 @@ class GpioPin
|
||||
throw new \Exception;
|
||||
}
|
||||
$this->edge = $edge;
|
||||
//file_put_contents("/sys/class/gpio/{$this->pin}/edge", $edge);
|
||||
file_put_contents("/sys/class/gpio/{$this->pin}/edge", $edge);
|
||||
return $this;
|
||||
}
|
||||
|
||||
@ -138,17 +136,17 @@ class GpioPin
|
||||
{
|
||||
if ($ansi) {
|
||||
$status = "\e[44;37;1m GPIO{$this->pin} \e[0m\n";
|
||||
$direction = "\e[36;1m".
|
||||
$direction =
|
||||
($this->direction=="input"?(CS::chr(0x2190)):(CS::chr(0x2192))).
|
||||
"\e[0m ".$this->direction;
|
||||
$edge = "\e[33;1m";
|
||||
if ($this->edge == "rising") {
|
||||
$edge.= CS::chr(0x21A5)."\e[0m rising";
|
||||
" ".$this->direction;
|
||||
$edge = $this->edge; //"";
|
||||
/*if ($this->edge == "rising") {
|
||||
$edge.= CS::chr(0x21A5)." rising";
|
||||
} elseif ($this->edge == "falling") {
|
||||
$edge.= CS::chr(0x21A7)."\e[0m falling";
|
||||
$edge.= CS::chr(0x21A7)." falling";
|
||||
} else {
|
||||
$edge.= "\e[0m".$this->edge;
|
||||
}
|
||||
}*/
|
||||
} else {
|
||||
$status = "********** GPIO{$this->pin} **********\n";
|
||||
$direction = $this->direction;
|
||||
|
Reference in New Issue
Block a user