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

Method LED

java/libraries/io/src/processing/io/LED.java:52–103  ·  view source on GitHub ↗

Opens a LED device @param dev device name @see list @webref

(String dev)

Source from the content-addressed store, hash-verified

50 * @webref
51 */
52 public LED(String dev) {
53 NativeInterface.loadLibrary();
54 this.dev = dev;
55
56 if (NativeInterface.isSimulated()) {
57 return;
58 }
59
60 // read maximum brightness
61 try {
62 Path path = Paths.get("/sys/class/leds/" + dev + "/max_brightness");
63 String tmp = new String(Files.readAllBytes(path));
64 maxBrightness = Integer.parseInt(tmp.trim());
65 } catch (Exception e) {
66 System.err.println(e.getMessage());
67 throw new RuntimeException("Unable to read maximum brightness");
68 }
69
70 // read current trigger setting to be able to restore it later
71 try {
72 Path path = Paths.get("/sys/class/leds/" + dev + "/trigger");
73 String tmp = new String(Files.readAllBytes(path));
74 int start = tmp.indexOf('[');
75 int end = tmp.indexOf(']', start);
76 if (start != -1 && end != -1) {
77 prevTrigger = tmp.substring(start+1, end);
78 }
79 } catch (Exception e) {
80 System.err.println(e.getMessage());
81 throw new RuntimeException("Unable to read trigger setting");
82 }
83
84 // read current brightness to be able to restore it later
85 try {
86 Path path = Paths.get("/sys/class/leds/" + dev + "/brightness");
87 String tmp = new String(Files.readAllBytes(path));
88 prevBrightness = Integer.parseInt(tmp.trim());
89 } catch (Exception e) {
90 System.err.println(e.getMessage());
91 throw new RuntimeException("Unable to read current brightness");
92 }
93
94 // disable trigger
95 String fn = "/sys/class/leds/" + dev + "/trigger";
96 int ret = NativeInterface.writeFile(fn, "none");
97 if (ret < 0) {
98 if (ret == -13) { // EACCES
99 System.err.println("You might need to install a custom udev rule to allow regular users to modify /sys/class/leds/*.");
100 }
101 throw new RuntimeException(NativeInterface.getError(ret));
102 }
103 }
104
105
106 /**

Callers

nothing calls this directly

Calls 9

loadLibraryMethod · 0.95
isSimulatedMethod · 0.95
writeFileMethod · 0.95
getErrorMethod · 0.95
parseIntMethod · 0.80
getMethod · 0.65
getMessageMethod · 0.65
trimMethod · 0.45
printlnMethod · 0.45

Tested by

no test coverage detected