Skip to content

Commit 4471608

Browse files
committed
IO: Fix pinMode() retry logic
If the file node is not accessible yet, NativeInterface.writeFile() will return -EACCES instead of -EPERM. Thanks @msurguy for reporting this and testing.
1 parent 356e700 commit 4471608

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

java/libraries/io/src/processing/io/GPIO.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -389,14 +389,14 @@ public static void pinMode(int pin, int mode) {
389389
}
390390

391391
// we need to give udev some time to change the file permissions behind our back
392-
// retry for 500ms when writing to the file fails with -EPERM
392+
// retry for 500ms when writing to the file fails with -EACCES
393393
long start = System.currentTimeMillis();
394394
do {
395395
ret = NativeInterface.writeFile(fn, out);
396-
if (ret == -1) {
396+
if (ret == -13) {
397397
Thread.yield();
398398
}
399-
} while (ret == -1 && System.currentTimeMillis()-start < 500);
399+
} while (ret == -13 && System.currentTimeMillis()-start < 500);
400400

401401
if (ret < 0) {
402402
throw new RuntimeException(fn + ": " + NativeInterface.getError(ret));

0 commit comments

Comments
 (0)