X Tutup
Skip to content

Commit 1811de6

Browse files
committed
I/O: Documentation changes
1 parent 75a9f00 commit 1811de6

File tree

5 files changed

+36
-135
lines changed

5 files changed

+36
-135
lines changed

java/libraries/io/src/processing/io/GPIO.java

Lines changed: 28 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

java/libraries/io/src/processing/io/I2C.java

Lines changed: 5 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,8 @@ public class I2C {
4242

4343

4444
/**
45-
* Opens an I2C device as master
46-
*
47-
* @param dev device name
45+
* Opens an I2C interface as master
46+
* @param dev interface name
4847
* @see list
4948
* @webref
5049
*/
@@ -60,19 +59,6 @@ public I2C(String dev) {
6059

6160
/**
6261
* Begins a transmission to an attached device
63-
*
64-
* I2C addresses consist of 7 bits plus one bit that indicates whether
65-
* the device is being read from or written to. Some datasheets list
66-
* the address in an 8 bit form (7 address bits + R/W bit), while others
67-
* provide the address in a 7 bit form, with the address in the lower
68-
* 7 bits. This function expects the address in the lower 7 bits, the
69-
* same way as in Arduino's Wire library, and as shown in the output
70-
* of the i2cdetect tool.
71-
* If the address provided in a datasheet is greater than 127 (hex 0x7f)
72-
* or there are separate addresses for read and write operations listed,
73-
* which vary exactly by one, then you want to shift the this number by
74-
* one bit to the right before passing it as an argument to this function.
75-
* @param slave 7 bit address of slave device
7662
* @see write
7763
* @see read
7864
* @see endTransmission
@@ -111,8 +97,6 @@ protected void finalize() throws Throwable {
11197

11298
/**
11399
* Ends the current transmissions
114-
*
115-
* This executes any queued writes.
116100
* @see beginTransmission
117101
* @see write
118102
* @webref
@@ -137,7 +121,7 @@ public void endTransmission() {
137121

138122

139123
/**
140-
* Lists all available I2C devices
124+
* Lists all available I2C interfaces
141125
* @return String array
142126
* @webref
143127
*/
@@ -161,10 +145,6 @@ public static String[] list() {
161145

162146
/**
163147
* Reads bytes from the attached device
164-
*
165-
* You must call beginTransmission() before calling this function. This function
166-
* also ends the current transmisison and sends any data that was queued using
167-
* write() before.
168148
* @param len number of bytes to read
169149
* @return bytes read from device
170150
* @see beginTransmission
@@ -195,10 +175,6 @@ public byte[] read(int len) {
195175

196176
/**
197177
* Adds bytes to be written to the device
198-
*
199-
* You must call beginTransmission() before calling this function.
200-
* The actual writing takes part when read() or endTransmission() is being
201-
* called.
202178
* @param out bytes to be written
203179
* @see beginTransmission
204180
* @see read
@@ -222,33 +198,23 @@ public void write(byte[] out) {
222198

223199

224200
/**
225-
* Adds bytes to be written to the device
226-
*
227-
* You must call beginTransmission() before calling this function.
228-
* The actual writing takes part when read() or endTransmission() is being
229-
* called.
201+
* Adds bytes to be written to the attached device
230202
* @param out string to be written
231203
* @see beginTransmission
232204
* @see read
233205
* @see endTransmission
234-
* @webref
235206
*/
236207
public void write(String out) {
237208
write(out.getBytes());
238209
}
239210

240211

241212
/**
242-
* Adds a byte to be written to the device
243-
*
244-
* You must call beginTransmission() before calling this function.
245-
* The actual writing takes part when read() or endTransmission() is being
246-
* called.
213+
* Adds a byte to be written to the attached device
247214
* @param out single byte to be written (0-255)
248215
* @see beginTransmission
249216
* @see read
250217
* @see endTransmission
251-
* @webref
252218
*/
253219
public void write(int out) {
254220
if (out < 0 || 255 < out) {

java/libraries/io/src/processing/io/LED.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,6 @@ public void brightness(float bright) {
119119

120120
/**
121121
* Restores the previous state
122-
*
123-
* Without calling this function the LED will remain in the current
124-
* state even after the sketch has been closed.
125122
* @webref
126123
*/
127124
public void close() {

java/libraries/io/src/processing/io/PWM.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,6 @@ public void clear() {
9999

100100
/**
101101
* Gives ownership of a channel back to the operating system
102-
*
103-
* Without calling this function the channel will remain in the current
104-
* state even after the sketch has been closed.
105102
* @webref
106103
*/
107104
public void close() {
@@ -187,10 +184,6 @@ public void set(int period, float duty) {
187184

188185
/**
189186
* Enables the PWM output with a preset period of 1 kHz
190-
*
191-
* This period approximately matches the dedicated PWM pins on
192-
* the Arduino Uno, which have a frequency of 980 Hz.
193-
* It is recommended to use set(period, duty) instead.
194187
* @param duty duty cycle, 0.0 (always off) to 1.0 (always on)
195188
* @webref
196189
*/

0 commit comments

Comments
 (0)
X Tutup