001package com.pi4j.wiringpi; 002 003/* 004 * #%L 005 * ********************************************************************** 006 * ORGANIZATION : Pi4J 007 * PROJECT : Pi4J :: Java Library (Core) 008 * FILENAME : Gpio.java 009 * 010 * This file is part of the Pi4J project. More information about 011 * this project can be found here: http://www.pi4j.com/ 012 * ********************************************************************** 013 * %% 014 * Copyright (C) 2012 - 2015 Pi4J 015 * %% 016 * This program is free software: you can redistribute it and/or modify 017 * it under the terms of the GNU Lesser General Public License as 018 * published by the Free Software Foundation, either version 3 of the 019 * License, or (at your option) any later version. 020 * 021 * This program is distributed in the hope that it will be useful, 022 * but WITHOUT ANY WARRANTY; without even the implied warranty of 023 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 024 * GNU General Lesser Public License for more details. 025 * 026 * You should have received a copy of the GNU General Lesser Public 027 * License along with this program. If not, see 028 * <http://www.gnu.org/licenses/lgpl-3.0.html>. 029 * #L% 030 */ 031 032 033import com.pi4j.util.NativeLibraryLoader; 034 035/** 036 * <[>WiringPi GPIO Control</[> 037 * 038 * <p> 039 * Some of the functions in the WiringPi library are designed to mimic those in the Arduino Wiring 040 * system. There are relatively easy to use and should present no problems for anyone used to the 041 * Arduino system, or C programming in-general. 042 * </p> 043 * 044 * <p> 045 * The main difference is that unlike the Arduino system, the main loop of the program is not 046 * provided for you and you need to write it yourself. This is often desirable in a Linux system 047 * anyway as it can give you access to command-line arguments and so on. See the examples page for 048 * some simple examples and a Makefile to use. 049 * </p> 050 * 051 * <p> 052 * Before using the Pi4J library, you need to ensure that the Java VM in configured with access to 053 * the following system libraries: 054 * <ul> 055 * <li>pi4j</li> 056 * <li>wiringPi</li> 057 * </ul> 058 * <blockquote> This library depends on the wiringPi native system library.</br> (developed by 059 * Gordon Henderson @ <a href="http://wiringpi.com/">http://wiringpi.com/</a>) 060 * </blockquote> 061 * </p> 062 * 063 * @see <a href="http://www.pi4j.com/">http://www.pi4j.com/</a> 064 * @see <a 065 * href="http://wiringpi.com/reference/">http://wiringpi.com/reference/</a> 066 * @author Robert Savage (<a 067 * href="http://www.savagehomeautomation.com">http://www.savagehomeautomation.com</a>) 068 */ 069public class Gpio { 070 071 // private constructor 072 private Gpio() { 073 // forbid object construction 074 } 075 076 /** 077 * The total number of GPIO pins available in the WiringPi library. 078 * <i>(Note this is not the maximum pin count on the Pi GPIO header.)</i> 079 */ 080 public static final int NUM_PINS = 46; 081 082 /** 083 * GPIO pin constant for INPUT direction for reading pin states 084 * 085 * @see #pinMode(int,int) 086 */ 087 public static final int INPUT = 0; 088 089 /** 090 * GPIO pin constant for OUTPUT direction for writing digital pin states (0/1) 091 * 092 * @see #pinMode(int,int) 093 */ 094 public static final int OUTPUT = 1; 095 096 /** 097 * GPIO pin constant for PWM_OUTPUT direction for writing analog pin states 098 * 099 * @see #pinMode(int,int) 100 */ 101 public static final int PWM_OUTPUT = 2; 102 103 /** 104 * GPIO pin constant for GPIO_CLOCK pin mode 105 * 106 * @see #pinMode(int,int) 107 */ 108 public static final int GPIO_CLOCK = 3; 109 110 /** 111 * GPIO pin state constant for LOW/OFF/0VDC 112 * 113 * @see #digitalWrite(int,int) 114 */ 115 public static final int LOW = 0; 116 117 /** 118 * GPIO pin state constant for HIGH/ON/+3.3VDC 119 * 120 * @see #digitalWrite(int,int) 121 */ 122 public static final int HIGH = 1; 123 124 /** 125 * GPIO constant to disable the pull-up or pull-down resistor mode on a GPIO pin. 126 * 127 * @see #waitForInterrupt(int,int) 128 */ 129 public static final int PUD_OFF = 0; 130 131 /** 132 * GPIO constant to enable the pull-down resistor mode on a GPIO pin. 133 * 134 * @see #waitForInterrupt(int,int) 135 */ 136 public static final int PUD_DOWN = 1; 137 138 /** 139 * GPIO constant to enable the pull-up resistor mode on a GPIO pin. 140 * 141 * @see #waitForInterrupt(int,int) 142 */ 143 public static final int PUD_UP = 2; 144 145 146 /** 147 * GPIO constant to define PWM balanced mode. 148 * 149 * @see #pwmSetMode(int) 150 */ 151 public static final int PWM_MODE_BAL = 1; 152 153 154 /** 155 * GPIO constant to define PWM mark:space mode. 156 * 157 * @see #pwmSetMode(int) 158 */ 159 public static final int PWM_MODE_MS = 0; 160 161 162 /** 163 * GPIO constants to define interrupt levels 164 * 165 * @see #wiringPiISR(int,int,com.pi4j.wiringpi.GpioInterruptCallback) 166 */ 167 public static final int INT_EDGE_SETUP = 0; 168 public static final int INT_EDGE_FALLING = 1; 169 public static final int INT_EDGE_RISING = 2; 170 public static final int INT_EDGE_BOTH = 3; 171 172 static { 173 // Load the platform library 174 NativeLibraryLoader.load("libpi4j.so"); 175 } 176 177 /** 178 * <p>Setup Functions</p> 179 * 180 * <p> 181 * This initializes the wiringPi system and assumes that the calling program is going to be 182 * using the wiringPi pin numbering scheme. This is a simplified numbering scheme which provides 183 * a mapping from virtual pin numbers 0 through 16 to the real underlying Broadcom GPIO pin 184 * numbers. See the pins page for a table which maps the wiringPi pin number to the Broadcom 185 * GPIO pin number to the physical location on the edge connector. 186 * </p> 187 * 188 * <p><b><i>This function needs to be called with root privileges.</i></b></p> 189 * 190 * @see <a 191 * href="http://wiringpi.com/reference/setup/">http://wiringpi.com/reference/setup/</a> 192 * @return If this function returns a value of '-1' then an error has occurred and the 193 * initialization of the GPIO has failed. A return value of '0' indicates a successful 194 * GPIO initialization. 195 */ 196 public static native int wiringPiSetup(); 197 198 /** 199 * <p>Setup Functions</p> 200 * 201 * <p> 202 * This initializes the wiringPi system but uses the /sys/class/gpio interface rather than 203 * accessing the hardware directly. This can be called as a non-root user provided the GPIO pins 204 * have been exported before-hand using the gpio program. Pin number in this mode is the native 205 * Broadcom GPIO numbers. 206 * </p> 207 * 208 * <p> 209 * <ul> 210 * Note: 211 * </ul> 212 * In this mode you can only use the pins which have been exported via the /sys/class/gpio 213 * interface. You must export these pins before you call your program. You can do this in a 214 * separate shell-script, or by using the system() function from inside your program. 215 * </p> 216 * 217 * <p> 218 * <b><i>Also note that some functions (noted below) have no effect when using this mode as 219 * they're not currently possible to action unless called with root privileges.</i></b> 220 * </p> 221 * 222 * @see <a 223 * href="http://wiringpi.com/reference/setup/">http://wiringpi.com/reference/setup/</a> 224 * @return If this function returns a value of '-1' then an error has occurred and the 225 * initialization of the GPIO has failed. A return value of '0' indicates a successful 226 * GPIO initialization. 227 */ 228 public static native int wiringPiSetupSys(); 229 230 /** 231 * <p>Setup Functions</p> 232 * 233 * <p> 234 * This setup function is identical to wiringPiSetup(), however it allows the calling programs 235 * to use the Broadcom GPIO pin numbers directly with no re-mapping. 236 * </p> 237 * 238 * <p> <b><i>This function needs to be called with root privileges.</i></b></p> 239 * 240 * @see <a 241 * href="http://wiringpi.com/reference/setup/">http://wiringpi.com/reference/setup/</a> 242 * @return If this function returns a value of '-1' then an error has occurred and the 243 * initialization of the GPIO has failed. A return value of '0' indicates a successful 244 * GPIO initialization. 245 */ 246 public static native int wiringPiSetupGpio(); 247 248 249 /** 250 * <p>Setup Functions</p> 251 * 252 * <p> 253 * This setup function is identical to wiringPiSetup(), however it allows the calling programs 254 * to use the physical header pin numbers on the board GPIO header. 255 * </p> 256 * 257 * <p> <b><i>This function needs to be called with root privileges.</i></b></p> 258 * 259 * @see <a 260 * href="http://wiringpi.com/reference/setup/">http://wiringpi.com/reference/setup/</a> 261 * @return If this function returns a value of '-1' then an error has occurred and the 262 * initialization of the GPIO has failed. A return value of '0' indicates a successful 263 * GPIO initialization. 264 */ 265 public static native int wiringPiSetupPhys(); 266 267 268 /** 269 * <p>Core Functions</p> 270 * 271 * <p> 272 * This sets the mode of a pin to either INPUT, OUTPUT, PWM_OUTPUT or GPIO_CLOCK. Note that only wiringPi pin 1 273 * (BCM_GPIO 18) supports PWM output and only wiringPi pin 7 (BCM_GPIO 4) supports CLOCK output modes. 274 * </p> 275 * 276 * <p> <b><i>This function has no effect when in Sys mode.</i></b></p> 277 * 278 * @see #INPUT 279 * @see #OUTPUT 280 * @see #PWM_OUTPUT 281 * @see <a 282 * href="http://wiringpi.com/reference/core-functions/">http://wiringpi.com/reference/core-functions/</a> 283 * @param pin The GPIO pin number. </br><i>(Depending on how wiringPi was initialized, this may 284 * be the wiringPi pin number, the Broadcom GPIO pin number, or the board header pin number.)</i> 285 * @param mode Pin mode/direction to apply to the selected pin.</br>The following constants are 286 * provided for use with this parameter: 287 * <ul> 288 * <li>INPUT</li> 289 * <li>OUTPUT</li> 290 * <li>PWM_OUTPUT</li> 291 * <li>GPIO_CLOCK</li> 292 * </ul> 293 */ 294 public static native void pinMode(int pin, int mode); 295 296 297 /** 298 * <p>Core Functions</p> 299 * 300 * This sets the pull-up or pull-down resistor mode on the given pin, which should be set as an 301 * input. Unlike the Arduino, the BCM2835 has both pull-up an down internal resistors. The 302 * parameter pud should be; PUD_OFF, (no pull up/down), PUD_DOWN (pull to ground) or PUD_UP 303 * (pull to 3.3v) 304 * 305 * This function has no effect when in Sys mode (see above) If you need to activate a 306 * pull-up/pull-down, then you can do it with the gpio program in a script before you start your 307 * program. 308 * 309 * @see #PUD_OFF 310 * @see #PUD_DOWN 311 * @see #PUD_UP 312 * @see <a 313 * href="http://wiringpi.com/reference/core-functions/">http://wiringpi.com/reference/core-functions/</a> 314 * @param pin The GPIO pin number. </br><i>(Depending on how wiringPi was initialized, this may 315 * be the wiringPi pin number or the Broadcom GPIO pin number.)</i> 316 * @param pud Pull Up/Down internal pin resistance.</br>The following constants are provided for 317 * use with this parameter: 318 * <ul> 319 * <li>PUD_OFF</li> 320 * <li>PUD_DOWN</li> 321 * <li>PUD_UP</li> 322 * </ul> 323 */ 324 public static native void pullUpDnControl(int pin, int pud); 325 326 327 /** 328 * <p>Core Functions</p> 329 * 330 * <p> 331 * Writes the value HIGH or LOW (1 or 0) to the given pin which must have been previously set as 332 * an output. WiringPi treats any non-zero number as HIGH, however 0 is the only representation of LOW. 333 * </p> 334 * 335 * @see #HIGH 336 * @see #LOW 337 * @see <a 338 * href="http://wiringpi.com/reference/core-functions/">http://wiringpi.com/reference/core-functions/</a> 339 * @param pin The GPIO pin number. </br><i>(Depending on how wiringPi was initialized, this may 340 * be the wiringPi pin number or the Broadcom GPIO pin number.)</i> 341 * @param value The pin state to write to the selected pin.</br>The following constants are 342 * provided for use with this parameter: 343 * <ul> 344 * <li>HIGH</li> 345 * <li>LOW</li> 346 * </ul> 347 */ 348 public static native void digitalWrite(int pin, int value); 349 350 351 /** 352 * <p>Core Functions</p> 353 * 354 * <p> 355 * Writes the value HIGH or LOW ('true' or 'false') to the given pin which must have been 356 * previously set as an output. 357 * </p> 358 * 359 * @see <a 360 * href="http://wiringpi.com/reference/core-functions/">http://wiringpi.com/reference/core-functions/</a> 361 * @param pin The GPIO pin number. </br><i>(Depending on how wiringPi was initialized, this may 362 * be the wiringPi pin number or the Broadcom GPIO pin number.)</i> 363 * @param value The pin boolean state to write to the selected pin. 364 */ 365 public static void digitalWrite(int pin, boolean value) { 366 digitalWrite(pin, (value) ? 1 : 0); 367 } 368 369 370 /** 371 * <p>Core Functions</p> 372 * 373 * <p> 374 * Writes the value to the PWM register for the given pin. The value must be between 0 and 1024. 375 * (Again, note that only pin 1 supports PWM: ) 376 * </p> 377 * 378 * <p><b>This function has no effect when in Sys mode</b></p> 379 * 380 * @see <a 381 * href="http://wiringpi.com/reference/core-functions/">http://wiringpi.com/reference/core-functions/</a> 382 * @param pin The GPIO pin number. </br><i>(Depending on how wiringPi was initialized, this may 383 * be the wiringPi pin number or the Broadcom GPIO pin number.)</i> 384 * @param value The analog value to write to the selected pin. </br><i>(The value must be between 385 * 0 and 1024.)</i> 386 */ 387 public static native void pwmWrite(int pin, int value); 388 389 390 /** 391 * <p>Core Functions</p> 392 * 393 * <p> 394 * This function returns the value read at the given pin. It will be HIGH or LOW (1 or 0) 395 * depending on the logic level at the pin. 396 * </p> 397 * 398 * @see <a 399 * href="http://wiringpi.com/reference/core-functions/">http://wiringpi.com/reference/core-functions/</a> 400 * @param pin The GPIO pin number. </br><i>(Depending on how wiringPi was initialized, this may 401 * be the wiringPi pin number or the Broadcom GPIO pin number.)</i> 402 * @return If the selected GPIO pin is HIGH, then a value of '1' is returned; else of the pin is 403 * LOW, then a value of '0' is returned. 404 */ 405 public static native int digitalRead(int pin); 406 407 408 /** 409 * <p>Core Functions</p> 410 * 411 * <p> 412 * This returns the value read on the supplied analog input pin. You will need to register additional analog 413 * modules to enable this function for devices such as the Gertboard, quick2Wire analog board, etc. 414 * </p> 415 * 416 * @see <a 417 * href="http://wiringpi.com/reference/core-functions/">http://wiringpi.com/reference/core-functions/</a> 418 * @param pin The GPIO pin number. </br><i>(Depending on how wiringPi was initialized, this may 419 * be the wiringPi pin number or the Broadcom GPIO pin number.)</i> 420 * @return Analog value of selected pin. 421 */ 422 public static native int analogRead(int pin); 423 424 425 /** 426 * <p>Core Functions</p> 427 * 428 * <p> 429 * This writes the given value to the supplied analog pin. You will need to register additional analog modules to 430 * enable this function for devices such as the Gertboard. 431 * </p> 432 * 433 * @see <a 434 * href="http://wiringpi.com/reference/core-functions/">http://wiringpi.com/reference/core-functions/</a> 435 * @param pin The GPIO pin number. </br><i>(Depending on how wiringPi was initialized, this may 436 * be the wiringPi pin number or the Broadcom GPIO pin number.)</i> 437 * @param value The analog value to assign to the selected pin number. 438 */ 439 public static native void analogWrite(int pin, int value); 440 441 442 /** 443 * <p>Timing Functions</p> 444 * 445 * <p> 446 * This causes program execution to pause for at least howLong milliseconds. Due to the 447 * multi-tasking nature of Linux it could be longer. Note that the maximum delay is an unsigned 448 * 32-bit integer or approximately 49 days. 449 * </p> 450 * 451 * @see <a 452 * href="http://wiringpi.com/reference/timing/">http://wiringpi.com/reference/timing/</a> 453 * @param howLong The number of milliseconds to delay the main program thread. 454 */ 455 public static native void delay(long howLong); 456 457 458 /** 459 * <p>Timing Functions</p> 460 * 461 * <p> 462 * This returns a number representing the number if milliseconds since your program called one 463 * of the wiringPiSetup functions. It returns an unsigned 32-bit number which wraps after 49 464 * days. 465 * </p> 466 * 467 * @see <a 468 * href="http://wiringpi.com/reference/timing/">http://wiringpi.com/reference/timing/</a> 469 * @return The number if milliseconds since the program called one of the wiringPi setup 470 * functions. 471 */ 472 public static native long millis(); 473 474 475 /** 476 * <p>Timing Functions</p> 477 * 478 * <p> 479 * This returns a number representing the number of microseconds since your program called one of the 480 * wiringPiSetup functions. It returns an unsigned 32-bit number which wraps after approximately 71 minutes. 481 * </p> 482 * 483 * @see <a 484 * href="http://wiringpi.com/reference/timing/">http://wiringpi.com/reference/timing/</a> 485 * @return The number if microseconds since the program called one of the wiringPi setup 486 * functions. 487 */ 488 public static native long micros(); 489 490 491 /** 492 * <p>Timing Functions</p> 493 * 494 * <p> 495 * This causes program execution to pause for at least howLong microseconds. Due to the 496 * multi-tasking nature of Linux it could be longer. Note that the maximum delay is an unsigned 497 * 32-bit integer microseconds or approximately 71 minutes. 498 * 499 * Delays under 100 microseconds are timed using a hard-coded loop continually polling the system time, 500 * Delays over 100 microseconds are done using the system nanosleep() function – You may need to consider 501 * the implications of very short delays on the overall performance of the system, especially if using 502 * threads. 503 * </p> 504 * 505 * @see <a 506 * href="http://wiringpi.com/reference/timing/">http://wiringpi.com/reference/timing/</a> 507 * @param howLong The number of microseconds to delay the main program thread. 508 */ 509 public static native void delayMicroseconds(long howLong); 510 511 512 /** 513 * <p>Priority, Interrupt and Thread Functions</p> 514 * 515 * <p> 516 * This attempts to shift your program (or thread in a multi-threaded program) to a higher 517 * priority and enables a real-time scheduling. The priority parameter should be from 0 (the 518 * Default) to 99 (the maximum). This won't make your program go any faster, but it will give it 519 * a bigger slice of time when other programs are running. The priority parameter works relative 520 * to others and so you can make one program priority 1 and another priority 2 and it will have 521 * the same effect as setting one to 10 and the other to 90 (as long as no other programs are 522 * running with elevated priorities) 523 * </p> 524 * 525 * <p> 526 * The return value is 0 for success and -1 for error. If an error is returned, the program 527 * should then consult the errno global variable, as per the usual conventions. 528 * </p> 529 * 530 * <p> 531 * Note: Only programs running as root can change their priority. If called from a non-root 532 * program then nothing happens. 533 * </p> 534 * 535 * @see <a 536 * href="http://wiringpi.com/reference/priority-interrupts-and-threads/">http://wiringpi.com/reference/priority-interrupts-and-threads/</a> 537 * @param priority The priority parameter should be from 0 (the Default) to 99 (the maximum) 538 * @return The return value is 0 for success and -1 for error. If an error is returned, the 539 * program should then consult the errno global variable, as per the usual conventions. 540 */ 541 public static native int piHiPri(int priority); 542 543 544 /** 545 * <p>Priority, Interrupt and Thread Functions</p> 546 * 547 * <p> 548 * With a newer kernel patched with the GPIO interrupt handling code, you can now wait for an 549 * interrupt in your program. This frees up the processor to do other tasks while you're waiting 550 * for that interrupt. The GPIO can be set to interrupt on a rising, falling or both edges of 551 * the incoming signal. 552 * </p> 553 * <p> <b> int waitForInterrupt (int pin, int timeOut) </b> </p> 554 * 555 * <p> 556 * When called, it will wait for an interrupt event to happen on that pin and your program will 557 * be stalled. The timeOut parameter is given in milliseconds, or can be -1 which means to wait 558 * forever. 559 * </p> 560 * 561 * <p> 562 * Before you call waitForInterrupt, you must first initialize the GPIO pin and at present the 563 * only way to do this is to use the gpio program, either in a script, or using the system() 564 * call from inside your program. 565 * </p> 566 * 567 * <p> 568 * e.g. We want to wait for a falling-edge interrupt on GPIO pin 0, so to setup the hardware, we 569 * need to run: 570 * 571 * <pre> 572 * gpio edge 0 falling 573 * </pre> 574 * 575 * </p> 576 * 577 * @deprecated Note: Jan 2013: The waitForInterrupt() function is deprecated – you should use the newer 578 * and easier to use wiringPiISR() function. 579 * 580 * @see <a 581 * href="http://wiringpi.com/reference/priority-interrupts-and-threads/">http://wiringpi.com/reference/priority-interrupts-and-threads/</a> 582 * @param pin The GPIO pin number. </br><i>(Depending on how wiringPi was initialized, this may 583 * be the wiringPi pin number or the Broadcom GPIO pin number.)</i> 584 * @param timeout The number of milliseconds to wait before timing out. </br>A value of '-1' will 585 * disable the timeout. 586 * @return The return value is -1 if an error occurred (and errno will be set appropriately), 0 587 * if it timed out, or 1 on a successful interrupt event. 588 */ 589 public static native int waitForInterrupt(int pin, int timeout); 590 591 592 /** 593 * <p>Priority, Interrupt and Thread Functions</p> 594 * 595 * <p> 596 * This function registers a function to received interrupts on the specified pin. The edgeType parameter is either 597 * INT_EDGE_FALLING, INT_EDGE_RISING, INT_EDGE_BOTH or INT_EDGE_SETUP. If it is INT_EDGE_SETUP then no 598 * initialisation of the pin will happen – it’s assumed that you have already setup the pin elsewhere 599 * (e.g. with the gpio program), but if you specify one of the other types, then the pin will be exported and 600 * initialised as specified. This is accomplished via a suitable call to the gpio utility program, so it need to 601 * be available 602 * </p> 603 * 604 * <p> 605 * The pin number is supplied in the current mode – native wiringPi, BCM_GPIO, physical or Sys modes. 606 * </p> 607 * 608 * <p> 609 * This function will work in any mode, and does not need root privileges to work. 610 * </p> 611 * 612 * <p> 613 * The function will be called when the interrupt triggers. When it is triggered, it’s cleared in the dispatcher 614 * before calling your function, so if a subsequent interrupt fires before you finish your handler, then it won’t 615 * be missed. (However it can only track one more interrupt, if more than one interrupt fires while one is being 616 * handled then they will be ignored) 617 * </p> 618 * 619 * <p> 620 * This function is run at a high priority (if the program is run using sudo, or as root) and executes 621 * concurrently with the main program. It has full access to all the global variables, open file handles 622 * and so on. 623 * </p> 624 * 625 * @see <a 626 * href="http://wiringpi.com/reference/priority-interrupts-and-threads/">http://wiringpi.com/reference/priority-interrupts-and-threads/</a> 627 * @param pin The GPIO pin number. </br><i>(Depending on how wiringPi was initialized, this may 628 * be the wiringPi pin number or the Broadcom GPIO pin number.)</i> 629 * @param edgeType The type of pin edge event to watch for: INT_EDGE_FALLING, INT_EDGE_RISING, INT_EDGE_BOTH or INT_EDGE_SETUP. 630 * @return The return value is -1 if an error occurred (and errno will be set appropriately), 0 631 * if it timed out, or 1 on a successful interrupt event. 632 */ 633 public static native int wiringPiISR(int pin, int edgeType, GpioInterruptCallback callback); 634 635 636 // /** 637 // * -------------------------------------------------------------------------------------------- 638 // * lets not use native code for threading in Java; that could get you into some trouble. 639 // * -------------------------------------------------------------------------------------------- 640 // * <h1>Concurrent Processing (multi-threading)</h1> 641 // * 642 // * wiringPi has a simplified interface to the Linux implementation of Posix threads, as well as 643 // * a (simplified) mechanisms to access mutexs (Mutual exclusions) 644 // * 645 // * Using these functions you can create a new process (a function inside your main program) 646 // * which runs concurrently with your main program and using the mutex mechanisms, safely pass 647 // * variables between them. 648 // * 649 // * @see <a 650 // * href="http://wiringpi.com/reference/priority-interrupts-and-threads/">http://wiringpi.com/reference/priority-interrupts-and-threads/</a> 651 // */ 652 // public static native int piThreadCreate(void fn, int timeout); 653 // public static native void piLock(int key); 654 // public static native void piUnlock(int key); 655 656 657 /** 658 * <p>[Hardware]</p> 659 * 660 * <p> This method provides the board revision as determined by the wiringPi library. </p> 661 * 662 * @see <a 663 * href="http://wiringpi.com/reference/raspberry-pi-specifics/">http://wiringpi.com/reference/raspberry-pi-specifics/</a> 664 * @return The return value represents the major board revision version. 665 * A -1 will be returned if the board revision cannot be determined. 666 */ 667 public static native int piBoardRev(); 668 669 670 /** 671 * <p>[Hardware]</p> 672 * 673 * <p> This method provides the edge GPIO pin number for the requested wiringPi pin number. </p> 674 * 675 * @see <a 676 * href="http://wiringpi.com/reference/raspberry-pi-specifics/">http://wiringpi.com/reference/raspberry-pi-specifics/</a> 677 * @return The return value represents the RaspberryPi GPIO (edge) pin number. 678 * A -1 will be returned for an invalid pin number. 679 */ 680 public static native int wpiPinToGpio(int wpiPin); 681 682 683 /** 684 * <p>[Hardware]</p> 685 * 686 * <p> This returns the BCM_GPIO pin number of the supplied physical pin on the board header connector. </p> 687 * 688 * @see <a 689 * href="http://wiringpi.com/reference/raspberry-pi-specifics/">http://wiringpi.com/reference/raspberry-pi-specifics/</a> 690 * @return The return value represents the RaspberryPi GPIO (edge) pin number. 691 * A -1 will be returned for an invalid pin number. 692 */ 693 public static native int physPinToGpio(int physPin); 694 695 696 /** 697 * <p> This writes the 8-bit byte supplied to the first 8 GPIO pins. It’s the fastest way to set all 8 bits at once to a particular value, 698 * although it still takes two write operations to the Pi’s GPIO hardware. </p> 699 * 700 * @see <a 701 * href="http://wiringpi.com/reference/raspberry-pi-specifics/">http://wiringpi.com/reference/raspberry-pi-specifics/</a> 702 */ 703 public static native void digitalWriteByte(int value); 704 705 706 /** 707 * <p>[PWM]</p> 708 * 709 * <p> The PWM generator can run in 2 modes – “balanced” and “mark:space”. The mark:space mode is traditional, however 710 * the default mode in the Pi is “balanced”. You can switch modes by supplying the parameter: PWM_MODE_BAL or PWM_MODE_MS.</p> 711 * 712 * @see <a 713 * href="http://wiringpi.com/reference/raspberry-pi-specifics/">http://wiringpi.com/reference/raspberry-pi-specifics/</a> 714 */ 715 public static native void pwmSetMode(int mode); 716 717 718 /** 719 * <p>[PWM]</p> 720 * 721 * <p> This sets the range register in the PWM generator. The default is 1024.</p> 722 * 723 * @see <a 724 * href="http://wiringpi.com/reference/raspberry-pi-specifics/">http://wiringpi.com/reference/raspberry-pi-specifics/</a> 725 */ 726 public static native void pwmSetRange(int range); 727 728 729 /** 730 * <p>[PWM]</p> 731 * 732 * <p> This sets the divisor for the PWM clock.</p> 733 * 734 * @see <a 735 * href="http://wiringpi.com/reference/raspberry-pi-specifics/">http://wiringpi.com/reference/raspberry-pi-specifics/</a> 736 */ 737 public static native void pwmSetClock(int divisor); 738 739 740 /** 741 * <p>[Hardware]</p> 742 * 743 * <p> This sets the “strength” of the pad drivers for a particular group of pins. There are 3 groups of pins and the drive strength is from 0 to 7. Do not use this unless you know what you are doing. </p> 744 * 745 * @see <a 746 * href="http://wiringpi.com/reference/raspberry-pi-specifics/">http://wiringpi.com/reference/raspberry-pi-specifics/</a> 747 */ 748 public static native void setPadDrive(int group, int value); 749 750 751 /** 752 * <p>[Hardware]</p> 753 * 754 * <p> This gets the ALT function level of the requested pin number </p> 755 * 756 * @see <a 757 * href="http://wiringpi.com/reference/raspberry-pi-specifics/">http://wiringpi.com/reference/raspberry-pi-specifics/</a> 758 */ 759 public static native int getAlt(int pin); 760 761 762 /** 763 * <p>[Hardware]</p> 764 * 765 * <p> This sets the “frequency” of a GPIO pin </p> 766 * 767 * @see <a 768 * href="http://wiringpi.com/reference/raspberry-pi-specifics/">http://wiringpi.com/reference/raspberry-pi-specifics/</a> 769 */ 770 public static native void gpioClockSet(int pin, int frequency); 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 // private static class Hook extends Thread 789 // { 790 // File libfile; 791 // 792 // public Hook(File libfile) 793 // { 794 // this.libfile = libfile; 795 // } 796 // public void run() 797 // { 798 // if(libfile.exists()) 799 // libfile.deleteOnExit() 800 // System.out.println( "Running Clean Up..." ); 801 // } 802 // } 803}