如何使用AndroidThings初始化Cap12xxInputDriver?

时间:2017-04-29 20:44:29

标签: android-things

我已经克隆了电容式触摸的androidthings示例: https://github.com/androidthings/drivers-samples/tree/master/cap12xx

以下内容用于初始化驱动程序:

04-29 20:33:45.159 1238-1238/? W/CaptouchActivity: Unable to open driver connection
com.google.android.things.pio.PioException: android.os.ServiceSpecificException: I/O error
at com.google.android.things.pio.I2cDevice.writeRegByte(I2cDevice.java:198)
at com.google.android.things.contrib.driver.cap12xx.Cap12xx.setInputsEnabled(Cap12xx.java:418)
at com.google.android.things.contrib.driver.cap12xx.Cap12xx.init(Cap12xx.java:241)
at com.google.android.things.contrib.driver.cap12xx.Cap12xx.<init>(Cap12xx.java:188)
at com.google.android.things.contrib.driver.cap12xx.Cap12xxInputDriver.<init>(Cap12xxInputDriver.java:92)
at com.google.android.things.contrib.driver.cap12xx.Cap12xxInputDriver.<init>(Cap12xxInputDriver.java:69)
at com.example.androidthings.driversamples.CaptouchActivity.onCreate(CaptouchActivity.java:51)
at android.app.Activity.performCreate(Activity.java:6662)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2599)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
Caused by: android.os.ServiceSpecificException: I/O error
at android.os.Parcel.readException(Parcel.java:1697)
at android.os.Parcel.readException(Parcel.java:1636)
at com.google.android.things.pio.IPeripheralManagerClient$Stub$Proxy.I2cWriteRegByte(IPeripheralManagerClient.java:1517)
at com.google.android.things.pio.I2cDevice.writeRegByte(I2cDevice.java:196)
at com.google.android.things.contrib.driver.cap12xx.Cap12xx.setInputsEnabled(Cap12xx.java:418) 
at com.google.android.things.contrib.driver.cap12xx.Cap12xx.init(Cap12xx.java:241) 
at com.google.android.things.contrib.driver.cap12xx.Cap12xx.<init>(Cap12xx.java:188) 
at com.google.android.things.contrib.driver.cap12xx.Cap12xxInputDriver.<init>(Cap12xxInputDriver.java:92) 
at com.google.android.things.contrib.driver.cap12xx.Cap12xxInputDriver.<init>(Cap12xxInputDriver.java:69) 
at com.example.androidthings.driversamples.CaptouchActivity.onCreate(CaptouchActivity.java:51) 
at android.app.Activity.performCreate(Activity.java:6662) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2599) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707) 
at android.app.ActivityThread.-wrap12(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:154) 
at android.app.ActivityThread.main(ActivityThread.java:6077) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755) 

当它被击中时,我得到一个例外,如下所示。我不确定我做错了什么或如何解决这个问题,因为我无法看到I2cDevice类中发生了什么。硬件设置是安装在Raspberry Pi Model 3 B中的RainbowHAT。显示,温度,压力和LED工作正常。

如何初始化Cap12xxInputDriver?

{{1}}

2 个答案:

答案 0 :(得分:2)

与Devunwired一样,Rainbow HAT电容式按钮通过GPIO显示。它们非常易于使用。

您可以在此处找到密码:Technical Reference - 3 Touch Inputs via AT42QT1070

如何在此处使用触摸按钮:https://github.com/blundell/androidthings-gpio-input

以下是在活动中使用彩虹帽上的电容按钮A的示例:

public class MainActivity extends Activity {

    private static final String TOUCH_BUTTON_A_PIN = "BCM21";

    private Gpio bus;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        PeripheralManager service = PeripheralManager.newInstance();

        try {
            bus = service.openGpio(TOUCH_BUTTON_A_PIN);
        } catch (IOException e) {
            throw new IllegalStateException(TOUCH_BUTTON_A_PIN + " bus cannot be opened.", e);
        }

        try {
            bus.setDirection(Gpio.DIRECTION_IN);
            bus.setActiveType(Gpio.ACTIVE_LOW);
        } catch (IOException e) {
            throw new IllegalStateException(TOUCH_BUTTON_A_PIN + " bus cannot be configured.", e);
        }
    }

    @Override
    protected void onStart() {
        super.onStart();
        try {
            bus.setEdgeTriggerType(Gpio.EDGE_BOTH);
            bus.registerGpioCallback(touchButtonACallback);
        } catch (IOException e) {
            throw new IllegalStateException(TOUCH_BUTTON_A_PIN + " bus cannot be monitored.", e);
        }
    }

    private final GpioCallback touchButtonACallback = new GpioCallback() {
        @Override
        public boolean onGpioEdge(Gpio gpio) {
            try {
                if (gpio.getValue()) {
                    Log.i("TUT", "ON PRESSED DOWN");
                } else {
                    Log.i("TUT", "ON PRESSED UP");
                }
            } catch (IOException e) {
                throw new IllegalStateException(TOUCH_BUTTON_A_PIN + " cannot be read.", e);
            }
            return true;
        }
    };

    @Override
    protected void onStop() {
        bus.unregisterGpioCallback(touchButtonACallback);
        super.onStop();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        try {
            bus.close();
        } catch (IOException e) {
            Log.e("TUT", TOUCH_BUTTON_A_PIN + " bus cannot be closed, you may experience errors on next launch.", e);
        }
    }
}

答案 1 :(得分:0)

Rainbow HAT上没有CAP1208芯片,因此尝试初始化I2C总线上的芯片会在开始写入init命令时抛出错误,因为设备不存在。 Rainbow HAT上的电容式按钮在内部进行管理,并作为纯GPIO引脚公开。

如果您想体验CAP12xx系列的上限功能,可以试试Raspberry Pi的Explorer HAT Pro