Gpio
public
interface
Gpio
implements
Closeablecom.google.android.things.pio.Gpio
Known Indirect Subclasses
Controls a GPIO pin.
General-purpose input/output (GPIO) pins are physical pins on an integrated circuit that can
be controlled via software. A GPIO pin can be configured as input to read the voltage value or
as output to change the voltage value. It only understands logic values
(true/false) which maps physically to a low value (the pin has the same voltage
as Ground) or high value (the pin has the same voltage as IOREF). GPIOs are frequently used to
communicate with simple peripherals like sensors and actuators.
Opening a GPIO pin takes ownership of it for the whole system, preventing anyone else from
opening/accessing the GPIO until you call
Summary
Constants
int
true corresponds with high voltage.
int
true corresponds with low voltage.
int
int
true (equivalent of calling
int
false (equivalent of calling
int
int
true to false).
int
int
false to true).
Public methods
abstract
void
Releases the GPIO pin.
default
String
Returns the I/O name.
abstract
boolean
Gets the current value of the GPIO pin (for GPIO pins configured as input only).
default
void
Registers a callback for GPIO edge interrupts.
abstract
void
Registers a callback for GPIO edge interrupts.
abstract
void
setActiveType(int activeType)
Sets the active level.
abstract
void
setDirection(int direction)
Sets the direction of the GPIO pin.
abstract
void
setEdgeTriggerType(int edgeTriggerType)
Sets the interrupt trigger type.
abstract
void
setValue(boolean value)
Sets the value of the GPIO pin (for GPIO pins configured as output only).
abstract
void
Unregisters an interrupt callback.
Inherited methods
From
interface
abstract
void
Closes this stream and releases any system resources associated
with it.
From
interface
abstract
void
Closes this resource, relinquishing any underlying resources.
Constants
ACTIVE_HIGH
int ACTIVE_HIGH
true corresponds with high voltage.
Constant Value:
1
(0x00000001)
ACTIVE_LOW
int ACTIVE_LOW
true corresponds with low voltage.
Constant Value:
0
(0x00000000)
DIRECTION_IN
int DIRECTION_IN
Constant Value:
0
(0x00000000)
DIRECTION_OUT_INITIALLY_HIGH
int DIRECTION_OUT_INITIALLY_HIGH
true (equivalent of calling
Constant Value:
1
(0x00000001)
DIRECTION_OUT_INITIALLY_LOW
int DIRECTION_OUT_INITIALLY_LOW
false (equivalent of calling
Constant Value:
2
(0x00000002)
EDGE_BOTH
int EDGE_BOTH
Constant Value:
3
(0x00000003)
EDGE_FALLING
int EDGE_FALLING
true to false).
Constant Value:
2
(0x00000002)
EDGE_NONE
int EDGE_NONE
Constant Value:
0
(0x00000000)
EDGE_RISING
int EDGE_RISING
false to true).
Constant Value:
1
(0x00000001)
Public methods
close
void close ()
Releases the GPIO pin.
This must be called in order for the GPIO pin to be released and be available to other
users. Closing a GPIO does not change its state, for example if it closed while outputting
a high signal, it will continue to output high until another user opens it and changes its
state.
Throws
if the GPIO is already closed.
getName
String getName ()
Returns the I/O name.
Returns
getValue
boolean getValue ()
Gets the current value of the GPIO pin (for GPIO pins configured as input only).
Returns
boolean
the state of the GPIO pin. Return value is undefined if the GPIO is configured
as an output.
registerGpioCallback
void registerGpioCallback (GpioCallback callback)
Registers a callback for GPIO edge interrupts.Parameters
callback
GpioCallback: GpioCallback to register.
Throws
IOException
registerGpioCallback
void registerGpioCallback (Handler handler,
GpioCallback callback)
Registers a callback for GPIO edge interrupts.
The type of edges to watch for must be first set with
Parameters
handler
Handler: Handler to run callbacks on, or null to use the current thread.
callback
GpioCallback: GpioCallback to register.
Throws
IOException
setActiveType
void setActiveType (int activeType)
Sets the active level.
Parameters
activeType
setDirection
void setDirection (int direction)
Sets the direction of the GPIO pin.
setEdgeTriggerType
void setEdgeTriggerType (int edgeTriggerType)
Sets the interrupt trigger type.
The trigger type is based on the logical pin value, not the physical voltage. For
example, false-to-true
transition, but if the GPIO is configured as
Parameters
edgeTriggerType
int: Type of trigger to use for interrupt. One of
setValue
void setValue (boolean value)
Sets the value of the GPIO pin (for GPIO pins configured as output only).
Parameters
value
boolean: Value to set.
unregisterGpioCallback
void unregisterGpioCallback (GpioCallback callback)
Unregisters an interrupt callback.
Parameters
callback
GpioCallback: GpioCallback to unregister.