diff --git a/cap1xxx/src/main/java/com/google/android/things/contrib/driver/cap1xxx/Cap1xxx.java b/cap1xxx/src/main/java/com/google/android/things/contrib/driver/cap1xxx/Cap1xxx.java index da56482..296ba5f 100644 --- a/cap1xxx/src/main/java/com/google/android/things/contrib/driver/cap1xxx/Cap1xxx.java +++ b/cap1xxx/src/main/java/com/google/android/things/contrib/driver/cap1xxx/Cap1xxx.java @@ -89,7 +89,7 @@ public enum Configuration { /** * Default I2C slave address for the CAP1xxx family. */ - public static final int I2C_ADDRESS = 0x28; + public static final int DEFAULT_I2C_ADDRESS = 0x28; @Retention(RetentionPolicy.SOURCE) @IntDef({REPEAT_DISABLE, REPEAT_FAST, REPEAT_NORMAL, REPEAT_SLOW}) @@ -192,7 +192,7 @@ public Cap1xxx(Context context, String i2cName, String alertName, Configuration } /** - * Create a new Cap1xxx controller. + * Create a new Cap1xxx controller with the default I2C address. * * @param i2cName I2C port name where the controller is attached. Cannot be null. * @param alertName optional GPIO pin name connected to the controller's @@ -213,22 +213,38 @@ public Cap1xxx(Context context, String i2cName, String alertName, Configuration this(i2cName, alertName, chip, handler); } + /** + * Create a new Cap1xxx controller with the default I2C address. + * + * @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 Cap1xxx(String i2cName, String alertName, Configuration chip, Handler handler) throws IOException { + this(i2cName, DEFAULT_I2C_ADDRESS, alertName, chip, handler); + } + /** * Create a new Cap1xxx controller. * * @param i2cName I2C port name where the controller is attached. Cannot be null. + * @param i2cAddress 7-bit I2C address for the attached controller. * @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 Cap1xxx(String i2cName, String alertName, Configuration chip, Handler handler) + + public Cap1xxx(String i2cName, int i2cAddress, String alertName, Configuration chip, Handler handler) throws IOException { mChipConfiguration = chip; try { PeripheralManager manager = PeripheralManager.getInstance(); - I2cDevice device = manager.openI2cDevice(i2cName, I2C_ADDRESS); + I2cDevice device = manager.openI2cDevice(i2cName, i2cAddress); Gpio alertPin = null; if (alertName != null) { alertPin = manager.openGpio(alertName); diff --git a/cap1xxx/src/main/java/com/google/android/things/contrib/driver/cap1xxx/Cap1xxxInputDriver.java b/cap1xxx/src/main/java/com/google/android/things/contrib/driver/cap1xxx/Cap1xxxInputDriver.java index 6b8f2f2..d3b026f 100644 --- a/cap1xxx/src/main/java/com/google/android/things/contrib/driver/cap1xxx/Cap1xxxInputDriver.java +++ b/cap1xxx/src/main/java/com/google/android/things/contrib/driver/cap1xxx/Cap1xxxInputDriver.java @@ -83,8 +83,8 @@ public Cap1xxxInputDriver(Context context, String i2cName, String alertName, Con } /** - * Create a new Cap1xxxInputDriver to forward capacitive touch events to the Android input - * framework. + * Create a new Cap1xxxInputDriver with the default I2C address to forward capacitive touch + * events to the Android input framework. * * @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. @@ -100,6 +100,25 @@ public Cap1xxxInputDriver(String i2cName, String alertName, Configuration chip, init(peripheral, keyCodes); } + /** + * Create a new Cap1xxxInputDriver to forward capacitive touch events to the Android input + * framework. + * + * @param i2cName I2C port name where the controller is attached. Cannot be null. + * @param i2cAddress 7-bit I2C address for the attached controller. + * @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. + * @param keyCodes {@link KeyEvent} codes to be emitted for each input channel. Length must + * match the input channel count of the Configuration {@code chip}. + */ + public Cap1xxxInputDriver(String i2cName, int i2cAddress, String alertName, Configuration chip, Handler handler, + int[] keyCodes) throws IOException { + Cap1xxx peripheral = new Cap1xxx(i2cName, i2cAddress, alertName, chip, handler); + init(peripheral, keyCodes); + } + /** * Constructor invoked from unit tests. */