@@ -89,14 +89,9 @@ public static void analogWrite(int pin, int value) { |
89 | 89 |
|
90 | 90 |
|
91 | 91 | /** |
92 | | - * Calls a function when the value of an INPUT pin changes |
93 | | - * |
94 | | - * Don't use enableInterrupt() and waitForInterrupt() in combination with |
95 | | - * this function, as they are orthogonal. The sketch method provided must |
96 | | - * accept a single integer (int) parameter, which is the number of the GPIO |
97 | | - * pin that the interrupt occured on. |
| 92 | + * Calls a function when the value of an input pin changes |
98 | 93 | * @param pin GPIO pin |
99 | | - * @param parent this |
| 94 | + * @param parent typically use "this" |
100 | 95 | * @param method name of sketch method to call |
101 | 96 | * @param mode when to call: GPIO.CHANGE, GPIO.FALLING or GPIO.RISING |
102 | 97 | * @see noInterrupts |
@@ -163,7 +158,6 @@ public void run() { |
163 | 158 | * Board-specific classes, such as RPI, assign -1 to pins that carry power, |
164 | 159 | * ground and the like. |
165 | 160 | * @param pin GPIO pin |
166 | | - * @webref |
167 | 161 | */ |
168 | 162 | protected static void checkValidPin(int pin) { |
169 | 163 | if (pin < 0) { |
@@ -174,9 +168,6 @@ protected static void checkValidPin(int pin) { |
174 | 168 |
|
175 | 169 | /** |
176 | 170 | * Returns the value of an input pin |
177 | | - * |
178 | | - * You need to set the pin to INPUT by calling pinMode before calling |
179 | | - * this function. |
180 | 171 | * @param pin GPIO pin |
181 | 172 | * @return GPIO.HIGH (1) or GPIO.LOW (0) |
182 | 173 | * @see pinMode |
@@ -207,14 +198,9 @@ public static int digitalRead(int pin) { |
207 | 198 |
|
208 | 199 |
|
209 | 200 | /** |
210 | | - * Sets an output pin to HIGH or LOW |
211 | | - * |
212 | | - * You need set the pin to OUTPUT by calling pinMode before calling this |
213 | | - * function. It is not possible to enable or disable internal pull-up |
214 | | - * resistors for inputs using this function, which is something that's |
215 | | - * supported on Arduino. |
| 201 | + * Sets an output pin to be either high or low |
216 | 202 | * @param pin GPIO pin |
217 | | - * @param value GPIO.HIGH or GPIO.LOW |
| 203 | + * @param value GPIO.HIGH (1) or GPIO.LOW (0) |
218 | 204 | * @see pinMode |
219 | 205 | * @see digitalRead |
220 | 206 | * @webref |
@@ -247,17 +233,7 @@ public static void digitalWrite(int pin, int value) { |
247 | 233 |
|
248 | 234 |
|
249 | 235 | /** |
250 | | - * Sets an output pin to HIGH or LOW |
251 | | - * |
252 | | - * You need set the pin to OUTPUT by calling pinMode before calling this |
253 | | - * function. It is not possible to enable or disable internal pull-up |
254 | | - * resistors for inputs using this function, which is something that's |
255 | | - * supported on Arduino. |
256 | | - * @param pin GPIO pin |
257 | 236 | * @param value true or false |
258 | | - * @see pinMode |
259 | | - * @see digitalRead |
260 | | - * @webref |
261 | 237 | */ |
262 | 238 | public static void digitalWrite(int pin, boolean value) { |
263 | 239 | if (value) { |
@@ -269,33 +245,24 @@ public static void digitalWrite(int pin, boolean value) { |
269 | 245 |
|
270 | 246 |
|
271 | 247 | /** |
272 | | - * Disables an interrupt for an INPUT pin |
273 | | - * |
274 | | - * Use this function only in combination with enableInterrupt() and |
275 | | - * waitForInterrupt(). This should not be called when attachInterrupt() |
276 | | - * is being used. |
| 248 | + * Disables an interrupt for an input pin |
277 | 249 | * @param pin GPIO pin |
278 | 250 | * @see enableInterrupt |
279 | 251 | * @see waitForInterrupt |
280 | | - * @webref |
281 | 252 | */ |
282 | | - public static void disableInterrupt(int pin) { |
| 253 | + protected static void disableInterrupt(int pin) { |
283 | 254 | enableInterrupt(pin, NONE); |
284 | 255 | } |
285 | 256 |
|
286 | 257 |
|
287 | 258 | /** |
288 | | - * Enables an interrupt for an INPUT pin |
289 | | - * |
290 | | - * Use this function only when calling waitForInterrupt(). This should not |
291 | | - * be called when attachInterrupt() is being used. |
| 259 | + * Enables an interrupt for an input pin |
292 | 260 | * @param pin GPIO pin |
293 | 261 | * @param mode what to wait for: GPIO.CHANGE, GPIO.FALLING or GPIO.RISING |
294 | 262 | * @see waitForInterrupt |
295 | 263 | * @see disableInterrupt |
296 | | - * @webref |
297 | 264 | */ |
298 | | - public static void enableInterrupt(int pin, int mode) { |
| 265 | + protected static void enableInterrupt(int pin, int mode) { |
299 | 266 | checkValidPin(pin); |
300 | 267 |
|
301 | 268 | String out; |
@@ -324,11 +291,6 @@ public static void enableInterrupt(int pin, int mode) { |
324 | 291 |
|
325 | 292 | /** |
326 | 293 | * Allows interrupts to happen |
327 | | - * |
328 | | - * You can use noInterrupts() and interrupts() in tandem to make sure no interrupts |
329 | | - * are occuring while your sketch is doing a particular task. This is only relevant |
330 | | - * when using attachInterrupt(), not for waitForInterrupt(). By default, interrupts |
331 | | - * are enabled. |
332 | 294 | * @see attachInterrupt |
333 | 295 | * @see noInterrupts |
334 | 296 | * @see releaseInterrupt |
@@ -341,11 +303,6 @@ public static void interrupts() { |
341 | 303 |
|
342 | 304 | /** |
343 | 305 | * Prevents interrupts from happpening |
344 | | - * |
345 | | - * You can use noInterrupts() and interrupts() in tandem to make sure no interrupts |
346 | | - * are occuring while your sketch is doing a particular task. This is only relevant |
347 | | - * when using attachInterrupt(), not for waitForInterrupt(). By default, interrupts |
348 | | - * are enabled. |
349 | 306 | * @see attachInterrupt |
350 | 307 | * @see interrupts |
351 | 308 | * @see releaseInterrupt |
@@ -357,11 +314,7 @@ public static void noInterrupts() { |
357 | 314 |
|
358 | 315 |
|
359 | 316 | /** |
360 | | - * Sets a pin to INPUT or OUTPUT |
361 | | - * |
362 | | - * While pins are implicitly set to input by default on Arduino, it is |
363 | | - * necessary to call this function for any pin you want to access later, |
364 | | - * including input pins. |
| 317 | + * Configures a pin to act either as input or output |
365 | 318 | * @param pin GPIO pin |
366 | 319 | * @param mode GPIO.INPUT or GPIO.OUTPUT |
367 | 320 | * @see digitalRead |
@@ -421,10 +374,7 @@ public static void pinMode(int pin, int mode) { |
421 | 374 |
|
422 | 375 |
|
423 | 376 | /** |
424 | | - * Stops listening for interrupts on an INPUT pin |
425 | | - * |
426 | | - * Use this function only in combination with attachInterrupt(). This should |
427 | | - * not be called when enableInterrupt() and waitForInterrupt() are being used. |
| 377 | + * Stops listening for interrupts on an input pin |
428 | 378 | * @param pin GPIO pin |
429 | 379 | * @see attachInterrupt |
430 | 380 | * @see noInterrupts |
@@ -452,9 +402,6 @@ public static void releaseInterrupt(int pin) { |
452 | 402 |
|
453 | 403 | /** |
454 | 404 | * Gives ownership of a pin back to the operating system |
455 | | - * |
456 | | - * Without calling this function the pin will remain in the current |
457 | | - * state even after the sketch has been closed. |
458 | 405 | * @param pin GPIO pin |
459 | 406 | * @see pinMode |
460 | 407 | * @webref |
@@ -477,7 +424,21 @@ public static void releasePin(int pin) { |
477 | 424 |
|
478 | 425 |
|
479 | 426 | /** |
480 | | - * Waits for the value of an INPUT pin to change |
| 427 | + * Waits for the value of an input pin to change |
| 428 | + * @param pin GPIO pin |
| 429 | + * @param mode what to wait for: GPIO.CHANGE, GPIO.FALLING or GPIO.RISING |
| 430 | + * @param timeout don't wait more than timeout milliseconds (-1 waits indefinitely) |
| 431 | + * @return true if the interrupt occured, false if the timeout occured |
| 432 | + * @webref |
| 433 | + */ |
| 434 | + public static boolean waitForInterrupt(int pin, int mode, int timeout) { |
| 435 | + enableInterrupt(pin, mode); |
| 436 | + return waitForInterrupt(pin, timeout); |
| 437 | + } |
| 438 | + |
| 439 | + |
| 440 | + /** |
| 441 | + * Waits for the value of an input pin to change |
481 | 442 | * |
482 | 443 | * Make sure to setup the interrupt with enableInterrupt() before calling |
483 | 444 | * this function. A timeout value of -1 waits indefinitely. |
@@ -486,9 +447,8 @@ public static void releasePin(int pin) { |
486 | 447 | * @return true if the interrupt occured, false if the timeout occured |
487 | 448 | * @see enableInterrupt |
488 | 449 | * @see disableInterrupt |
489 | | - * @webref |
490 | 450 | */ |
491 | | - public static boolean waitForInterrupt(int pin, int timeout) { |
| 451 | + protected static boolean waitForInterrupt(int pin, int timeout) { |
492 | 452 | checkValidPin(pin); |
493 | 453 |
|
494 | 454 | String fn = String.format("/sys/class/gpio/gpio%d/value", pin); |
@@ -509,17 +469,16 @@ public static boolean waitForInterrupt(int pin, int timeout) { |
509 | 469 |
|
510 | 470 |
|
511 | 471 | /** |
512 | | - * Waits for the value of an INPUT pin to change |
| 472 | + * Waits for the value of an input pin to change |
513 | 473 | * |
514 | 474 | * Make sure to setup the interrupt with enableInterrupt() before calling |
515 | 475 | * this function. This function will wait indefinitely for an interrupt |
516 | 476 | * to occur. |
517 | 477 | * @parm pin GPIO pin |
518 | 478 | * @see enableInterrupt |
519 | 479 | * @see disableInterrupt |
520 | | - * @webref |
521 | 480 | */ |
522 | | - public static void waitForInterrupt(int pin) { |
| 481 | + protected static void waitForInterrupt(int pin) { |
523 | 482 | waitForInterrupt(pin, -1); |
524 | 483 | } |
525 | 484 | } |