FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Merge pull request #3997 from gohai/for-ben-14 · raj347/processing@f33df17 · GitHub

Repository navigation

Commit f33df17

Browse files
committed
Merge pull request processing#3997 from gohai/for-ben-14
Medium-sized I/O updates
2 parents a1bd718 + 46185d7 commit f33df17

12 files changed

Lines changed: 180 additions & 234 deletions

File tree

‎build/build.xml‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1347,6 +1347,10 @@ remove the spaces for depth since it should be double dash, but screws up commen
13471347
<include name="antlr/**" />
13481348
<include name="processing/**" />
13491349
</packageset>
1350+
<packageset dir="../java/libraries/io/src">
1351+
<include name="antlr/**" />
1352+
<include name="processing/**" />
1353+
</packageset>
13501354
<packageset dir="../java/libraries/net/src">
13511355
<include name="antlr/**" />
13521356
<include name="processing/**" />

‎java/libraries/io/build.xml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0"?>
2-
<project name="Processing I/O Library" default="build">
2+
<project name="Processing Hardware I/O Library" default="build">
33

44
<target name="clean" description="Clean the build directories">
55
<delete dir="bin" />
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
name = I/O
1+
name = Hardware I/O
22
version = 1
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
name = I/O for Raspberry Pi and other Linux-based computers
1+
name = Hardware I/O for Raspberry Pi and other Linux-based computers

‎java/libraries/io/src/native/impl.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
Copyright (c) The Processing Foundation 2015
3-
I/O library developed by Gottfried Haider as part of GSOC 2015
3+
Hardware I/O library developed by Gottfried Haider as part of GSoC 2015
44
55
This library is free software; you can redistribute it and/or
66
modify it under the terms of the GNU Lesser General Public

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

Lines changed: 54 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
/*
44
Copyright (c) The Processing Foundation 2015
5-
I/O library developed by Gottfried Haider as part of GSOC 2015
5+
Hardware I/O library developed by Gottfried Haider as part of GSoC 2015
66
77
This library is free software; you can redistribute it and/or
88
modify it under the terms of the GNU Lesser General Public
@@ -31,6 +31,9 @@
3131
import java.util.Map;
3232

3333

34+
/**
35+
* @webref
36+
*/
3437
public class GPIO {
3538

3639
// those constants are generally the same as in Arduino.h
@@ -43,9 +46,18 @@ public class GPIO {
4346
public static final int HIGH = 1;
4447

4548
public static final int NONE = 0;
46-
public static final int CHANGE = 1; // trigger when level changes
47-
public static final int FALLING = 2; // trigger when level changes from high to low
48-
public static final int RISING = 3; // trigger when level changes from low to high
49+
/**
50+
* trigger when level changes
51+
*/
52+
public static final int CHANGE = 1;
53+
/**
54+
* trigger when level changes from high to low
55+
*/
56+
public static final int FALLING = 2;
57+
/**
58+
* trigger when level changes from low to high
59+
*/
60+
public static final int RISING = 3;
4961

5062
protected static Map<Integer, Thread> irqThreads = new HashMap<Integer, Thread>();
5163
protected static boolean serveInterrupts = true;
@@ -77,19 +89,15 @@ public static void analogWrite(int pin, int value) {
7789

7890

7991
/**
80-
* Calls a function when the value of an INPUT pin changes
81-
*
82-
* Don't use enableInterrupt() and waitForInterrupt() in combination with
83-
* this function, as they are orthogonal. The sketch method provided must
84-
* accept a single integer (int) parameter, which is the number of the GPIO
85-
* pin that the interrupt occured on.
92+
* Calls a function when the value of an input pin changes
8693
* @param pin GPIO pin
87-
* @param parent this
94+
* @param parent typically use "this"
8895
* @param method name of sketch method to call
8996
* @param mode when to call: GPIO.CHANGE, GPIO.FALLING or GPIO.RISING
9097
* @see noInterrupts
9198
* @see interrupts
9299
* @see releaseInterrupt
100+
* @webref
93101
*/
94102
public static void attachInterrupt(int pin, PApplet parent, String method, int mode) {
95103
if (irqThreads.containsKey(pin)) {
@@ -158,63 +166,13 @@ protected static void checkValidPin(int pin) {
158166
}
159167

160168

161-
/**
162-
* Pauses the execution of the sketch
163-
*
164-
* Calling this function will have an influence on the framerate
165-
* the sketch is going to achieve.
166-
* @param ms milliseconds to pause
167-
*/
168-
protected static void delay(int ms) {
169-
try {
170-
Thread.sleep(ms);
171-
} catch (InterruptedException e) {
172-
}
173-
}
174-
175-
176-
/**
177-
* Pauses the execution of the sketch
178-
*
179-
* Note: Both the operating system, as well as Processing, are not what is
180-
* called "hard real-time" systems. In other words: there are many factors,
181-
* outside of the control of the programmer, which can influence the execution
182-
* of the program in minute ways. Those are generally not an issue, or even
183-
* noticeable using a desktop operating system, but they can be a factor, when
184-
* the timing of a particular sequence of events is critical. For example, one
185-
* might to wait a very specific number amount of time after receiving an
186-
* interrupt before changing the state of an output pin. When programming with
187-
* micro-controllers, as found on the Arduino Uno, there very little between
188-
* your code and the actual hardware, and multiple executions of the same
189-
* sketch will probably match each other almost to the very tick of a clock
190-
* (which happens at the speed of 16 MHz). Systems running full-fledged
191-
* desktop operating systems, such as Linux, are generally multi-tasking,
192-
* which means that the operating system allocates small slices of time to
193-
* the many different processes that run concurrently. The effect of this is
194-
* often offset by the sheer clock speeds that such computers run. But
195-
* regardless: if you require your sketch to adhere to a very specific timing,
196-
* you might be disappointed.
197-
* @param us microseconds to pause
198-
*/
199-
protected static void delayMicroseconds(int us) {
200-
int ms = (int)(us / 1000);
201-
int ns = (us - (ms * 1000)) * 1000;
202-
try {
203-
Thread.sleep(ms, ns);
204-
} catch (InterruptedException e) {
205-
}
206-
}
207-
208-
209169
/**
210170
* Returns the value of an input pin
211-
*
212-
* You need to set the pin to INPUT by calling pinMode before calling
213-
* this function.
214171
* @param pin GPIO pin
215172
* @return GPIO.HIGH (1) or GPIO.LOW (0)
216173
* @see pinMode
217174
* @see digitalWrite
175+
* @webref
218176
*/
219177
public static int digitalRead(int pin) {
220178
checkValidPin(pin);
@@ -240,16 +198,12 @@ public static int digitalRead(int pin) {
240198

241199

242200
/**
243-
* Sets an output pin to HIGH or LOW
244-
*
245-
* You need set the pin to OUTPUT by calling pinMode before calling this
246-
* function. It is not possible to enable or disable internal pull-up
247-
* resistors for inputs using this function, which is something that's
248-
* supported on Arduino.
201+
* Sets an output pin to be either high or low
249202
* @param pin GPIO pin
250-
* @param value GPIO.HIGH or GPIO.LOW
203+
* @param value GPIO.HIGH (1) or GPIO.LOW (0)
251204
* @see pinMode
252205
* @see digitalRead
206+
* @webref
253207
*/
254208
public static void digitalWrite(int pin, int value) {
255209
checkValidPin(pin);
@@ -279,16 +233,7 @@ public static void digitalWrite(int pin, int value) {
279233

280234

281235
/**
282-
* Sets an output pin to HIGH or LOW
283-
*
284-
* You need set the pin to OUTPUT by calling pinMode before calling this
285-
* function. It is not possible to enable or disable internal pull-up
286-
* resistors for inputs using this function, which is something that's
287-
* supported on Arduino.
288-
* @param pin GPIO pin
289236
* @param value true or false
290-
* @see pinMode
291-
* @see digitalRead
292237
*/
293238
public static void digitalWrite(int pin, boolean value) {
294239
if (value) {
@@ -300,31 +245,24 @@ public static void digitalWrite(int pin, boolean value) {
300245

301246

302247
/**
303-
* Disables an interrupt for an INPUT pin
304-
*
305-
* Use this function only in combination with enableInterrupt() and
306-
* waitForInterrupt(). This should not be called when attachInterrupt()
307-
* is being used.
248+
* Disables an interrupt for an input pin
308249
* @param pin GPIO pin
309250
* @see enableInterrupt
310251
* @see waitForInterrupt
311252
*/
312-
public static void disableInterrupt(int pin) {
253+
protected static void disableInterrupt(int pin) {
313254
enableInterrupt(pin, NONE);
314255
}
315256

316257

317258
/**
318-
* Enables an interrupt for an INPUT pin
319-
*
320-
* Use this function only when calling waitForInterrupt(). This should not
321-
* be called when attachInterrupt() is being used.
259+
* Enables an interrupt for an input pin
322260
* @param pin GPIO pin
323261
* @param mode what to wait for: GPIO.CHANGE, GPIO.FALLING or GPIO.RISING
324262
* @see waitForInterrupt
325263
* @see disableInterrupt
326264
*/
327-
public static void enableInterrupt(int pin, int mode) {
265+
protected static void enableInterrupt(int pin, int mode) {
328266
checkValidPin(pin);
329267

330268
String out;
@@ -353,14 +291,10 @@ public static void enableInterrupt(int pin, int mode) {
353291

354292
/**
355293
* Allows interrupts to happen
356-
*
357-
* You can use noInterrupts() and interrupts() in tandem to make sure no interrupts
358-
* are occuring while your sketch is doing a particular task. This is only relevant
359-
* when using attachInterrupt(), not for waitForInterrupt(). By default, interrupts
360-
* are enabled.
361294
* @see attachInterrupt
362295
* @see noInterrupts
363296
* @see releaseInterrupt
297+
* @webref
364298
*/
365299
public static void interrupts() {
366300
serveInterrupts = true;
@@ -369,31 +303,24 @@ public static void interrupts() {
369303

370304
/**
371305
* Prevents interrupts from happpening
372-
*
373-
* You can use noInterrupts() and interrupts() in tandem to make sure no interrupts
374-
* are occuring while your sketch is doing a particular task. This is only relevant
375-
* when using attachInterrupt(), not for waitForInterrupt(). By default, interrupts
376-
* are enabled.
377306
* @see attachInterrupt
378307
* @see interrupts
379308
* @see releaseInterrupt
309+
* @webref
380310
*/
381311
public static void noInterrupts() {
382312
serveInterrupts = false;
383313
}
384314

385315

386316
/**
387-
* Sets a pin to INPUT or OUTPUT
388-
*
389-
* While pins are implicitly set to input by default on Arduino, it is
390-
* necessary to call this function for any pin you want to access later,
391-
* including input pins.
317+
* Configures a pin to act either as input or output
392318
* @param pin GPIO pin
393319
* @param mode GPIO.INPUT or GPIO.OUTPUT
394320
* @see digitalRead
395321
* @see digitalWrite
396322
* @see releasePin
323+
* @webref
397324
*/
398325
public static void pinMode(int pin, int mode) {
399326
checkValidPin(pin);
@@ -447,14 +374,12 @@ public static void pinMode(int pin, int mode) {
447374

448375

449376
/**
450-
* Stops listening for interrupts on an INPUT pin
451-
*
452-
* Use this function only in combination with attachInterrupt(). This should
453-
* not be called when enableInterrupt() and waitForInterrupt() are being used.
377+
* Stops listening for interrupts on an input pin
454378
* @param pin GPIO pin
455379
* @see attachInterrupt
456380
* @see noInterrupts
457381
* @see interrupts
382+
* @webref
458383
*/
459384
public static void releaseInterrupt(int pin) {
460385
Thread t = irqThreads.get(pin);
@@ -477,11 +402,9 @@ public static void releaseInterrupt(int pin) {
477402

478403
/**
479404
* Gives ownership of a pin back to the operating system
480-
*
481-
* Without calling this function the pin will remain in the current
482-
* state even after the sketch has been closed.
483405
* @param pin GPIO pin
484406
* @see pinMode
407+
* @webref
485408
*/
486409
public static void releasePin(int pin) {
487410
checkValidPin(pin);
@@ -501,16 +424,31 @@ public static void releasePin(int pin) {
501424

502425

503426
/**
504-
* 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
505442
*
506443
* Make sure to setup the interrupt with enableInterrupt() before calling
507444
* this function. A timeout value of -1 waits indefinitely.
445+
* @param pin GPIO pin
508446
* @param timeout don't wait more than timeout milliseconds
509447
* @return true if the interrupt occured, false if the timeout occured
510448
* @see enableInterrupt
511449
* @see disableInterrupt
512450
*/
513-
public static boolean waitForInterrupt(int pin, int timeout) {
451+
protected static boolean waitForInterrupt(int pin, int timeout) {
514452
checkValidPin(pin);
515453

516454
String fn = String.format("/sys/class/gpio/gpio%d/value", pin);
@@ -531,15 +469,16 @@ public static boolean waitForInterrupt(int pin, int timeout) {
531469

532470

533471
/**
534-
* Waits for the value of an INPUT pin to change
472+
* Waits for the value of an input pin to change
535473
*
536474
* Make sure to setup the interrupt with enableInterrupt() before calling
537475
* this function. This function will wait indefinitely for an interrupt
538476
* to occur.
477+
* @parm pin GPIO pin
539478
* @see enableInterrupt
540479
* @see disableInterrupt
541480
*/
542-
public static void waitForInterrupt(int pin) {
481+
protected static void waitForInterrupt(int pin) {
543482
waitForInterrupt(pin, -1);
544483
}
545484
}

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL