@@ -89,14 +89,9 @@ public static void analogWrite(int pin, int value) {
8989
9090
9191 /**
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
9893 * @param pin GPIO pin
99- * @param parent this
94+ * @param parent typically use " this"
10095 * @param method name of sketch method to call
10196 * @param mode when to call: GPIO.CHANGE, GPIO.FALLING or GPIO.RISING
10297 * @see noInterrupts
@@ -163,7 +158,6 @@ public void run() {
163158 * Board-specific classes, such as RPI, assign -1 to pins that carry power,
164159 * ground and the like.
165160 * @param pin GPIO pin
166- * @webref
167161 */
168162 protected static void checkValidPin (int pin ) {
169163 if (pin < 0 ) {
@@ -174,9 +168,6 @@ protected static void checkValidPin(int pin) {
174168
175169 /**
176170 * 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.
180171 * @param pin GPIO pin
181172 * @return GPIO.HIGH (1) or GPIO.LOW (0)
182173 * @see pinMode
@@ -207,14 +198,9 @@ public static int digitalRead(int pin) {
207198
208199
209200 /**
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
216202 * @param pin GPIO pin
217- * @param value GPIO.HIGH or GPIO.LOW
203+ * @param value GPIO.HIGH (1) or GPIO.LOW (0)
218204 * @see pinMode
219205 * @see digitalRead
220206 * @webref
@@ -247,17 +233,7 @@ public static void digitalWrite(int pin, int value) {
247233
248234
249235 /**
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
257236 * @param value true or false
258- * @see pinMode
259- * @see digitalRead
260- * @webref
261237 */
262238 public static void digitalWrite (int pin , boolean value ) {
263239 if (value ) {
@@ -269,33 +245,24 @@ public static void digitalWrite(int pin, boolean value) {
269245
270246
271247 /**
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
277249 * @param pin GPIO pin
278250 * @see enableInterrupt
279251 * @see waitForInterrupt
280- * @webref
281252 */
282- public static void disableInterrupt (int pin ) {
253+ protected static void disableInterrupt (int pin ) {
283254 enableInterrupt (pin , NONE );
284255 }
285256
286257
287258 /**
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
292260 * @param pin GPIO pin
293261 * @param mode what to wait for: GPIO.CHANGE, GPIO.FALLING or GPIO.RISING
294262 * @see waitForInterrupt
295263 * @see disableInterrupt
296- * @webref
297264 */
298- public static void enableInterrupt (int pin , int mode ) {
265+ protected static void enableInterrupt (int pin , int mode ) {
299266 checkValidPin (pin );
300267
301268 String out ;
@@ -324,11 +291,6 @@ public static void enableInterrupt(int pin, int mode) {
324291
325292 /**
326293 * 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.
332294 * @see attachInterrupt
333295 * @see noInterrupts
334296 * @see releaseInterrupt
@@ -341,11 +303,6 @@ public static void interrupts() {
341303
342304 /**
343305 * 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.
349306 * @see attachInterrupt
350307 * @see interrupts
351308 * @see releaseInterrupt
@@ -357,11 +314,7 @@ public static void noInterrupts() {
357314
358315
359316 /**
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
365318 * @param pin GPIO pin
366319 * @param mode GPIO.INPUT or GPIO.OUTPUT
367320 * @see digitalRead
@@ -421,10 +374,7 @@ public static void pinMode(int pin, int mode) {
421374
422375
423376 /**
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
428378 * @param pin GPIO pin
429379 * @see attachInterrupt
430380 * @see noInterrupts
@@ -452,9 +402,6 @@ public static void releaseInterrupt(int pin) {
452402
453403 /**
454404 * 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.
458405 * @param pin GPIO pin
459406 * @see pinMode
460407 * @webref
@@ -477,7 +424,21 @@ public static void releasePin(int pin) {
477424
478425
479426 /**
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
481442 *
482443 * Make sure to setup the interrupt with enableInterrupt() before calling
483444 * this function. A timeout value of -1 waits indefinitely.
@@ -486,9 +447,8 @@ public static void releasePin(int pin) {
486447 * @return true if the interrupt occured, false if the timeout occured
487448 * @see enableInterrupt
488449 * @see disableInterrupt
489- * @webref
490450 */
491- public static boolean waitForInterrupt (int pin , int timeout ) {
451+ protected static boolean waitForInterrupt (int pin , int timeout ) {
492452 checkValidPin (pin );
493453
494454 String fn = String .format ("/sys/class/gpio/gpio%d/value" , pin );
@@ -509,17 +469,16 @@ public static boolean waitForInterrupt(int pin, int timeout) {
509469
510470
511471 /**
512- * Waits for the value of an INPUT pin to change
472+ * Waits for the value of an input pin to change
513473 *
514474 * Make sure to setup the interrupt with enableInterrupt() before calling
515475 * this function. This function will wait indefinitely for an interrupt
516476 * to occur.
517477 * @parm pin GPIO pin
518478 * @see enableInterrupt
519479 * @see disableInterrupt
520- * @webref
521480 */
522- public static void waitForInterrupt (int pin ) {
481+ protected static void waitForInterrupt (int pin ) {
523482 waitForInterrupt (pin , -1 );
524483 }
525484}
0 commit comments