public function setDisplay($segments) { $active_pins = []; foreach (str_split($segments) as $segment) { if (isset($this->pinout[$segment])) { $active_pins[$this->pinout[$segment]] = $this->pinout[$segment]; } } foreach ($this->pinout as $pin) { $this->io->setPin($pin, isset($active_pins[$pin]) ? 1 : 0); } }
$gpio->release(); } else { sendError(404, $vars[1] . " Not Found"); } } } function routeRequest($gpio) { $method = $_SERVER['REQUEST_METHOD']; $request_uri = $_SERVER['REQUEST_URI']; $root = $_SERVER['DOCUMENT_ROOT']; $script = $_SERVER['SCRIPT_FILENAME']; $path = pathinfo($script); $context = substr($path['dirname'], strlen($root)); $uri = substr($request_uri, strlen($context)); $vars = explode('/', $uri); global $SERVER_VERSION; header("Server: " + $SERVER_VERSION); if ($method == "GET") { doGET($gpio, $vars); } else { if ($method == "POST") { doPOST($gpio, $vars); } else { sendError(405, "Not Allowed"); } } } $gpio = new GPIO(); $gpio->init(); routeRequest($gpio);
<?php include 'gpiohelper.php'; /* This script cycles a 7-segment display through the numbers 0-9, then exits. pin 0 - button other pins - see declaration of GPIOSevenSegmentDisplay */ $io = new GPIO([0 => 'in', 1 => 'out']); header('content-type: text/plain'); $io->addComponent('display', new GPIOSevenSegmentDisplay($io, ['a' => 1, 'b' => 23, 'c' => 13, 'd' => 14, 'e' => 6, 'f' => 7, 'g' => 26])); $io->display->setValue(0); $io->onChange(0, function (GPIOEvent $event) { static $count = 0; if ($event->state == 1) { // button is down $count++; $event->io->display->setValue($count); if ($count >= 9) { $event->io->end(); } } }); $io->run(); echo 'done';
$this->disable($pin); } } } } } function init() { $this->setPINSEnabled(true); } function release() { $this->setPINSEnabled(false); } } if (isset($_SERVER["SHELL"]) && !isset($_SERVER["GATEWAY_INTERFACE"])) { $gpio = new GPIO(); if ($argc == 1) { } else { if ($argc == 2 && $argv[1] == "init") { $gpio->init(); } else { if ($argc == 2 && $argv[1] == "release") { $gpio->release(); } else { echo "usage:\n"; echo "php " . $argv['0'] . " [init|release]\n"; } } } }
$deviceName = filter_var($_GET["dev"], FILTER_SANITIZE_STRING); } if (isset($_GET["lat"])) { $lat = filter_var($_GET["lat"], FILTER_SANITIZE_STRING); } if (isset($_GET["lng"])) { $lng = filter_var($_GET["lng"], FILTER_SANITIZE_STRING); } if (isset($_GET["name"])) { $name = filter_var($_GET["name"], FILTER_SANITIZE_STRING); } $mailSubject = "RASPI RELE BIT:{$bit} {$deviceName}"; $mailBody = "<b>Aktivita:</b> RASPI RELE BIT<BR>\n <b>Device:</b> {$deviceName} <BR>\n <b>Datum:</b> " . date("d.m.Y H:i:s") . "<BR>\n <b>BIT :</b> {$bit} <BR>\n <b>IP:</b> {$ip}"; $HTTPAnswer = new HTTPAnswer(); $oMySQL = new MySQL('temperature', $GLOBALS["dblogin"], $GLOBALS["dbpwd"], $GLOBALS["dbhost"], 3306); $Gpio = new GPIO($oMySQL); switch ($act) { default: break; case 'getlocation': $HTTPAnswer->HTTPAnswer(HTTP_ANSWER_STATUS_200, $Gpio->getLocationOnJson(), true); break; case 'savelocation': $Gpio->saveLocation($lat, $lng, $name); break; case 'readallevents': $HTTPAnswer->HTTPAnswer(HTTP_ANSWER_STATUS_200, $Gpio->getAllEventsOnJson(), true); break; case 'readall': $HTTPAnswer->HTTPAnswer(HTTP_ANSWER_STATUS_200, $Gpio->getAllBitsOnJson(), true); break;
<?php include 'gpiohelper.php'; /* This script toggles an LED 6 times when a button is pressed, then exits. pin 0 - button pin 1 - LED and resistor */ $io = new GPIO([0 => 'in', 1 => 'out']); header('content-type: text/plain'); $io->onChange(0, function (GPIOEvent $event) { static $count = 0; if ($event->state == 1) { // button is down $state = $event->io->getPin(1); $event->io->setPin(1, 1 - $state); $count++; if ($count >= 6) { $event->io->end(); } } }); $io->run(); echo 'done';
function set($value) { $value_file = $this->base_dir . '/value'; GPIO::_put($value_file, $value); }
<?php include 'gpiohelper.php'; $io = new GPIO([1 => GPIO::OUT]); if (isset($_GET['set'])) { $io->setPin($_GET['set'], 1); } if (isset($_GET['unset'])) { $io->setPin($_GET['unset'], 0); } if (isset($_GET['toggle'])) { $pinval = $io->getPin($_GET['toggle']); $newpinval = 1 - $pinval; $io->setPin($_GET['toggle'], $newpinval); } if (isset($_GET['direction'])) { if ($io->getDirection($_GET['direction']) == GPIO::OUT) { $io->setDirection($_GET['direction'], GPIO::IN); } else { $io->setDirection($_GET['direction'], GPIO::OUT); } } ?> <!DOCTYPE html> <html> <head> <title>GPIO PHP Test Page</title> </head> <body>
<?php include 'gpiohelper.php'; $io = new GPIO([0 => 'out', 1 => 'out', 6 => 'out', 7 => 'in']); function setLine($line) { global $io; $bits = str_split($line, 1); foreach ($bits as $bit) { $bit = intval($bit); $io->setPin(0, $bit); $io->setPin(1, 1); $io->setPin(1, 0); } $io->setPin(0, 0); $io->setPin(6, 1); $io->setPin(6, 0); } $lines = <<<LINES 00000001 00000010 00000100 00001000 00010000 00100000 01000000 10000000 00000000 10000000 01000000 00100000