| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| 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)); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments