| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
12 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1347,6 +1347,10 @@ remove the spaces for depth since it should be double dash, but screws up commen | |||
| 1347 | 1347 | <include name="antlr/**" /> | |
| 1348 | 1348 | <include name="processing/**" /> | |
| 1349 | 1349 | </packageset> | |
| 1350 | + <packageset dir="../java/libraries/io/src"> | ||
| 1351 | + <include name="antlr/**" /> | ||
| 1352 | + <include name="processing/**" /> | ||
| 1353 | + </packageset> | ||
| 1350 | 1354 | <packageset dir="../java/libraries/net/src"> | |
| 1351 | 1355 | <include name="antlr/**" /> | |
| 1352 | 1356 | <include name="processing/**" /> | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,5 +1,5 @@ | |||
| 1 | 1 | <?xml version="1.0"?> | |
| 2 | - <project name="Processing I/O Library" default="build"> | ||
| 2 | + <project name="Processing Hardware I/O Library" default="build"> | ||
| 3 | 3 | ||
| 4 | 4 | <target name="clean" description="Clean the build directories"> | |
| 5 | 5 | <delete dir="bin" /> | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,2 +1,2 @@ | |||
| 1 | - name = I/O | ||
| 1 | + name = Hardware I/O | ||
| 2 | 2 | version = 1 | |
| Original file line number | Diff line number | Diff 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 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,6 +1,6 @@ | |||
| 1 | 1 | /* | |
| 2 | 2 | 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 | ||
| 4 | 4 | ||
| 5 | 5 | This library is free software; you can redistribute it and/or | |
| 6 | 6 | modify it under the terms of the GNU Lesser General Public | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2,7 +2,7 @@ | |||
| 2 | 2 | ||
| 3 | 3 | /* | |
| 4 | 4 | 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 | ||
| 6 | 6 | ||
| 7 | 7 | This library is free software; you can redistribute it and/or | |
| 8 | 8 | modify it under the terms of the GNU Lesser General Public | |
@@ -31,6 +31,9 @@ | |||
| 31 | 31 | import java.util.Map; | |
| 32 | 32 | ||
| 33 | 33 | ||
| 34 | + /** | ||
| 35 | + * @webref | ||
| 36 | + */ | ||
| 34 | 37 | public class GPIO { | |
| 35 | 38 | ||
| 36 | 39 | // those constants are generally the same as in Arduino.h | |
@@ -43,9 +46,18 @@ public class GPIO { | |||
| 43 | 46 | public static final int HIGH = 1; | |
| 44 | 47 | ||
| 45 | 48 | 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; | ||
| 49 | 61 | ||
| 50 | 62 | protected static Map<Integer, Thread> irqThreads = new HashMap<Integer, Thread>(); | |
| 51 | 63 | protected static boolean serveInterrupts = true; | |
@@ -77,19 +89,15 @@ public static void analogWrite(int pin, int value) { | |||
| 77 | 89 | ||
| 78 | 90 | ||
| 79 | 91 | /** | |
| 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 | ||
| 86 | 93 | * @param pin GPIO pin | |
| 87 | - * @param parent this | ||
| 94 | + * @param parent typically use "this" | ||
| 88 | 95 | * @param method name of sketch method to call | |
| 89 | 96 | * @param mode when to call: GPIO.CHANGE, GPIO.FALLING or GPIO.RISING | |
| 90 | 97 | * @see noInterrupts | |
| 91 | 98 | * @see interrupts | |
| 92 | 99 | * @see releaseInterrupt | |
| 100 | + * @webref | ||
| 93 | 101 | */ | |
| 94 | 102 | public static void attachInterrupt(int pin, PApplet parent, String method, int mode) { | |
| 95 | 103 | if (irqThreads.containsKey(pin)) { | |
@@ -158,63 +166,13 @@ protected static void checkValidPin(int pin) { | |||
| 158 | 166 | } | |
| 159 | 167 | ||
| 160 | 168 | ||
| 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 | - | ||
| 209 | 169 | /** | |
| 210 | 170 | * 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. | ||
| 214 | 171 | * @param pin GPIO pin | |
| 215 | 172 | * @return GPIO.HIGH (1) or GPIO.LOW (0) | |
| 216 | 173 | * @see pinMode | |
| 217 | 174 | * @see digitalWrite | |
| 175 | + * @webref | ||
| 218 | 176 | */ | |
| 219 | 177 | public static int digitalRead(int pin) { | |
| 220 | 178 | checkValidPin(pin); | |
@@ -240,16 +198,12 @@ public static int digitalRead(int pin) { | |||
| 240 | 198 | ||
| 241 | 199 | ||
| 242 | 200 | /** | |
| 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 | ||
| 249 | 202 | * @param pin GPIO pin | |
| 250 | - * @param value GPIO.HIGH or GPIO.LOW | ||
| 203 | + * @param value GPIO.HIGH (1) or GPIO.LOW (0) | ||
| 251 | 204 | * @see pinMode | |
| 252 | 205 | * @see digitalRead | |
| 206 | + * @webref | ||
| 253 | 207 | */ | |
| 254 | 208 | public static void digitalWrite(int pin, int value) { | |
| 255 | 209 | checkValidPin(pin); | |
@@ -279,16 +233,7 @@ public static void digitalWrite(int pin, int value) { | |||
| 279 | 233 | ||
| 280 | 234 | ||
| 281 | 235 | /** | |
| 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 | ||
| 289 | 236 | * @param value true or false | |
| 290 | - * @see pinMode | ||
| 291 | - * @see digitalRead | ||
| 292 | 237 | */ | |
| 293 | 238 | public static void digitalWrite(int pin, boolean value) { | |
| 294 | 239 | if (value) { | |
@@ -300,31 +245,24 @@ public static void digitalWrite(int pin, boolean value) { | |||
| 300 | 245 | ||
| 301 | 246 | ||
| 302 | 247 | /** | |
| 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 | ||
| 308 | 249 | * @param pin GPIO pin | |
| 309 | 250 | * @see enableInterrupt | |
| 310 | 251 | * @see waitForInterrupt | |
| 311 | 252 | */ | |
| 312 | - public static void disableInterrupt(int pin) { | ||
| 253 | + protected static void disableInterrupt(int pin) { | ||
| 313 | 254 | enableInterrupt(pin, NONE); | |
| 314 | 255 | } | |
| 315 | 256 | ||
| 316 | 257 | ||
| 317 | 258 | /** | |
| 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 | ||
| 322 | 260 | * @param pin GPIO pin | |
| 323 | 261 | * @param mode what to wait for: GPIO.CHANGE, GPIO.FALLING or GPIO.RISING | |
| 324 | 262 | * @see waitForInterrupt | |
| 325 | 263 | * @see disableInterrupt | |
| 326 | 264 | */ | |
| 327 | - public static void enableInterrupt(int pin, int mode) { | ||
| 265 | + protected static void enableInterrupt(int pin, int mode) { | ||
| 328 | 266 | checkValidPin(pin); | |
| 329 | 267 | ||
| 330 | 268 | String out; | |
@@ -353,14 +291,10 @@ public static void enableInterrupt(int pin, int mode) { | |||
| 353 | 291 | ||
| 354 | 292 | /** | |
| 355 | 293 | * 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. | ||
| 361 | 294 | * @see attachInterrupt | |
| 362 | 295 | * @see noInterrupts | |
| 363 | 296 | * @see releaseInterrupt | |
| 297 | + * @webref | ||
| 364 | 298 | */ | |
| 365 | 299 | public static void interrupts() { | |
| 366 | 300 | serveInterrupts = true; | |
@@ -369,31 +303,24 @@ public static void interrupts() { | |||
| 369 | 303 | ||
| 370 | 304 | /** | |
| 371 | 305 | * 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. | ||
| 377 | 306 | * @see attachInterrupt | |
| 378 | 307 | * @see interrupts | |
| 379 | 308 | * @see releaseInterrupt | |
| 309 | + * @webref | ||
| 380 | 310 | */ | |
| 381 | 311 | public static void noInterrupts() { | |
| 382 | 312 | serveInterrupts = false; | |
| 383 | 313 | } | |
| 384 | 314 | ||
| 385 | 315 | ||
| 386 | 316 | /** | |
| 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 | ||
| 392 | 318 | * @param pin GPIO pin | |
| 393 | 319 | * @param mode GPIO.INPUT or GPIO.OUTPUT | |
| 394 | 320 | * @see digitalRead | |
| 395 | 321 | * @see digitalWrite | |
| 396 | 322 | * @see releasePin | |
| 323 | + * @webref | ||
| 397 | 324 | */ | |
| 398 | 325 | public static void pinMode(int pin, int mode) { | |
| 399 | 326 | checkValidPin(pin); | |
@@ -447,14 +374,12 @@ public static void pinMode(int pin, int mode) { | |||
| 447 | 374 | ||
| 448 | 375 | ||
| 449 | 376 | /** | |
| 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 | ||
| 454 | 378 | * @param pin GPIO pin | |
| 455 | 379 | * @see attachInterrupt | |
| 456 | 380 | * @see noInterrupts | |
| 457 | 381 | * @see interrupts | |
| 382 | + * @webref | ||
| 458 | 383 | */ | |
| 459 | 384 | public static void releaseInterrupt(int pin) { | |
| 460 | 385 | Thread t = irqThreads.get(pin); | |
@@ -477,11 +402,9 @@ public static void releaseInterrupt(int pin) { | |||
| 477 | 402 | ||
| 478 | 403 | /** | |
| 479 | 404 | * 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. | ||
| 483 | 405 | * @param pin GPIO pin | |
| 484 | 406 | * @see pinMode | |
| 407 | + * @webref | ||
| 485 | 408 | */ | |
| 486 | 409 | public static void releasePin(int pin) { | |
| 487 | 410 | checkValidPin(pin); | |
@@ -501,16 +424,31 @@ public static void releasePin(int pin) { | |||
| 501 | 424 | ||
| 502 | 425 | ||
| 503 | 426 | /** | |
| 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 | ||
| 505 | 442 | * | |
| 506 | 443 | * Make sure to setup the interrupt with enableInterrupt() before calling | |
| 507 | 444 | * this function. A timeout value of -1 waits indefinitely. | |
| 445 | + * @param pin GPIO pin | ||
| 508 | 446 | * @param timeout don't wait more than timeout milliseconds | |
| 509 | 447 | * @return true if the interrupt occured, false if the timeout occured | |
| 510 | 448 | * @see enableInterrupt | |
| 511 | 449 | * @see disableInterrupt | |
| 512 | 450 | */ | |
| 513 | - public static boolean waitForInterrupt(int pin, int timeout) { | ||
| 451 | + protected static boolean waitForInterrupt(int pin, int timeout) { | ||
| 514 | 452 | checkValidPin(pin); | |
| 515 | 453 | ||
| 516 | 454 | String fn = String.format("/sys/class/gpio/gpio%d/value", pin); | |
@@ -531,15 +469,16 @@ public static boolean waitForInterrupt(int pin, int timeout) { | |||
| 531 | 469 | ||
| 532 | 470 | ||
| 533 | 471 | /** | |
| 534 | - * Waits for the value of an INPUT pin to change | ||
| 472 | + * Waits for the value of an input pin to change | ||
| 535 | 473 | * | |
| 536 | 474 | * Make sure to setup the interrupt with enableInterrupt() before calling | |
| 537 | 475 | * this function. This function will wait indefinitely for an interrupt | |
| 538 | 476 | * to occur. | |
| 477 | + * @parm pin GPIO pin | ||
| 539 | 478 | * @see enableInterrupt | |
| 540 | 479 | * @see disableInterrupt | |
| 541 | 480 | */ | |
| 542 | - public static void waitForInterrupt(int pin) { | ||
| 481 | + protected static void waitForInterrupt(int pin) { | ||
| 543 | 482 | waitForInterrupt(pin, -1); | |
| 544 | 483 | } | |
| 545 | 484 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments