Skip to content

Commit 46185d7

Browse files
committed
I/O: Another filename fix for PWM
1 parent 08d0269 commit 46185d7

File tree

1 file changed

+3
-1
lines changed
  • java/libraries/io/src/processing/io

1 file changed

+3
-1
lines changed

java/libraries/io/src/processing/io/PWM.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,17 +157,19 @@ public static String[] list() {
157157
public void set(int period, float duty) {
158158
// set period
159159
String fn = fn = String.format("/sys/class/pwm/%s/pwm%d/period", chip, channel);
160+
// convert to nanoseconds
160161
int ret = NativeInterface.writeFile(fn, String.format("%d", (int)(1000000000 / period)));
161162
if (ret < 0) {
162163
throw new RuntimeException(fn + ": " + NativeInterface.getError(ret));
163164
}
164165

165166
// set duty cycle
166-
fn = fn = String.format("/sys/class/pwm/%s/pwm%d/duty", chip, channel);
167+
fn = fn = String.format("/sys/class/pwm/%s/pwm%d/duty_cycle", chip, channel);
167168
if (duty < 0.0 || 1.0 < duty) {
168169
System.err.println("Duty cycle must be between 0.0 and 1.0.");
169170
throw new IllegalArgumentException("Illegal argument");
170171
}
172+
// convert to nanoseconds
171173
ret = NativeInterface.writeFile(fn, String.format("%d", (int)((1000000000 * duty) / period)));
172174
if (ret < 0) {
173175
throw new RuntimeException(fn + ": " + NativeInterface.getError(ret));

0 commit comments

Comments
 (0)