File tree Expand file tree Collapse file tree 1 file changed +11
-9
lines changed
java/libraries/io/src/processing/io Expand file tree Collapse file tree 1 file changed +11
-9
lines changed Original file line number Diff line number Diff line change @@ -356,14 +356,6 @@ public static void pinMode(int pin, int mode) {
356356 }
357357 }
358358
359- // delay to give udev a chance to change the file permissions behind our back
360- // there should really be a cleaner way for this
361- try {
362- Thread .sleep (500 );
363- } catch (InterruptedException e ) {
364- Thread .currentThread ().interrupt ();
365- }
366-
367359 // set direction and default level for outputs
368360 fn = String .format ("/sys/class/gpio/gpio%d/direction" , pin );
369361 String out ;
@@ -395,7 +387,17 @@ public static void pinMode(int pin, int mode) {
395387 } else {
396388 throw new IllegalArgumentException ("Unknown mode" );
397389 }
398- ret = NativeInterface .writeFile (fn , out );
390+
391+ // 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
393+ long start = System .currentTimeMillis ();
394+ do {
395+ ret = NativeInterface .writeFile (fn , out );
396+ if (ret == -1 ) {
397+ Thread .yield ();
398+ }
399+ } while (ret == -1 && System .currentTimeMillis ()-start < 500 );
400+
399401 if (ret < 0 ) {
400402 throw new RuntimeException (fn + ": " + NativeInterface .getError (ret ));
401403 }
You can’t perform that action at this time.
0 commit comments