public class GPIO
extends java.lang.Object
A GPIO
lets you configure and control a physical module or board
pin being able to write and read its value.
To obtain an instance of the GPIO you have to use one of the following methods:
Modifier and Type | Field | Description |
---|---|---|
static int |
DEFAULT_POLLING_RATE |
Default polling rate: milliseconds.
|
Modifier and Type | Method | Description |
---|---|---|
protected void |
finalize() |
|
int |
getKernelNumber() |
Retrieves the kernel number associated to this GPIO object.
|
GPIOMode |
getMode() |
Retrieves the GPIO working mode.
|
int |
getPinIndex() |
Retrieves the pin index associated to this GPIO object.
|
int |
getPortIndex() |
Retrieves the base port index associated to this GPIO object.
|
GPIOValue |
getValue() |
Retrieves the GPIO value.
|
void |
registerListener(IGPIOListener listener) |
Registers a listener to detect when a GPIO changes value.
|
void |
setMode(GPIOMode mode) |
Sets the GPIO working mode.
|
void |
setPollingRate(int pollingRate) |
Configures the polling rate time for this GPIO.
|
void |
setValue(GPIOValue value) |
Sets the GPIO value.
|
java.lang.String |
toString() |
Returns a string representation of this GPIO.
|
void |
unregisterListener(IGPIOListener listener) |
Unregisters a listener to stop detecting when a GPIO changes value.
|
public static final int DEFAULT_POLLING_RATE
public GPIOValue getValue() throws GPIOException
Attempts to read the GPIO value file and retrieve the contents.
This method only has effect if GPIO mode is:
GPIOMode.INPUT
GPIOMode.INTERRUPT_EDGE_RISING
GPIOMode.INTERRUPT_EDGE_FALLING
GPIOMode.INTERRUPT_EDGE_BOTH
For modes GPIOMode.OUTPUT_HIGH
and GPIOMode.OUTPUT_LOW
this method always returns GPIOValue.LOW
.
GPIOException
- If there is an error reading the GPIO value.setValue(GPIOValue)
,
GPIOValue.HIGH
,
GPIOValue.LOW
public void setValue(GPIOValue value) throws GPIOException
Attempts to write in the GPIO value file.
This method only has effect if GPIO mode is:
GPIOMode.OUTPUT_HIGH
GPIOMode.OUTPUT_LOW
For modes GPIOMode.INPUT
, GPIOMode.INTERRUPT_EDGE_RISING
,
GPIOMode.INTERRUPT_EDGE_FALLING
and
GPIOMode.INTERRUPT_EDGE_BOTH
this method returns without further
action.
value
- New GPIO value.GPIOException
- If there is an error setting the GPIO value.java.lang.NullPointerException
- If value == null
.getValue()
,
setMode(GPIOMode)
,
GPIOValue.HIGH
,
GPIOValue.LOW
public GPIOMode getMode()
setMode(GPIOMode)
,
GPIOMode.INPUT
,
GPIOMode.INTERRUPT_EDGE_BOTH
,
GPIOMode.INTERRUPT_EDGE_FALLING
,
GPIOMode.INTERRUPT_EDGE_RISING
,
GPIOMode.OUTPUT_HIGH
,
GPIOMode.OUTPUT_LOW
public void setMode(GPIOMode mode) throws GPIOException
Configures required GPIO edge and direction values to set the GPIO in the given working mode.
mode
- The desired GPIO working mode.GPIOException
- If the given mode is not valid or if there is an
error setting the GPIO direction or edge.java.lang.NullPointerException
- If mode == null
.getMode()
,
GPIOMode.INPUT
,
GPIOMode.INTERRUPT_EDGE_BOTH
,
GPIOMode.INTERRUPT_EDGE_FALLING
,
GPIOMode.INTERRUPT_EDGE_RISING
,
GPIOMode.OUTPUT_HIGH
,
GPIOMode.OUTPUT_LOW
public int getKernelNumber()
public int getPortIndex()
public int getPinIndex()
public void registerListener(IGPIOListener listener)
If the given listener is already registered, this method does nothing.
listener
- The listener to be registered.java.lang.NullPointerException
- If listener == null
.unregisterListener(IGPIOListener)
,
IGPIOListener
public void unregisterListener(IGPIOListener listener)
If the given listener is not registered, this method does nothing.
listener
- The listener to be unregistered.java.lang.NullPointerException
- If listener == null
.registerListener(IGPIOListener)
,
IGPIOListener
public void setPollingRate(int pollingRate)
The polling rate stands for the amount of milliseconds between checks for changes in the GPIO value.
Note: Depending on the configured polling rate changes may not be detected if they occur between checks.
HIGH................__________.................
| |
LOW _______________| |________________
^ ^
| |
+-----------------------------+
Polling rate time
pollingRate
- Time in milliseconds to wait between each
interruption triggered check.java.lang.IllegalArgumentException
- If pollingRate < 0
.getPollingRate()
public java.lang.String toString()
Currently this is a string indicating the GPIO kernel number, its port and pin indexes and how it is configured.
You can get these values separately using getKernelNumber()
,
getPortIndex()
, getPinIndex()
, and getMode()
.
toString
in class java.lang.Object
protected void finalize() throws java.lang.Throwable
finalize
in class java.lang.Object
java.lang.Throwable