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:
This library depends on the wiringPi native system library. (developed by Gordon Henderson @ http://wiringpi.com/)
Modifier and Type | Field and Description |
---|---|
static int |
DIRECTION_HIGH
GPIO PIN DIRECTION
|
static int |
DIRECTION_IN
GPIO PIN DIRECTION
|
static int |
DIRECTION_LOW
GPIO PIN DIRECTION
|
static int |
DIRECTION_OUT
GPIO PIN DIRECTION
|
static int |
EDGE_BOTH
GPIO PIN EDGE DETECTION
|
static int |
EDGE_FALLING
GPIO PIN EDGE DETECTION
|
static int |
EDGE_NONE
GPIO PIN EDGE DETECTION
|
static int |
EDGE_RISING
GPIO PIN EDGE DETECTION
|
Modifier and Type | Method and Description |
---|---|
static void |
export(int pin,
int direction)
This method will export the selected GPIO pin.
|
static int |
getDirection(int pin)
This method will get the selected GPIO pin's export direction.
|
static int |
getEdgeDetection(int pin)
This method will get the selected GPIO pin's edge detection setting.
|
static boolean |
isExported(int pin)
This method determines if the requested GPIO pin is already exported.
|
static int |
isPinSupported(int pin)
This method will return a value of '1' if the pin is supported
|
static boolean |
setDirection(int pin,
int direction)
This method will set the selected GPIO pin's export direction.
|
static boolean |
setEdgeDetection(int pin,
int edge)
This method will set the selected GPIO pin's edge detection.
|
static void |
unexport(int pin)
This method will unexport the selected GPIO pin.
|
public static final int DIRECTION_IN
GPIO PIN DIRECTION
GPIO pin constant for IN direction for reading pin states
public static final int DIRECTION_OUT
GPIO PIN DIRECTION
GPIO pin constant for OUT direction for writing digital pin states (0/1).
public 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).
public 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).
public 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.
setEdgeDetection(int,int)
,
Constant Field Valuespublic 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.
setEdgeDetection(int,int)
,
Constant Field Valuespublic 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.
setEdgeDetection(int,int)
,
Constant Field Valuespublic 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.
setEdgeDetection(int,int)
,
Constant Field Valuespublic static void export(int pin, int direction) throws RuntimeException
This method will export the selected GPIO pin.
This method required root permissions access.
pin
- GPIO pin number (not header pin number; not wiringPi pin number)direction
- pin directionRuntimeException
DIRECTION_IN
,
DIRECTION_OUT
public static void unexport(int pin) throws RuntimeException
This method will unexport the selected GPIO pin.
This method required root permissions access.
pin
- GPIO pin number (not header pin number; not wiringPi pin number)RuntimeException
public static boolean isExported(int pin) throws RuntimeException
This method determines if the requested GPIO pin is already exported.
pin
- GPIO pin number (not header pin number; not wiringPi pin number)RuntimeException
public static boolean setEdgeDetection(int pin, int edge) throws RuntimeException
This 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.
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:
RuntimeException
EDGE_NONE
,
EDGE_BOTH
,
EDGE_RISING
,
EDGE_FALLING
public static int getEdgeDetection(int pin) throws RuntimeException
This method will get the selected GPIO pin's edge detection setting. Edge detection instructs when the hardware GPIO changes raise interrupts on the system.
pin
- GPIO pin number (not header pin number; not wiringPi pin number)RuntimeException
EDGE_NONE
,
EDGE_BOTH
,
EDGE_RISING
,
EDGE_FALLING
public static boolean setDirection(int pin, int direction) throws RuntimeException
This method will set the selected GPIO pin's export direction.
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:
RuntimeException
DIRECTION_IN
,
DIRECTION_OUT
public static int getDirection(int pin) throws RuntimeException
This method will get the selected GPIO pin's export direction.
pin
- GPIO pin number (not header pin number; not wiringPi pin number)RuntimeException
DIRECTION_IN
,
DIRECTION_OUT
public static int isPinSupported(int pin) throws RuntimeException
This method will return a value of '1' if the pin is supported
pin
- pin numberRuntimeException
Copyright © 2012–2019 Pi4J. All rights reserved.