Skip to content

Commit

Permalink
Merge pull request #114 from pimoroni/patch-cap12xx-i2c-addr-select
Browse files Browse the repository at this point in the history
cap1xxx - add support to specify alternate i2c address (#111)
  • Loading branch information
devunwired authored Sep 20, 2018
2 parents 647b5ed + 58c1bc1 commit aa3209b
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down Expand Up @@ -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
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
*/
Expand Down

0 comments on commit aa3209b

Please sign in to comment.