GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — IO: Speed up GPIO.pinMode() · crazyrex/processing@4cbf6bc

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • java/libraries/io/src/processing/io
    • GPIO.java
Expand file treeCollapse file tree
Open diff view settings
Collapse file

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

Copy file name to clipboardExpand all lines: java/libraries/io/src/processing/io/GPIO.java
+11-9Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff 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
}

0 commit comments

Comments
0 (0)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.