本文整理汇总了Java中com.google.android.things.pio.PeripheralManagerService.openGpio方法的典型用法代码示例。如果您正苦于以下问题:Java PeripheralManagerService.openGpio方法的具体用法?Java PeripheralManagerService.openGpio怎么用?Java PeripheralManagerService.openGpio使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.android.things.pio.PeripheralManagerService
的用法示例。
在下文中一共展示了PeripheralManagerService.openGpio方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onCreate
import com.google.android.things.pio.PeripheralManagerService; //导入方法依赖的package包/类
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
PeripheralManagerService service = new PeripheralManagerService();
mUltrasonicSensorDriver = new UltrasonicSensorDriver(BoardDefaults.getGPIOForTrig(),
BoardDefaults.getGPIOForEcho(), this);
try {
mRedPin = service.openGpio(BoardDefaults.getGPIOForRedLED());
mRedPin.setDirection(Gpio.DIRECTION_OUT_INITIALLY_LOW);
mRedPin.setValue(false);
mYellowPin = service.openGpio(BoardDefaults.getGPIOForYellowLED());
mYellowPin.setDirection(Gpio.DIRECTION_OUT_INITIALLY_LOW);
mYellowPin.setValue(false);
mGreenPin = service.openGpio(BoardDefaults.getGPIOForGreenLED());
mGreenPin.setDirection(Gpio.DIRECTION_OUT_INITIALLY_LOW);
mGreenPin.setValue(false);
} catch (IOException e) {
e.printStackTrace();
}
}
示例2: initPIO
import com.google.android.things.pio.PeripheralManagerService; //导入方法依赖的package包/类
/**
* This method should only be called when running on an Android Things device.
*/
private void initPIO() {
PeripheralManagerService pioService = new PeripheralManagerService();
try {
mReadyLED = pioService.openGpio(BoardDefaults.getGPIOForLED());
mReadyLED.setDirection(Gpio.DIRECTION_OUT_INITIALLY_LOW);
mButtonDriver = new ButtonInputDriver(
BoardDefaults.getGPIOForButton(),
Button.LogicState.PRESSED_WHEN_LOW,
KeyEvent.KEYCODE_ENTER);
mButtonDriver.register();
} catch (IOException e) {
mButtonDriver = null;
Log.w(TAG, "Could not open GPIO pins", e);
}
}
开发者ID:androidthings,项目名称:sample-tensorflow-imageclassifier,代码行数:19,代码来源:ImageClassifierActivity.java
示例3: FrontRadar
import com.google.android.things.pio.PeripheralManagerService; //导入方法依赖的package包/类
/**
* Public constructor.
*/
public FrontRadar(@NonNull ObstacleAlertListener listener) {
super();
//Initialize GPIO
try {
PeripheralManagerService service = new PeripheralManagerService();
Gpio trigPin = service.openGpio(BoardDefaults.getGPIOForFrontRadarTrig());
Gpio echoPin = service.openGpio(BoardDefaults.getGPIOForFrontEcho());
mHCSR04Driver = new HCSR04Driver(echoPin, trigPin, this);
} catch (IOException e) {
e.printStackTrace();
throw new GpioInitializationException();
}
mListener = listener;
}
示例4: onCreate
import com.google.android.things.pio.PeripheralManagerService; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
PeripheralManagerService service = new PeripheralManagerService();
Log.d(TAG, "Available GPIO: " + service.getGpioList());
try {
// Create GPIO connection.
mButtonGpio = service.openGpio(BUTTON_PIN_NAME);
// Configure as an input, trigger events on every change.
mButtonGpio.setDirection(Gpio.DIRECTION_IN);
mButtonGpio.setEdgeTriggerType(Gpio.EDGE_BOTH);
// Value is true when the pin is LOW
mButtonGpio.setActiveType(Gpio.ACTIVE_LOW);
// Register the event callback.
mButtonGpio.registerGpioCallback(mCallback);
mLedGpio = service.openGpio(LED_PIN_NAME);
// Configure as an output.
mLedGpio.setDirection(Gpio.DIRECTION_OUT_INITIALLY_LOW);
} catch (IOException e) {
Log.w(TAG, "Error opening GPIO", e);
}
}
示例5: ValvesControl
import com.google.android.things.pio.PeripheralManagerService; //导入方法依赖的package包/类
public ValvesControl(String pinValveO2, String pinValveCO2, String pinValveVacuum) {
manager = new PeripheralManagerService();
try {
valveCO2 = manager.openGpio(pinValveCO2);
valveO2 = manager.openGpio(pinValveO2);
valveVacuum = manager.openGpio(pinValveVacuum);
valveCO2.setDirection(Gpio.DIRECTION_OUT_INITIALLY_LOW);
valveO2.setDirection(Gpio.DIRECTION_OUT_INITIALLY_LOW);
valveVacuum.setDirection(Gpio.DIRECTION_OUT_INITIALLY_LOW);
valveCO2.setActiveType(Gpio.ACTIVE_HIGH);
valveO2.setActiveType(Gpio.ACTIVE_HIGH);
valveVacuum.setActiveType(Gpio.ACTIVE_HIGH);
} catch (IOException e) {
e.printStackTrace();
}
}
示例6: onCreate
import com.google.android.things.pio.PeripheralManagerService; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.d(TAG, "onCreate");
PeripheralManagerService manager = new PeripheralManagerService();
try {
for (int i = 0; i < mLedGpios.length; i++) {
mLedGpios[i] = manager.openGpio(gpioNames[i]);
mLedGpios[i].setDirection(Gpio.DIRECTION_OUT_INITIALLY_LOW);
}
} catch (IOException e) {
e.printStackTrace();
}
thread = new NetworkThread(manager, mLedGpios);
thread.start();
}
示例7: onCreate
import com.google.android.things.pio.PeripheralManagerService; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.i(TAG, "Starting ButtonActivity");
PeripheralManagerService pioService = new PeripheralManagerService();
try {
Log.i(TAG, "Configuring GPIO pins");
mLedGpio = pioService.openGpio(BoardDefaults.getGPIOForLED());
mLedGpio.setDirection(Gpio.DIRECTION_OUT_INITIALLY_LOW);
Log.i(TAG, "Registering button driver");
// Initialize and register the InputDriver that will emit SPACE key events
// on GPIO state changes.
mButtonInputDriver = new ButtonInputDriver(
BoardDefaults.getGPIOForButton(),
Button.LogicState.PRESSED_WHEN_LOW,
KeyEvent.KEYCODE_SPACE);
mButtonInputDriver.register();
} catch (IOException e) {
Log.e(TAG, "Error configuring GPIO pins", e);
}
}
示例8: I2cBitBangDevice
import com.google.android.things.pio.PeripheralManagerService; //导入方法依赖的package包/类
public I2cBitBangDevice(int i2cAddress, String pinData, String pinClock) throws IOException {
mAddress = i2cAddress;
PeripheralManagerService pioService = new PeripheralManagerService();
try {
mData = pioService.openGpio(pinData);
mData.setDirection(Gpio.DIRECTION_OUT_INITIALLY_LOW);
mClock = pioService.openGpio(pinClock);
mClock.setDirection(Gpio.DIRECTION_OUT_INITIALLY_LOW);
} catch (IOException|RuntimeException e) {
try {
close();
} catch (IOException|RuntimeException ignored) {
}
throw e;
}
}
示例9: MatrixKeypad
import com.google.android.things.pio.PeripheralManagerService; //导入方法依赖的package包/类
public MatrixKeypad(String[] rowPins, String[] colPins, int[] keyCodes,
Handler handler) throws IOException {
PeripheralManagerService pioService = new PeripheralManagerService();
mGpioRows = new Gpio[rowPins.length];
mGpioCols = new Gpio[colPins.length];
mKeyCodes = keyCodes;
mMatrix = new MatrixKey[rowPins.length][colPins.length];
// Initialize Gpio and keys
for (int r = 0; r < rowPins.length; r++) {
mGpioRows[r] = pioService.openGpio(rowPins[r]);
mGpioRows[r].setDirection(Gpio.DIRECTION_IN);
for (int c = 0; c < colPins.length; c++) {
if (mGpioCols[c] == null) {
mGpioCols[c] = pioService.openGpio(colPins[c]);
mGpioCols[c].setDirection(Gpio.DIRECTION_IN);
}
mMatrix[r][c] = new MatrixKey(keyCodes[r * colPins.length + c]);
}
}
initKeyScanHandler(handler);
}
示例10: Cap12xx
import com.google.android.things.pio.PeripheralManagerService; //导入方法依赖的package包/类
/**
* Create a new Cap12xx controller.
*
* @param i2cName I2C port name where the controller is attached. Cannot be null.
* @param alertName optional GPIO pin name connected to the controller's
* alert interrupt signal. Can be null.
* @param chip identifier for the connected controller device chip.
* @param handler optional {@link Handler} for software polling and callback events.
* @throws IOException
*/
public Cap12xx(String i2cName, String alertName, Configuration chip, Handler handler)
throws IOException {
mChipConfiguration = chip;
try {
PeripheralManagerService manager = new PeripheralManagerService();
I2cDevice device = manager.openI2cDevice(i2cName, I2C_ADDRESS);
Gpio alertPin = null;
if (alertName != null) {
alertPin = manager.openGpio(alertName);
}
init(device, alertPin, chip, handler);
} catch (IOException|RuntimeException e) {
// Close the peripherals if an init error occurs
try {
close();
} catch (IOException|RuntimeException ignored) {
}
throw e;
}
}
示例11: onCreate
import com.google.android.things.pio.PeripheralManagerService; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.i(TAG, "Starting BlinkActivity");
PeripheralManagerService service = new PeripheralManagerService();
try {
String pinName = BoardDefaults.getGPIOForLED();
mLedGpio = service.openGpio(pinName);
mLedGpio.setDirection(Gpio.DIRECTION_OUT_INITIALLY_LOW);
Log.i(TAG, "Start blinking LED GPIO pin");
// Post a Runnable that continuously switch the state of the GPIO, blinking the
// corresponding LED
mHandler.post(mBlinkRunnable);
} catch (IOException e) {
Log.e(TAG, "Error on PeripheralIO API", e);
}
}
示例12: GpioHandler
import com.google.android.things.pio.PeripheralManagerService; //导入方法依赖的package包/类
private GpioHandler() {
EventBus.getDefault().register(this);
mContext = ContextHolder.getAppContext();
manager = new PeripheralManagerService();
try {
mAlarmGpio = manager.openGpio(GPIO_ALARM_TRIGGER);
mAlarmGpio.setDirection(Gpio.DIRECTION_OUT_INITIALLY_LOW);
mMotion = new Button(GPIO_ALARM_MOTION,
Button.LogicState.PRESSED_WHEN_HIGH
);
mMotion.setOnButtonEventListener(this);
} catch (IOException e) {
Log.e(BurglarAlarmConstants.LOG_TAG, "IOException :" + e);
}
}
示例13: initPIO
import com.google.android.things.pio.PeripheralManagerService; //导入方法依赖的package包/类
private void initPIO() {
PeripheralManagerService pioService = new PeripheralManagerService();
try {
mReadyLED = pioService.openGpio(BoardDefaults.getGPIOForLED());
mReadyLED.setDirection(Gpio.DIRECTION_OUT_INITIALLY_LOW);
mButtonDriver = new ButtonInputDriver(
BoardDefaults.getGPIOForButton(),
Button.LogicState.PRESSED_WHEN_LOW,
KeyEvent.KEYCODE_ENTER);
mButtonDriver.register();
} catch (IOException e) {
mButtonDriver = null;
Log.w(TAG, "Could not open GPIO pins", e);
}
}
示例14: HC595Driver
import com.google.android.things.pio.PeripheralManagerService; //导入方法依赖的package包/类
/**
* Create and initialize LED matrix
* @param RCLK_pin memory clock input(STCP)
* @param SRCLK_pin shift register clock input(SHCP)
* @param DI_pin serial data input
* @throws IOException
*/
public HC595Driver(@NonNull String RCLK_pin, @NonNull String SRCLK_pin, @NonNull String DI_pin) throws IOException {
PeripheralManagerService service = new PeripheralManagerService();
RCLK = service.openGpio(RCLK_pin); RCLK.setDirection(Gpio.DIRECTION_OUT_INITIALLY_LOW);
SRCLK = service.openGpio(SRCLK_pin); SRCLK.setDirection(Gpio.DIRECTION_OUT_INITIALLY_LOW);
DI = service.openGpio(DI_pin); DI.setDirection(Gpio.DIRECTION_OUT_INITIALLY_LOW);
refreshThread.setPriority(Process.THREAD_PRIORITY_LESS_FAVORABLE);
refreshThread.start();
}
示例15: MY9221LEDDriver
import com.google.android.things.pio.PeripheralManagerService; //导入方法依赖的package包/类
/**
* Create and initialize driver
* @param DI_pin_name DI data input
* @param DCLK_pin_name DCLK clock input
* @throws IOException
*/
public MY9221LEDDriver(@NonNull String DI_pin_name, @NonNull String DCLK_pin_name) throws IOException {
PeripheralManagerService service = new PeripheralManagerService();
mDI = service.openGpio(DI_pin_name);
mDI.setDirection(Gpio.DIRECTION_OUT_INITIALLY_LOW);
mDCLK = service.openGpio(DCLK_pin_name);
mDCLK.setDirection(Gpio.DIRECTION_OUT_INITIALLY_LOW);
clk_flag = false;
}