MCPcopy Index your code
hub / github.com/processing/processing / PWM

Method PWM

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

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

(String channel)

Source from the content-addressed store, hash-verified

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

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