Enables an interrupt for an input pin @param pin GPIO pin @param mode what to wait for: GPIO.CHANGE, GPIO.FALLING or GPIO.RISING @see waitForInterrupt @see disableInterrupt
(int pin, int mode)
| 299 | * @see disableInterrupt |
| 300 | */ |
| 301 | protected static void enableInterrupt(int pin, int mode) { |
| 302 | checkValidPin(pin); |
| 303 | |
| 304 | String out; |
| 305 | if (mode == NONE) { |
| 306 | out = "none"; |
| 307 | } else if (mode == CHANGE) { |
| 308 | out = "both"; |
| 309 | } else if (mode == FALLING) { |
| 310 | out = "falling"; |
| 311 | } else if (mode == RISING) { |
| 312 | out = "rising"; |
| 313 | } else { |
| 314 | throw new IllegalArgumentException("Unknown mode"); |
| 315 | } |
| 316 | |
| 317 | if (NativeInterface.isSimulated()) { |
| 318 | return; |
| 319 | } |
| 320 | |
| 321 | String fn = String.format("/sys/class/gpio/gpio%d/edge", pin); |
| 322 | int ret = NativeInterface.writeFile(fn, out); |
| 323 | if (ret < 0) { |
| 324 | if (ret == -2) { // ENOENT |
| 325 | System.err.println("Make sure your called pinMode on the input pin"); |
| 326 | } |
| 327 | throw new RuntimeException(NativeInterface.getError(ret)); |
| 328 | } |
| 329 | } |
| 330 | |
| 331 | |
| 332 | /** |
no test coverage detected