Added bugfix to prevent access errors on newly exported pin control files
This commit is contained in:
parent
17dd85f828
commit
f19a5bcea8
@ -33,4 +33,12 @@ for($n = 1; $n < 16; $n++) {
|
|||||||
usleep(500000);
|
usleep(500000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for($m = 0; $m < 20; $m++) {
|
||||||
|
foreach(array(0, 0, 12, 14, 15, 7, 3, 1, 0) as $n) {
|
||||||
|
$par->write($n);
|
||||||
|
usleep(100000);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
$par->write(0);
|
$par->write(0);
|
||||||
|
@ -155,12 +155,19 @@ class GpioPin
|
|||||||
} else {
|
} else {
|
||||||
$path = "/sys/class/gpio/{$file}";
|
$path = "/sys/class/gpio/{$file}";
|
||||||
}
|
}
|
||||||
if (!is_writable($path)) {
|
if (!file_exists($path)) {
|
||||||
throw new HardwareException("Sysfs file {$path} not writable");
|
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)) {
|
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);
|
fwrite($f,$value);
|
||||||
fclose($f);
|
fclose($f);
|
||||||
|
Loading…
Reference in New Issue
Block a user