function gpio($ettings, $target) { $tatus = readGPIO($target); $gpio = $target['gpioNumber']; //read in cmd flag if set $cmd = isset($_GET["cmd"]) ? $_GET["cmd"] : null; //test if value is a number if (is_numeric($target['gpioNumber'])) { //set the gpio's mode to output setMode($target, "out"); //toggle the gpio to high/low $tatus = $tatus == "0" ? 1 : 0; //check for commanded status flag and act upon it. if (isset($cmd)) { $tatus = $cmd == "off" ? 0 : 1; } writeGPIO($target, $tatus); //reading pin's status $status = readGPIO($target); echo $status; writeTimeStamp(); //only wait to change state if default state is not current state if ($target['state'] != readGPIO($target)) { if (isset($target['timer']) && $target['timer'] > 0) { usleep($target['timer'] * 1000000); writeDefaultToGPIO($target); } } } else { echo "fail"; } writeTimeStamp(); }
exec($script); } function dispatch($ettings, $fs) { if (isset($_GET["target"])) { $name = $_GET["target"]; if (array_key_exists($name, $ettings)) { $target = $ettings["{$name}"]; $type = $target["type"]; if ($type == "gpio") { require "GPIO.php"; gpio($ettings, $target); unlockStatusFile($fs); } else { if ($type == "script") { doScript($target, $fs); } else { echo "I can't handle anything except GPIOs right now " . $target['type'] . "<br>\n"; } } } else { echo "invalid setting {$name}<br>\n"; } } else { echo "no parameters specified to dispatch<br>\n"; } } include_once 'writeTimestamp.php'; dispatch($ettings, $fs); writeTimeStamp();