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

The following examples show how to use com.google.android.things.contrib.driver.button.Button. 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: RainbowHatInstrumentationTest.java    From contrib-drivers with Apache License 2.0 6 votes vote down vote up
/**
 * Verify that the buttons are not null.
 */
@Test
@UiThreadTest
public void testOpenButton() throws IOException {
    getInstrumentation().runOnMainSync(new Runnable() {
        @Override
        public void run() {
            try {
                Button buttonA = RainbowHat.openButtonA();
                Button buttonB = RainbowHat.openButtonB();
                Button buttonC = RainbowHat.openButtonC();
                Assert.assertNotNull(buttonA);
                Assert.assertNotNull(buttonB);
                Assert.assertNotNull(buttonC);
                buttonA.close();
                buttonB.close();
                buttonC.close();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
    });
}
 
Example #3
Source File: VoiceHatPeripheralInstrumentationTest.java    From contrib-drivers with Apache License 2.0 6 votes vote down vote up
/**
 * Verify that the button is null if not passed as a parameter.
 */
@Test
@UiThreadTest
public void testButtonNull() throws IOException {
    InstrumentationTestUtils.assertRaspberryPiOnly();
    getInstrumentation().runOnMainSync(new Runnable() {
        @Override
        public void run() {
            try {
                Button button = VoiceHat.openButton();
                Assert.assertNotNull(button);
                button.close();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
    });
}
 
Example #4
Source File: AssistantActivity.java    From androidthings-googleassistant with Apache License 2.0 5 votes vote down vote up
@Override
public void onButtonEvent(Button button, boolean pressed) {
    try {
        if (mLed != null) {
            mLed.setValue(pressed);
        }
    } catch (IOException e) {
        Log.d(TAG, "error toggling LED:", e);
    }
    if (pressed) {
        mAssistantHandler.post(mStartAssistantRequest);
    } else {
        mAssistantHandler.post(mStopAssistantRequest);
    }
}
 
Example #5
Source File: AssistantActivity.java    From androidthings-googleassistant with Apache License 2.0 5 votes vote down vote up
@Override
public void onButtonEvent(Button button, boolean pressed) {
    try {
        if (mLed != null) {
            mLed.setValue(pressed);
        }
    } catch (IOException e) {
        Log.d(TAG, "error toggling LED:", e);
    }
    if (pressed) {
        mAssistantHandler.post(mStartAssistantRequest);
    } else {
        mAssistantHandler.post(mStopAssistantRequest);
    }
}
 
Example #6
Source File: AssistantActivity.java    From androidthings-googleassistant with Apache License 2.0 5 votes vote down vote up
@Override
public void onButtonEvent(Button button, boolean pressed) {
    try {
        if (mLed != null) {
            mLed.setValue(pressed);
        }
    } catch (IOException e) {
        Log.d(TAG, "error toggling LED:", e);
    }
    if (pressed) {
        mAssistantHandler.post(mStartAssistantRequest);
    } else {
        mAssistantHandler.post(mStopAssistantRequest);
    }
}
 
Example #7
Source File: AssistantActivity.java    From androidthings-googleassistant with Apache License 2.0 5 votes vote down vote up
@Override
public void onButtonEvent(Button button, boolean pressed) {
    try {
        if (mLed != null) {
            mLed.setValue(pressed);
        }
    } catch (IOException e) {
        Log.d(TAG, "error toggling LED:", e);
    }
    if (pressed) {
        mAssistantHandler.post(mStartAssistantRequest);
    } else {
        mAssistantHandler.post(mStopAssistantRequest);
    }
}
 
Example #8
Source File: AssistantActivity.java    From sample-googleassistant with Apache License 2.0 5 votes vote down vote up
@Override
public void onButtonEvent(Button button, boolean pressed) {
    try {
        if (mLed != null) {
            mLed.setValue(pressed);
        }
    } catch (IOException e) {
        Log.d(TAG, "error toggling LED:", e);
    }
    if (pressed) {
        mEmbeddedAssistant.startConversation();
    }
}
 
Example #9
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 #10
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 #11
Source File: RainbowHat.java    From contrib-drivers with Apache License 2.0 4 votes vote down vote up
public static Button openButtonA() throws IOException {
    return openButton(BOARD.getButtonA());
}
 
Example #12
Source File: RainbowHat.java    From contrib-drivers with Apache License 2.0 4 votes vote down vote up
public static Button openButtonB() throws IOException {
    return openButton(BOARD.getButtonB());
}
 
Example #13
Source File: RainbowHat.java    From contrib-drivers with Apache License 2.0 4 votes vote down vote up
public static Button openButtonC() throws IOException {
    return openButton(BOARD.getButtonC());
}
 
Example #14
Source File: RainbowHat.java    From contrib-drivers with Apache License 2.0 4 votes vote down vote up
public static Button openButton(String pin) throws IOException {
    return new Button(pin, BUTTON_LOGIC_STATE);
}
 
Example #15
Source File: VoiceHat.java    From contrib-drivers with Apache License 2.0 2 votes vote down vote up
/**
 * Opens the button using the default pin on the Raspberry Pi.
 *
 * @return Pushbutton on the VoiceHat
 */
public static Button openButton() throws IOException {
    assertRaspberryPi3();
    return openButton(RPI_BUTTON_GPIO);
}
 
Example #16
Source File: VoiceHat.java    From contrib-drivers with Apache License 2.0 2 votes vote down vote up
/**
 * Opens the button using a specified pin.
 *
 * @param pinName The pin attached to the button.
 * @return Pushbutton on the VoiceHat
 */
public static Button openButton(String pinName) throws IOException {
    Button pushButton = new Button(pinName, LogicState.PRESSED_WHEN_LOW);
    pushButton.setDebounceDelay(BUTTON_DEBOUNCE_DELAY_MS);
    return pushButton;
}