android gpio 框架,Gpio  |  Android 开发者  |  Android Developers

Gpio

public

interface

Gpio

implements

Closeablecom.google.android.things.pio.Gpio

9af5b0d0e95b72f0836e23fa5ea15c04.pngKnown 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

9af5b0d0e95b72f0836e23fa5ea15c04.pngFrom

interface

abstract

void

Closes this stream and releases any system resources associated

with it.

9af5b0d0e95b72f0836e23fa5ea15c04.pngFrom

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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值