Modifier and Type | Field and Description |
---|---|
static int |
INPUT
Input port direction.
|
static int |
OUTPUT
Output port direction.
|
BIG_ENDIAN, LITTLE_ENDIAN, MIXED_ENDIAN
Modifier and Type | Method and Description |
---|---|
int |
getDirection()
Returns the current direction of this GPIO pin.
|
int |
getTrigger()
Returns the current pin interrupt trigger.
|
boolean |
getValue()
Returns the current value of this GPIO pin.
|
void |
setDirection(int direction)
Sets this GPIO pin for output or input.
|
void |
setInputListener(PinListener listener)
Registers a
PinListener instance which will get asynchronously notified when this
GPIO pin's value changes and according to the current trigger mode (see getTrigger ). |
void |
setTrigger(int trigger)
Sets this GPIO pin trigger mode.
|
void |
setValue(boolean value)
Sets the value of this GPIO pin.
|
static final int INPUT
static final int OUTPUT
int getDirection() throws IOException, UnavailableDeviceException, ClosedDeviceException
setDirection
the device configuration-specific default value is
returned.OUTPUT
if this GPIO pin is currently set as output;
INPUT
otherwise (the GPIO pin is set as input).IOException
- if some other I/O error occurs.UnavailableDeviceException
- if this device is not currently available - such as it is locked by another
application.ClosedDeviceException
- if the device has been closed.int getTrigger() throws IOException, UnavailableDeviceException, ClosedDeviceException
setTrigger
the device configuration-specific default value is
returned. Setting the trigger mode to GPIOPinConfig.TRIGGER_NONE
disables
the notification of the PinListener
instance (see setInputListener
without unregistering it. The value returned by this
method is unaffected by changes of the direction on a bidirectional GPIO pin.GPIOPinConfig.TRIGGER_NONE
,
GPIOPinConfig.TRIGGER_FALLING_EDGE
, GPIOPinConfig.TRIGGER_RISING_EDGE
, GPIOPinConfig.TRIGGER_BOTH_EDGES
, GPIOPinConfig.TRIGGER_HIGH_LEVEL
,
GPIOPinConfig.TRIGGER_LOW_LEVEL
, GPIOPinConfig.TRIGGER_BOTH_LEVELS
;
GPIOPinConfig.TRIGGER_NONE
if this GPIO pin is configured for output-only.IOException
- if some other I/O error occurs.UnavailableDeviceException
- if this device is not currently available - such as it is locked by another
application.ClosedDeviceException
- if the device has been closed.boolean getValue() throws IOException, UnavailableDeviceException, ClosedDeviceException
setValue
the device configuration-specific default value is returned.
This method can be called on both output and input pins.
IOException
- if an I/O error occurred such as the pin is not readable.UnavailableDeviceException
- if this device is not currently available - such as it is locked by another
application.ClosedDeviceException
- if the device has been closed.void setDirection(int direction) throws IOException, UnsupportedOperationException, IllegalArgumentException, UnavailableDeviceException, ClosedDeviceException
INPUT
if the GPIO pin is configured for input-only (see GPIOPinConfig.DIR_INPUT_ONLY
)
or is configured as bidirectional (see GPIOPinConfig.DIR_BOTH_INIT_INPUT
and GPIOPinConfig.DIR_BOTH_INIT_OUTPUT
).
The direction can only be set to OUTPUT
if the GPIO pin is configured for output-only (see GPIOPinConfig.DIR_OUTPUT_ONLY
)
or is configured as bidirectional (see GPIOPinConfig.DIR_BOTH_INIT_INPUT
and GPIOPinConfig.DIR_BOTH_INIT_OUTPUT
).
The value returned by getTrigger
is unaffected by changes of the direction on a bidirectional GPIO pin.direction
- OUTPUT
for output; INPUT
for input.IOException
- if some other I/O error occurs.UnsupportedOperationException
- if this GPIO pin cannot be configured for the desired direction.IllegalArgumentException
- if direction
is not equal to OUTPUT
or
INPUT
.UnavailableDeviceException
- if this device is not currently available - such as it is locked by another
application.ClosedDeviceException
- if the device has been closed.void setTrigger(int trigger) throws IOException, UnsupportedOperationException, IllegalArgumentException, UnavailableDeviceException, ClosedDeviceException
GPIOPinConfig.TRIGGER_NONE
disables
the notification of the PinListener
instance (see setInputListener
without unregistering it.trigger
- the interrupt trigger events, one of: GPIOPinConfig.TRIGGER_NONE
,
GPIOPinConfig.TRIGGER_FALLING_EDGE
,
GPIOPinConfig.TRIGGER_RISING_EDGE
,
GPIOPinConfig.TRIGGER_BOTH_EDGES
, GPIOPinConfig.TRIGGER_HIGH_LEVEL
, GPIOPinConfig.TRIGGER_LOW_LEVEL
,
GPIOPinConfig.TRIGGER_BOTH_LEVELS
.IOException
- if an IO error occurred.UnsupportedOperationException
- if this GPIO pin is currently configured for output or cannot otherwise
be configured with the desired trigger mode.IllegalArgumentException
- if trigger
is not one of the defined values.UnavailableDeviceException
- if this device is not currently available - such as it is locked by another
application.ClosedDeviceException
- if the device has been closed.void setInputListener(PinListener listener) throws IOException, UnsupportedOperationException, IllegalStateException, ClosedDeviceException
PinListener
instance which will get asynchronously notified when this
GPIO pin's value changes and according to the current trigger mode (see getTrigger
). Notification will automatically begin after registration completes.
If this GPIOPin
is open in DeviceManager.SHARED
access mode and if this
GPIOPin
is currently configured for input, the listeners registered by all the
applications sharing the underlying GPIO pin will get notified when its value changes.
A listener can only be registered for a GPIO pin currently configured for input.
If listener
is null
then the previously registered listener is removed.
Only one listener can be registered at a particular time.
listener
- the PinListener
instance to be notified when this GPIO pin's value
changes.IOException
- if some other I/O error occurs.UnsupportedOperationException
- if this GPIO pin is currently configured for output.IllegalStateException
- if listener
is not null
and a listener is already registered.ClosedDeviceException
- if the device has been closed.void setValue(boolean value) throws IOException, UnsupportedOperationException, UnavailableDeviceException, ClosedDeviceException
An attempt to set the value on a GPIO pin currently configured for input will result in a
UnsupportedOperationException
being thrown.
value
- the new pin value: true
for high, false
for low.UnsupportedOperationException
- if trying to set the value for pin configured for input.IOException
- if an I/O error occurred such as the pin is not writable.UnavailableDeviceException
- if this device is not currently available - such as it is locked by another
application.ClosedDeviceException
- if the device has been closed.