From ba1337633b50ce0cf98d3b1e68dde478ed02f789 Mon Sep 17 00:00:00 2001 From: Tom Aarts Date: Wed, 3 Apr 2024 19:17:03 -0500 Subject: [PATCH] fine tune delay after export. Testing fast SSD failed at 25 ms, worked 99% at 30. Set to 70 ms. Also, fixed bug if application with no pwm config shutdown value call pwm.shutdown(), then pi4j shutdown would invoke unexport a second time --- .../com/pi4j/plugin/linuxfs/provider/pwm/LinuxFsPwm.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/plugins/pi4j-plugin-linuxfs/src/main/java/com/pi4j/plugin/linuxfs/provider/pwm/LinuxFsPwm.java b/plugins/pi4j-plugin-linuxfs/src/main/java/com/pi4j/plugin/linuxfs/provider/pwm/LinuxFsPwm.java index 68631adf..a264023c 100644 --- a/plugins/pi4j-plugin-linuxfs/src/main/java/com/pi4j/plugin/linuxfs/provider/pwm/LinuxFsPwm.java +++ b/plugins/pi4j-plugin-linuxfs/src/main/java/com/pi4j/plugin/linuxfs/provider/pwm/LinuxFsPwm.java @@ -86,7 +86,7 @@ public Pwm initialize(Context context) throws InitializeException { logger.trace("exporting PWM [" + this.config.address() + "]; " + pwm.getPwmPath()); pwm.export(); // Delay to allow the SSD to persist the new directory and device partitions - Thread.sleep(250); + Thread.sleep(70); } else{ logger.trace("PWM [" + this.config.address() + "] is already exported; " + pwm.getPwmPath()); } @@ -224,7 +224,9 @@ public Pwm shutdown(Context context) throws ShutdownException { // otherwise ... un-export the GPIO pin from the Linux file system impl try { logger.trace("un-exporting PWM [" + this.config.address() + "]; " + pwm.getPwmPath()); - pwm.unexport(); + if(pwm.isExported()) { + pwm.unexport(); + } } catch (java.io.IOException e) { logger.error(e.getMessage(), e); throw new ShutdownException("Failed to UN-EXPORT PWM [" + config().address() + "] @ <" + pwm.systemPath() + ">; " + e.getMessage(), e);