Lists all available PWM channels @return String array @webref
()
| 136 | * @webref |
| 137 | */ |
| 138 | public static String[] list() { |
| 139 | if (NativeInterface.isSimulated()) { |
| 140 | return new String[]{ "pwmchip0/pwm0", "pwmchip0/pwm1" }; |
| 141 | } |
| 142 | |
| 143 | ArrayList<String> devs = new ArrayList<String>(); |
| 144 | File dir = new File("/sys/class/pwm"); |
| 145 | File[] chips = dir.listFiles(); |
| 146 | if (chips != null) { |
| 147 | for (File chip : chips) { |
| 148 | // get the number of supported channels |
| 149 | try { |
| 150 | Path path = Paths.get("/sys/class/pwm/" + chip.getName() + "/npwm"); |
| 151 | String tmp = new String(Files.readAllBytes(path)); |
| 152 | int npwm = Integer.parseInt(tmp.trim()); |
| 153 | for (int i=0; i < npwm; i++) { |
| 154 | devs.add(chip.getName() + "/pwm" + i); |
| 155 | } |
| 156 | } catch (Exception e) { |
| 157 | } |
| 158 | } |
| 159 | } |
| 160 | // listFiles() does not guarantee ordering |
| 161 | String[] tmp = devs.toArray(new String[devs.size()]); |
| 162 | Arrays.sort(tmp); |
| 163 | return tmp; |
| 164 | } |
| 165 | |
| 166 | |
| 167 | /** |