Class GpioUtil
- java.lang.Object
- 
- com.pi4j.wiringpi.GpioUtil
 
- 
 public class GpioUtil extends Object This utility class is provided to export, unexport, and manipulate pin direction. Before using the Pi4J library, you need to ensure that the Java VM in configured with access to the following system libraries: - pi4j
- wiringPi
 This library depends on the wiringPi native system library. (developed by Gordon Henderson @ http://wiringpi.com/) - Author:
- Robert Savage (http://www.savagehomeautomation.com)
- See Also:
- https://pi4j.com/, http://wiringpi.com/
 
- 
- 
Field SummaryFields Modifier and Type Field Description static intDIRECTION_HIGHGPIO PIN DIRECTIONstatic intDIRECTION_INGPIO PIN DIRECTIONstatic intDIRECTION_LOWGPIO PIN DIRECTIONstatic intDIRECTION_OUTGPIO PIN DIRECTIONstatic intEDGE_BOTHGPIO PIN EDGE DETECTIONstatic intEDGE_FALLINGGPIO PIN EDGE DETECTIONstatic intEDGE_NONEGPIO PIN EDGE DETECTIONstatic intEDGE_RISINGGPIO PIN EDGE DETECTION
 - 
Method SummaryAll Methods Static Methods Concrete Methods Modifier and Type Method Description static voidenableNonPrivilegedAccess()This method is used to enable non-privileged access to the GPIO pins on to system.static voidexport(int pin, int direction)This method will export the selected GPIO pin.static intgetDirection(int pin)This method will get the selected GPIO pin's export direction.static intgetEdgeDetection(int pin)This method will get the selected GPIO pin's edge detection setting.static booleanisExported(int pin)This method determines if the requested GPIO pin is already exported.static intisPinSupported(int pin)This method will return a value of '1' if the pin is supportedstatic booleanisPrivilegedAccessRequired()This method will return a value of '1' if Privileged access is required.static booleansetDirection(int pin, int direction)This method will set the selected GPIO pin's export direction.static booleansetEdgeDetection(int pin, int edge)This method will set the selected GPIO pin's edge detection.static voidunexport(int pin)This method will unexport the selected GPIO pin.
 
- 
- 
- 
Field Detail- 
DIRECTION_INpublic static final int DIRECTION_IN GPIO PIN DIRECTION GPIO pin constant for IN direction for reading pin states 
 - 
DIRECTION_OUTpublic static final int DIRECTION_OUT GPIO PIN DIRECTION GPIO pin constant for OUT direction for writing digital pin states (0/1). 
 - 
DIRECTION_HIGHpublic static final int DIRECTION_HIGH GPIO PIN DIRECTION GPIO pin constant for OUT direction with an initial default HIGH value for writing digital pin states (0/1). 
 - 
DIRECTION_LOWpublic static final int DIRECTION_LOW GPIO PIN DIRECTION GPIO pin constant for OUT direction with an initial default LOW value for writing digital pin states (0/1). 
 - 
EDGE_NONEpublic static final int EDGE_NONE GPIO PIN EDGE DETECTION This constant is provided as an edge detection mode for use with the 'edge' method. This constants instructs the edge detection to be disabled. - See Also:
- setEdgeDetection(int,int), Constant Field Values
 
 - 
EDGE_BOTHpublic static final int EDGE_BOTH GPIO PIN EDGE DETECTION This constant is provided as an edge detection mode for use with the 'edge' method. This constants instructs the edge detection to only look for rising and falling pins states; pins changing from LOW to HIGH or HIGH to LOW. - See Also:
- setEdgeDetection(int,int), Constant Field Values
 
 - 
EDGE_RISINGpublic static final int EDGE_RISING GPIO PIN EDGE DETECTION This constant is provided as an edge detection mode for use with the 'edge' method. This constants instructs the edge detection to only look for rising pins states; pins changing from LOW to HIGH. - See Also:
- setEdgeDetection(int,int), Constant Field Values
 
 - 
EDGE_FALLINGpublic static final int EDGE_FALLING GPIO PIN EDGE DETECTION This constant is provided as an edge detection mode for use with the 'edge' method. This constants instructs the edge detection to only look for falling pins states; pins changing from HIGH to LOW. - See Also:
- setEdgeDetection(int,int), Constant Field Values
 
 
- 
 - 
Method Detail- 
exportpublic static void export(int pin, int direction) throws RuntimeExceptionThis method will export the selected GPIO pin. This method required root permissions access. - Parameters:
- pin- GPIO pin number (not header pin number; not wiringPi pin number)
- direction- pin direction
- Throws:
- RuntimeException
- See Also:
- DIRECTION_IN,- DIRECTION_OUT
 
 - 
unexportpublic static void unexport(int pin) throws RuntimeExceptionThis method will unexport the selected GPIO pin. This method required root permissions access. - Parameters:
- pin- GPIO pin number (not header pin number; not wiringPi pin number)
- Throws:
- RuntimeException
 
 - 
isExportedpublic static boolean isExported(int pin) throws RuntimeExceptionThis method determines if the requested GPIO pin is already exported. - Parameters:
- pin- GPIO pin number (not header pin number; not wiringPi pin number)
- Returns:
- A return value of '0' represents that the pin is not exported. A return value of '1' represents that the pin is exported.
- Throws:
- RuntimeException
 
 - 
setEdgeDetectionpublic static boolean setEdgeDetection(int pin, int edge) throws RuntimeExceptionThis method will set the selected GPIO pin's edge detection. Edge detection instructs when the hardware GPIO changes raise interrupts on the system. NOTE: Calling this method will automatically export the pin and set the pin direction to INPUT. This method required root permissions access. - Parameters:
- pin- GPIO pin number (not header pin number; not wiringPi pin number)
- edge- The edge condition to detect: none, rising, falling, or both. The following constants are provided for use with this parameter:- EDGE_NONE
- EDGE_BOTH
- EDGE_RISING
- EDGE_FALLING
 
- Returns:
- A return value of '0' represents success. Errors are returned as negative numbers.
- Throws:
- RuntimeException
- See Also:
- EDGE_NONE,- EDGE_BOTH,- EDGE_RISING,- EDGE_FALLING
 
 - 
getEdgeDetectionpublic static int getEdgeDetection(int pin) throws RuntimeExceptionThis method will get the selected GPIO pin's edge detection setting. Edge detection instructs when the hardware GPIO changes raise interrupts on the system. - Parameters:
- pin- GPIO pin number (not header pin number; not wiringPi pin number)
- Returns:
- The edge condition detected on the selected pin: none, rising, falling, or both.
         The following constants are provided for use with this parameter:
         - EDGE_NONE
- EDGE_BOTH
- EDGE_RISING
- EDGE_FALLING
 
- Throws:
- RuntimeException
- See Also:
- EDGE_NONE,- EDGE_BOTH,- EDGE_RISING,- EDGE_FALLING
 
 - 
setDirectionpublic static boolean setDirection(int pin, int direction) throws RuntimeExceptionThis method will set the selected GPIO pin's export direction. - Parameters:
- pin- GPIO pin number (not header pin number; not wiringPi pin number)
- direction- The export direction to apply: IN, OUT. The following constants are provided for use with this parameter:- DIRECTION_IN
- DIRECTION_OUT
 
- Returns:
- A return value of '0' represents success. Errors are returned as negative numbers.
- Throws:
- RuntimeException
- See Also:
- DIRECTION_IN,- DIRECTION_OUT
 
 - 
getDirectionpublic static int getDirection(int pin) throws RuntimeExceptionThis method will get the selected GPIO pin's export direction. - Parameters:
- pin- GPIO pin number (not header pin number; not wiringPi pin number)
- Returns:
- The GPIO pin's configured export direction is returned: IN (0), OUT (1). The
         following constants are provided for use with this parameter:
         - DIRECTION_IN
- DIRECTION_OUT
 
- Throws:
- RuntimeException
- See Also:
- DIRECTION_IN,- DIRECTION_OUT
 
 - 
isPinSupportedpublic static int isPinSupported(int pin) throws RuntimeExceptionThis method will return a value of '1' if the pin is supported - Parameters:
- pin- pin number
- Returns:
- '1' is the pin is supported, else '0'
- Throws:
- RuntimeException
 
 - 
isPrivilegedAccessRequiredpublic static boolean isPrivilegedAccessRequired() throws RuntimeExceptionThis method will return a value of '1' if Privileged access is required. This method will return a value of '0' if Privileged access is NOT required. Privileged access is required if any of the the following conditions are not met: - You are running with Linux kernel version 4.1.7 or greater - The Device Tree is enabled - The 'bcm2835_gpiomem' kernel module loaded. - Udev rules are configured to permit write access to '/sys/class/gpio/**' - Returns:
- 'true' if privileged access is required; else returns 'false'.
- Throws:
- RuntimeException
 
 - 
enableNonPrivilegedAccesspublic static void enableNonPrivilegedAccess() throws RuntimeExceptionThis method is used to enable non-privileged access to the GPIO pins on to system. This method will throw a runtime exception if privileged access is required. You can test for required access using the 'isPrivilegedAccessRequired()' method. Please note when non-privileged access is enabled, you will not be able to use any hardware PWM or CLOCK functions. - Throws:
- RuntimeException
 
 
- 
 
-