|
|
|
@ -155,12 +155,19 @@ class GpioPin
|
|
|
|
|
} else {
|
|
|
|
|
$path = "/sys/class/gpio/{$file}";
|
|
|
|
|
}
|
|
|
|
|
if (!is_writable($path)) {
|
|
|
|
|
throw new HardwareException("Sysfs file {$path} not writable");
|
|
|
|
|
if (!file_exists($path)) {
|
|
|
|
|
throw new HardwareException("Sysfs file {$path} does not exist");
|
|
|
|
|
}
|
|
|
|
|
$f = fopen($path,"w+");
|
|
|
|
|
|
|
|
|
|
$ts = microtime(true);
|
|
|
|
|
while ((!is_writable($path)) && (microtime(true) < $ts+1)) {
|
|
|
|
|
usleep(10000);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$f = @fopen($path,"c");
|
|
|
|
|
if (!is_resource($f)) {
|
|
|
|
|
throw new HardwareException("Unable to write to sysfs file {$path}");
|
|
|
|
|
$err = error_get_last();
|
|
|
|
|
throw new HardwareException("Unable to write to sysfs file {$path}: ".$err['message']);
|
|
|
|
|
}
|
|
|
|
|
fwrite($f,$value);
|
|
|
|
|
fclose($f);
|
|
|
|
|