Lists all available LED devices @return String array @webref LED @webBrief Lists all available LED devices
()
| 176 | * @webBrief Lists all available LED devices |
| 177 | */ |
| 178 | public static String[] list() { |
| 179 | if (NativeInterface.isSimulated()) { |
| 180 | // as on the Raspberry Pi |
| 181 | return new String[]{ "led0", "led1" }; |
| 182 | } |
| 183 | |
| 184 | ArrayList<String> devs = new ArrayList<>(); |
| 185 | File dir = new File("/sys/class/leds"); |
| 186 | File[] files = dir.listFiles(); |
| 187 | if (files != null) { |
| 188 | for (File file : files) { |
| 189 | devs.add(file.getName()); |
| 190 | } |
| 191 | } |
| 192 | // listFiles() does not guarantee ordering |
| 193 | String[] tmp = devs.toArray(new String[devs.size()]); |
| 194 | Arrays.sort(tmp); |
| 195 | return tmp; |
| 196 | } |
| 197 | } |