com.google.android.things.contrib.driver.button.ButtonInputDriver Java Examples

The following examples show how to use com.google.android.things.contrib.driver.button.ButtonInputDriver. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ImageClassifierActivity.java    From sample-tensorflow-imageclassifier with Apache License 2.0 6 votes vote down vote up
/**
 * This method should only be called when running on an Android Things device.
 */
private void initPIO() {
    PeripheralManager pioManager = PeripheralManager.getInstance();
    try {
        mReadyLED = pioManager.openGpio(BoardDefaults.getGPIOForLED());
        mReadyLED.setDirection(Gpio.DIRECTION_OUT_INITIALLY_LOW);
        mButtonDriver = new ButtonInputDriver(
                BoardDefaults.getGPIOForButton(),
                Button.LogicState.PRESSED_WHEN_LOW,
                SHUTTER_KEYCODE);
        mButtonDriver.register();
    } catch (IOException e) {
        mButtonDriver = null;
        Log.w(TAG, "Could not open GPIO pins", e);
    }
}
 
Example #2
Source File: VoiceHatPeripheralInstrumentationTest.java    From contrib-drivers with Apache License 2.0 6 votes vote down vote up
/**
 * Registers button as an InputDriver
 */
@Test
@UiThreadTest
public void testButtonInputDriver() throws IOException {
    InstrumentationTestUtils.assertRaspberryPiOnly();
    getInstrumentation().runOnMainSync(new Runnable() {
        @Override
        public void run() {
            try {
                ButtonInputDriver driver =
                    VoiceHat.createButtonInputDriver(KeyEvent.KEYCODE_ENTER);
                driver.register();
                driver.unregister();
                driver.close();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
    });
}
 
Example #3
Source File: A2dpSinkActivity.java    From sample-bluetooth-audio with Apache License 2.0 5 votes vote down vote up
private void configureButton() {
    try {
        mPairingButtonDriver = new ButtonInputDriver(BoardDefaults.getGPIOForPairing(),
                Button.LogicState.PRESSED_WHEN_LOW, KeyEvent.KEYCODE_P);
        mPairingButtonDriver.register();
        mDisconnectAllButtonDriver = new ButtonInputDriver(
                BoardDefaults.getGPIOForDisconnectAllBTDevices(),
                Button.LogicState.PRESSED_WHEN_LOW, KeyEvent.KEYCODE_D);
        mDisconnectAllButtonDriver.register();
    } catch (IOException e) {
        Log.w(TAG, "Could not register GPIO button drivers. Use keyboard events to trigger " +
                "the functions instead", e);
    }
}
 
Example #4
Source File: DoorbellActivity.java    From doorbell with Apache License 2.0 5 votes vote down vote up
private void initPIO() {
    try {
        mButtonInputDriver = new ButtonInputDriver(
                BoardDefaults.getGPIOForButton(),
                Button.LogicState.PRESSED_WHEN_LOW,
                KeyEvent.KEYCODE_ENTER);
        mButtonInputDriver.register();
    } catch (IOException e) {
        mButtonInputDriver = null;
        Log.w(TAG, "Could not open GPIO pins", e);
    }
}
 
Example #5
Source File: RainbowHat.java    From contrib-drivers with Apache License 2.0 4 votes vote down vote up
public static ButtonInputDriver createButtonAInputDriver(int keycode) throws IOException {
    return createButtonInputDriver(BOARD.getButtonA(), keycode);
}
 
Example #6
Source File: RainbowHat.java    From contrib-drivers with Apache License 2.0 4 votes vote down vote up
public static ButtonInputDriver createButtonBInputDriver(int keycode) throws IOException {
    return createButtonInputDriver(BOARD.getButtonB(), keycode);
}
 
Example #7
Source File: RainbowHat.java    From contrib-drivers with Apache License 2.0 4 votes vote down vote up
public static ButtonInputDriver createButtonCInputDriver(int keycode) throws IOException {
    return createButtonInputDriver(BOARD.getButtonC(), keycode);
}
 
Example #8
Source File: RainbowHat.java    From contrib-drivers with Apache License 2.0 4 votes vote down vote up
public static ButtonInputDriver createButtonInputDriver(String pin, int keycode) throws IOException {
    return new ButtonInputDriver(pin, BUTTON_LOGIC_STATE, keycode);
}
 
Example #9
Source File: VoiceHat.java    From contrib-drivers with Apache License 2.0 2 votes vote down vote up
/**
 * Opens an InputDriver using the default pin on the Raspberry Pi.
 *
 * @return InputDriver for the pushbutton on the VoiceHat
 */
public static ButtonInputDriver createButtonInputDriver(int keyCode) throws IOException {
    assertRaspberryPi3();
    return createButtonInputDriver(RPI_BUTTON_GPIO, keyCode);
}
 
Example #10
Source File: VoiceHat.java    From contrib-drivers with Apache License 2.0 2 votes vote down vote up
/**
 * Opens an InputDriver using a specified.
 *
 * @return InputDriver for the pushbutton on the VoiceHat
 */
public static ButtonInputDriver createButtonInputDriver(String buttonGpioPin, int keyCode)
    throws IOException {
    return new ButtonInputDriver(buttonGpioPin, LogicState.PRESSED_WHEN_LOW, keyCode);
}