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

Method LED

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

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

(String dev)

Source from the content-addressed store, hash-verified

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

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