Hi jeff, that looks very useful.
one suggestion is to add a timeout property to the library so calls want hang if the I2C device does not respond. Perhaps something like this:
uint8_t count = 0;
Wire.beginTransmission(devAddr);
Wire.send(regAddr);
Wire.endTransmission();
Wire.beginTransmission(devAddr);
Wire.requestFrom(devAddr, length); // request length bytes from device
unsigned long readStart = millis();
do
{
if(Wire.available() >= length ) {
for (; Wire.available(); count++) {
data[count] = Wire.receive();
#ifdef I2CDEV_SERIAL_DEBUG
Serial.print(data[count], HEX);
Serial.print(" ");
#endif
}
}
}
while(millis() - readStart < timeout); //wait up to timeout period reading
Wire.endTransmission();
You would want to inform the caller of a timeout, for example return 0 if the code times out.