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)
| 271 | * @see disableInterrupt |
| 272 | */ |
| 273 | protected static void enableInterrupt(int pin, int mode) { |
| 274 | checkValidPin(pin); |
| 275 | |
| 276 | String out; |
| 277 | if (mode == NONE) { |
| 278 | out = "none"; |
| 279 | } else if (mode == CHANGE) { |
| 280 | out = "both"; |
| 281 | } else if (mode == FALLING) { |
| 282 | out = "falling"; |
| 283 | } else if (mode == RISING) { |
| 284 | out = "rising"; |
| 285 | } else { |
| 286 | throw new IllegalArgumentException("Unknown mode"); |
| 287 | } |
| 288 | |
| 289 | if (NativeInterface.isSimulated()) { |
| 290 | return; |
| 291 | } |
| 292 | |
| 293 | String fn = String.format("/sys/class/gpio/gpio%d/edge", pin); |
| 294 | int ret = NativeInterface.writeFile(fn, out); |
| 295 | if (ret < 0) { |
| 296 | if (ret == -2) { // ENOENT |
| 297 | System.err.println("Make sure your called pinMode on the input pin"); |
| 298 | } |
| 299 | throw new RuntimeException(NativeInterface.getError(ret)); |
| 300 | } |
| 301 | } |
| 302 | |
| 303 | |
| 304 | /** |
no test coverage detected