Search in sources :

Example 1 with LynxI2cWriteSingleByteCommand

use of com.qualcomm.hardware.lynx.commands.core.LynxI2cWriteSingleByteCommand in project robotcode by OutoftheBoxFTC.

the class LynxI2cDeviceSynch method internalWrite.

private void internalWrite(int ireg, byte[] data, final I2cWaitControl waitControl) {
    if (// paranoia, but safe
    data.length > 0) {
        // For register-based I2c devices: convention: first byte in a write is the initial register number
        byte[] payload = Util.concatenateByteArrays(new byte[] { (byte) ireg }, data);
        // We use the single-byte case when we can out of paranoia about the LynxI2cWriteMultipleBytesCommand
        // not being able to handle a byte count of one (that has not been verified with the firmware
        // programmers, but the corresponding read case has been)
        final LynxCommand<?> writeTx = payload.length == 1 ? new LynxI2cWriteSingleByteCommand(this.getModule(), this.bus, this.i2cAddr, payload[0]) : new LynxI2cWriteMultipleBytesCommand(this.getModule(), this.bus, this.i2cAddr, payload);
        try {
            acquireI2cLockWhile(new Supplier<Object>() {

                @Override
                public Object get() throws InterruptedException, RobotCoreException, LynxNackException {
                    sendI2cWriteTx(writeTx);
                    internalWaitForWriteCompletions(waitControl);
                    return null;
                }
            });
        } catch (InterruptedException | LynxNackException | RobotCoreException | RuntimeException e) {
            handleException(e);
        }
    }
}
Also used : LynxI2cWriteSingleByteCommand(com.qualcomm.hardware.lynx.commands.core.LynxI2cWriteSingleByteCommand) RobotCoreException(com.qualcomm.robotcore.exception.RobotCoreException) LynxI2cWriteMultipleBytesCommand(com.qualcomm.hardware.lynx.commands.core.LynxI2cWriteMultipleBytesCommand)

Aggregations

LynxI2cWriteMultipleBytesCommand (com.qualcomm.hardware.lynx.commands.core.LynxI2cWriteMultipleBytesCommand)1 LynxI2cWriteSingleByteCommand (com.qualcomm.hardware.lynx.commands.core.LynxI2cWriteSingleByteCommand)1 RobotCoreException (com.qualcomm.robotcore.exception.RobotCoreException)1