GeezerVison is showing github.com — I/O: Another filename fix for PWM · dimr/processing@46185d7
File tree
Expand file treeCollapse file tree
Open diff view settings
java/libraries/io/src/processing/io
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: java/libraries/io/src/processing/io/PWM.java +3-1Lines changed: 3 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -157,17 +157,19 @@ public static String[] list() { |
157 | 157 | public void set(int period, float duty) { |
158 | 158 | // set period |
159 | 159 | String fn = fn = String.format("/sys/class/pwm/%s/pwm%d/period", chip, channel); |
| 160 | + // convert to nanoseconds |
160 | 161 | int ret = NativeInterface.writeFile(fn, String.format("%d", (int)(1000000000 / period))); |
161 | 162 | if (ret < 0) { |
162 | 163 | throw new RuntimeException(fn + ": " + NativeInterface.getError(ret)); |
163 | 164 | } |
164 | 165 |
|
165 | 166 | // 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); |
167 | 168 | if (duty < 0.0 || 1.0 < duty) { |
168 | 169 | System.err.println("Duty cycle must be between 0.0 and 1.0."); |
169 | 170 | throw new IllegalArgumentException("Illegal argument"); |
170 | 171 | } |
| 172 | + // convert to nanoseconds |
171 | 173 | ret = NativeInterface.writeFile(fn, String.format("%d", (int)((1000000000 * duty) / period))); |
172 | 174 | if (ret < 0) { |
173 | 175 | throw new RuntimeException(fn + ": " + NativeInterface.getError(ret)); |
|