本文整理汇总了Java中com.google.android.things.contrib.driver.button.Button类的典型用法代码示例。如果您正苦于以下问题:Java Button类的具体用法?Java Button怎么用?Java Button使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Button类属于com.google.android.things.contrib.driver.button包,在下文中一共展示了Button类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initPIO
import com.google.android.things.contrib.driver.button.Button; //导入依赖的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
示例2: GpioHandler
import com.google.android.things.contrib.driver.button.Button; //导入依赖的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);
}
}
示例3: onCreate
import com.google.android.things.contrib.driver.button.Button; //导入依赖的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);
}
}
示例4: testButtonNull
import com.google.android.things.contrib.driver.button.Button; //导入依赖的package包/类
/**
* 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);
}
}
});
}
示例5: onButtonEvent
import com.google.android.things.contrib.driver.button.Button; //导入依赖的package包/类
@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);
}
}
示例6: initPIO
import com.google.android.things.contrib.driver.button.Button; //导入依赖的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);
}
}
示例7: onButtonEvent
import com.google.android.things.contrib.driver.button.Button; //导入依赖的package包/类
@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();
}
}
示例8: configureButton
import com.google.android.things.contrib.driver.button.Button; //导入依赖的package包/类
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);
}
}
示例9: initPIO
import com.google.android.things.contrib.driver.button.Button; //导入依赖的package包/类
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);
}
}
示例10: registerButtonDriver
import com.google.android.things.contrib.driver.button.Button; //导入依赖的package包/类
private static ButtonInputDriver registerButtonDriver(String pin, int keycode) throws IOException {
ButtonInputDriver driver = new ButtonInputDriver(pin, Button.LogicState.PRESSED_WHEN_LOW, keycode);
driver.register();
return driver;
}
示例11: setupButton
import com.google.android.things.contrib.driver.button.Button; //导入依赖的package包/类
private Button setupButton(String pin, Button.OnButtonEventListener buttonEventListener) throws IOException {
Button button = new Button(pin, Button.LogicState.PRESSED_WHEN_HIGH);
button.setDebounceDelay(BUTTON_DEBOUNCE_DELAY_MS);
button.setOnButtonEventListener(buttonEventListener);
return button;
}
示例12: OLEDBlock
import com.google.android.things.contrib.driver.button.Button; //导入依赖的package包/类
public OLEDBlock() throws IOException {
PeripheralManagerService peripheralManagerService = new PeripheralManagerService();
// Make sure GPIO is available for buttons
List<String> gpioList = peripheralManagerService.getGpioList();
if (gpioList.isEmpty()) {
Log.i(TAG, "No GPIO available on this device.");
throw new IOException("GPIO interface is require");
} else {
Log.i(TAG, "List of available GPIO : " + gpioList);
for ( int i = 0; i < GPIOButtons.length; i ++ ) {
if ( gpioList.contains(GPIOButtons[i]) == false )
Log.i(TAG, "GPIO "+GPIOButtons[i]+" is not available on this device.");
}
// SSD1306
if (gpioList.contains("GP14")== false )
Log.i(TAG, "GPIO GP14 is not available on this device.");
if (gpioList.contains("GP15")== false )
Log.i(TAG, "GPIO GP15 is not available on this device.");
}
// SPI will be use by SSD1306 OLED display
List<String> spiList = peripheralManagerService.getSpiBusList();
if (spiList.isEmpty()) {
Log.i(TAG, "No SPI available on this device.");
throw new IOException("SPI interface is require");
} else {
Log.i(TAG, "List of available SPI : " + spiList);
}
// Setup button
for ( int i = 0 ; i < GPIOButtons.length; i++ ) {
ButtonInputDriver buttonInputDriver = new ButtonInputDriver(GPIOButtons[i],
Button.LogicState.PRESSED_WHEN_LOW,
buttons[i] // the keycode to send
);
buttonInputDriver.register();
buttonInputDriverList.add(buttonInputDriver);
}
try {
ssd1306 = new SSD1306(spiList.get(0));
} catch (InterruptedException e) {
Log.e(TAG,"error",e);
throw new IOException("Unable to init SSD1306");
}
Log.i(TAG, "Completed init");
}
示例13: onButtonEvent
import com.google.android.things.contrib.driver.button.Button; //导入依赖的package包/类
@Override
public void onButtonEvent(Button button, boolean pressed) {
Log.i(BurglarAlarmConstants.LOG_TAG, "INPUT :" + pressed);
lastMotionState = pressed;
}
示例14: openButtonA
import com.google.android.things.contrib.driver.button.Button; //导入依赖的package包/类
public static Button openButtonA() throws IOException {
return openButton(BOARD.getButtonA());
}
示例15: openButtonB
import com.google.android.things.contrib.driver.button.Button; //导入依赖的package包/类
public static Button openButtonB() throws IOException {
return openButton(BOARD.getButtonB());
}