MCPcopy Index your code
hub / github.com/benfry/processing4 / PWM

Method PWM

java/libraries/io/src/processing/io/PWM.java:54–92  ·  view source on GitHub ↗

Opens a PWM channel @param channel PWM channel @see list @webref PWM @webBrief Opens a PWM channel

(String channel)

Source from the content-addressed store, hash-verified

52 * @webBrief Opens a PWM channel
53 */
54 public PWM(String channel) {
55 NativeInterface.loadLibrary();
56
57 int pos = channel.indexOf("/pwm");
58 if (pos == -1) {
59 throw new IllegalArgumentException("Unsupported channel");
60 }
61 chip = channel.substring(0, pos);
62 this.channel = Integer.parseInt(channel.substring(pos+4));
63
64 if (NativeInterface.isSimulated()) {
65 return;
66 }
67
68 // export channel through sysfs
69 String fn = "/sys/class/pwm/" + chip + "/export";
70 int ret = NativeInterface.writeFile(fn, Integer.toString(this.channel));
71 if (ret < 0) {
72 if (ret == -2) { // ENOENT
73 System.err.println("Make sure your kernel is compiled with PWM_SYSFS enabled and you have the necessary PWM driver for your platform");
74 }
75 // XXX: check
76 if (ret == -22) { // EINVAL
77 System.err.println("PWM channel " + channel + " does not seem to be available on your platform");
78 }
79 // XXX: check
80 if (ret != -16) { // EBUSY, returned when the pin is already exported
81 throw new RuntimeException(fn + ": " + NativeInterface.getError(ret));
82 }
83 }
84
85 // delay to give udev a chance to change the file permissions behind our back
86 // there should really be a cleaner way for this
87 try {
88 Thread.sleep(500);
89 } catch (InterruptedException e) {
90 Thread.currentThread().interrupt();
91 }
92 }
93
94
95 /**

Callers

nothing calls this directly

Calls 7

loadLibraryMethod · 0.95
isSimulatedMethod · 0.95
writeFileMethod · 0.95
getErrorMethod · 0.95
parseIntMethod · 0.80
toStringMethod · 0.45
printlnMethod · 0.45

Tested by

no test coverage detected