readWord method

int readWord(
  1. int address, [
  2. BitOrder order = BitOrder.msbLast
])

Reads a word from the I2C device with the address and the bit order].

Some I2C devices can directly be written without an explicit register. The bit order depends on the I2C device.

Implementation

int readWord(int address, [BitOrder order = BitOrder.msbLast]) {
  var data = <I2Cmsg>[];
  data.add(I2Cmsg(address, [I2CmsgFlags.i2c_m_rd], 2));
  var result = transfer(data);
  try {
    var ptr = result._messages[0].buf;
    var value = (ptr[(order == BitOrder.msbLast ? 0 : 1)] & 0xff) |
        (ptr[(order == BitOrder.msbLast ? 1 : 0)] & 0xff) << 8;
    return value;
  } finally {
    result.dispose();
  }
}