public final class GPIOPinConfig extends java.lang.Object implements DeviceConfig<GPIOPin>, DeviceConfig.HardwareAddressing
GPIOPinConfig
class encapsulates the hardware addressing information, and static and
dynamic configuration parameters of a GPIO pin.
Some hardware addressing, static or dynamic configuration parameters may be
set to UNASSIGNED
or null
(see
Unassigned, Default or Unused Parameter Values).
An instance of GPIOPinConfig
can be passed to the
open(DeviceConfig, ...)
and
open(Class, DeviceConfig, ...)
methods of the DeviceManager
to open the designated GPIO pin
with the specified configuration. A InvalidDeviceConfigException
is thrown when
attempting to open a device with an invalid or unsupported configuration.
Modifier and Type | Class and Description |
---|---|
static class |
GPIOPinConfig.Builder
The
Builder class allows for creating and initializing
GPIOPinConfig objects. |
DeviceConfig.HardwareAddressing
Modifier and Type | Field and Description |
---|---|
static int |
DIR_BOTH_INIT_INPUT
Bidirectional pin direction with initial input direction.
|
static int |
DIR_BOTH_INIT_OUTPUT
Bidirectional pin direction with initial output direction.
|
static int |
DIR_INPUT_ONLY
Input pin direction.
|
static int |
DIR_OUTPUT_ONLY
Output pin direction.
|
static int |
MODE_INPUT_PULL_DOWN
Input pull-down drive mode.
|
static int |
MODE_INPUT_PULL_UP
Input pull-up drive mode.
|
static int |
MODE_OUTPUT_OPEN_DRAIN
Output open-drain drive mode.
|
static int |
MODE_OUTPUT_PUSH_PULL
Output push-pull drive mode.
|
static int |
TRIGGER_BOTH_EDGES
Rising edge trigger.
|
static int |
TRIGGER_BOTH_LEVELS
Both levels trigger.
|
static int |
TRIGGER_FALLING_EDGE
Falling edge trigger.
|
static int |
TRIGGER_HIGH_LEVEL
High level trigger.
|
static int |
TRIGGER_LOW_LEVEL
Low level trigger.
|
static int |
TRIGGER_NONE
No interrupt trigger.
|
static int |
TRIGGER_RISING_EDGE
Rising edge trigger.
|
DEFAULT, UNASSIGNED
Constructor and Description |
---|
GPIOPinConfig(int controllerNumber,
int pinNumber,
int direction,
int mode,
int trigger,
boolean initValue)
Deprecated.
As of 1.1, use
GPIOPinConfig.Builder instead. |
GPIOPinConfig(java.lang.String controllerName,
int pinNumber,
int direction,
int mode,
int trigger,
boolean initValue)
Deprecated.
As of 1.1, use
GPIOPinConfig.Builder instead. |
Modifier and Type | Method and Description |
---|---|
static GPIOPinConfig |
deserialize(java.io.InputStream in)
Creates a new
GPIOPinConfig whose state is deserialized from the specified InputStream . |
boolean |
equals(java.lang.Object obj)
Checks two
GPIOPinConfig objects for equality. |
java.lang.String |
getControllerName()
Gets the configured controller name (such as its device file name on UNIX systems).
|
int |
getControllerNumber()
Gets the configured controller number for the pin.
|
int |
getDirection()
Gets the configured pin direction.
|
int |
getDriveMode()
Gets the configured pin drive mode.
|
boolean |
getInitValue()
Gets the configured initial value of the pin, if configured for output.
|
int |
getPinNumber()
Gets the configured pin number.
|
int |
getTrigger()
Gets the configured initial pin interrupt trigger.
|
int |
hashCode()
Returns the hash code value for this object.
|
int |
serialize(java.io.OutputStream out)
Serializes the state of this
GPIOPinConfig object to the specified OutputStream . |
public static final int DIR_BOTH_INIT_INPUT
public static final int DIR_BOTH_INIT_OUTPUT
public static final int DIR_INPUT_ONLY
public static final int DIR_OUTPUT_ONLY
public static final int MODE_INPUT_PULL_DOWN
This bit flag can be bitwise-combined (OR) with other drive mode bit flags.
public static final int MODE_INPUT_PULL_UP
This bit flag can be bitwise-combined (OR) with other drive mode bit flags.
public static final int MODE_OUTPUT_OPEN_DRAIN
This bit flag can be bitwise-combined (OR) with other drive mode bit flags.
public static final int MODE_OUTPUT_PUSH_PULL
This bit flag can be bitwise-combined (OR) with other drive mode bit flags.
public static final int TRIGGER_BOTH_EDGES
public static final int TRIGGER_BOTH_LEVELS
public static final int TRIGGER_FALLING_EDGE
public static final int TRIGGER_HIGH_LEVEL
public static final int TRIGGER_LOW_LEVEL
public static final int TRIGGER_NONE
public static final int TRIGGER_RISING_EDGE
@Deprecated public GPIOPinConfig(int controllerNumber, int pinNumber, int direction, int mode, int trigger, boolean initValue)
GPIOPinConfig.Builder
instead.GPIOPinConfig
with the specified hardware addressing information and
configuration parameters.
The controller name is set to null
.
controllerNumber
- the hardware port's number (a positive or zero integer) or UNASSIGNED
.pinNumber
- the hardware pin's number (a positive or zero integer) or UNASSIGNED
.direction
- the allowed and initial direction of the pin, one of: DIR_INPUT_ONLY
,
DIR_OUTPUT_ONLY
, DIR_BOTH_INIT_INPUT
,
DIR_BOTH_INIT_OUTPUT
.mode
- the drive mode of the pin: either UNASSIGNED
or a bitwise OR of at least one
of: MODE_INPUT_PULL_UP
, MODE_INPUT_PULL_DOWN
,
MODE_OUTPUT_PUSH_PULL
, MODE_OUTPUT_OPEN_DRAIN
; if the pin can be
set in both input and output direction then the mode must specify both an input
drive mode and an output drive mode (bit mask).trigger
- the initial interrupt trigger events, one of: TRIGGER_NONE
,
TRIGGER_FALLING_EDGE
, TRIGGER_RISING_EDGE
,
TRIGGER_BOTH_EDGES
, TRIGGER_HIGH_LEVEL
,
TRIGGER_LOW_LEVEL
, TRIGGER_BOTH_LEVELS
; if the pin is
set for output-only then trigger
must be TRIGGER_NONE
.initValue
- the initial value of the pin when initially set for output; ignored otherwise.java.lang.IllegalArgumentException
- if any of the following is true:
controllerNumber
is not in the defined range;pinNumber
is not in the defined range;direction
is not one of the defined values;trigger
is not one of the defined values;trigger
is incompatible with the direction(s) designated by direction
;mode
does not designate any mode (i.e. equals 0
);mode
designates more than one input or output drive mode;mode
does not designates a drive mode for or designates a drive mode
incompatible with the direction(s) designated by direction
.@Deprecated public GPIOPinConfig(java.lang.String controllerName, int pinNumber, int direction, int mode, int trigger, boolean initValue)
GPIOPinConfig.Builder
instead.GPIOPinConfig
with the specified hardware addressing information and
configuration parameters.
The controller number is set to UNASSIGNED
.
controllerName
- the controller name (such as its device file name on UNIX systems).pinNumber
- the hardware pin's number (a positive or zero integer) or UNASSIGNED
.direction
- the allowed and initial direction of the pin, one of: DIR_INPUT_ONLY
,
DIR_OUTPUT_ONLY
, DIR_BOTH_INIT_INPUT
,
DIR_BOTH_INIT_OUTPUT
.mode
- the drive mode of the pin: either UNASSIGNED
or a bitwise OR of at least one
of: MODE_INPUT_PULL_UP
, MODE_INPUT_PULL_DOWN
,
MODE_OUTPUT_PUSH_PULL
, MODE_OUTPUT_OPEN_DRAIN
; if the pin can be
set in both input and output direction then the mode must specify both an input
drive mode and an output drive mode (bit mask).trigger
- the initial interrupt trigger events, one of: TRIGGER_NONE
,
TRIGGER_FALLING_EDGE
, TRIGGER_RISING_EDGE
,
TRIGGER_BOTH_EDGES
, TRIGGER_HIGH_LEVEL
,
TRIGGER_LOW_LEVEL
, TRIGGER_BOTH_LEVELS
; if the pin is
set for output-only then trigger
must be TRIGGER_NONE
.initValue
- the initial value of the pin when initially set for output; ignored otherwise.java.lang.IllegalArgumentException
- if any of the following is true:
pinNumber
is not in the defined range;direction
is not one of the defined values;trigger
is not one of the defined values;trigger
is incompatible with the direction(s) designated by direction
;mode
does not designate any mode (i.e. equals 0
);mode
designates more than one input or output drive mode;mode
does not designates a drive mode for or designates a drive mode
incompatible with the direction(s) designated by direction
.java.lang.NullPointerException
- if controllerName
is null
.public static GPIOPinConfig deserialize(java.io.InputStream in) throws java.io.IOException
GPIOPinConfig
whose state is deserialized from the specified InputStream
.
This method may be invoked to restore the state of a GPIOPinConfig
object from a persistent store.in
- the stream to read from.GPIOPinConfig
instance.java.io.IOException
- if an I/O error occurs or if the provided stream does not
contain a representation of a GPIOPinConfig
object.public int serialize(java.io.OutputStream out) throws java.io.IOException
GPIOPinConfig
object to the specified OutputStream
.
This method may be invoked by the DeviceManager
to save the state of this GPIOPinConfig
object to a persistent store.serialize
in interface DeviceConfig<GPIOPin>
out
- the stream to write to.java.io.IOException
- if an I/O error occurs.DeviceProvider.deserialize(java.io.InputStream)
public int getDirection()
DIR_INPUT_ONLY
, DIR_OUTPUT_ONLY
,
DIR_BOTH_INIT_INPUT
, DIR_BOTH_INIT_OUTPUT
.public int getDriveMode()
UNASSIGNED
or a bitwise OR of at least one of :
MODE_INPUT_PULL_UP
, MODE_INPUT_PULL_DOWN
,
MODE_OUTPUT_PUSH_PULL
, MODE_OUTPUT_OPEN_DRAIN
.public boolean getInitValue()
false
if configured for input.public int getPinNumber()
UNASSIGNED
.public int getControllerNumber()
getControllerNumber
in interface DeviceConfig.HardwareAddressing
UNASSIGNED
.public java.lang.String getControllerName()
getControllerName
in interface DeviceConfig.HardwareAddressing
null
.public int getTrigger()
TRIGGER_NONE
,
TRIGGER_FALLING_EDGE
, TRIGGER_RISING_EDGE
,
TRIGGER_BOTH_EDGES
, TRIGGER_HIGH_LEVEL
, TRIGGER_LOW_LEVEL
,
TRIGGER_BOTH_LEVELS
.public int hashCode()
hashCode
in class java.lang.Object
public boolean equals(java.lang.Object obj)
GPIOPinConfig
objects for equality.equals
in class java.lang.Object
obj
- the object to test for equality with this object.true
if obj
is a GPIOPinConfig
and has the same hardware
addressing information and configuration parameter values as this
GPIOPinConfig
object; false
otherwise.Copyright © 2012, 2015, Oracle and/or its affiliates. All rights reserved.
Legal Notices