In the file "MPR121.cpp" in the function getRegister(), there is a Wire.endTransmission() directly after a Wire.requestFrom().
The Wire.endTransmission() should only be used when writing data and only in combination with Wire.beginTransmission() and almost always with Wire.write().
To test if valid data was received, the return value could be used, as is done in the other functions. However the function getRegister() can not return a 'false' like the other function.
This is not okay:
Wire.requestFrom(address,(unsigned char)1); // just a single byte
if(Wire.endTransmission()!=0){
error |= 1<<ADDRESS_UNKNOWN_BIT;
} else {
error &= ~(1<<ADDRESS_UNKNOWN_BIT);
}
scratch = Wire.read();
Perhaps this is better:
if(Wire.requestFrom(address,(unsigned char)1) == 1){ // just a single byte
error &= ~(1<<ADDRESS_UNKNOWN_BIT);
scratch = Wire.read();
} else {
error |= 1<<ADDRESS_UNKNOWN_BIT;
}
But I'm not sure if that is how you want to deal with an error.
In the file "MPR121.cpp" in the function getRegister(), there is a Wire.endTransmission() directly after a Wire.requestFrom().
The Wire.endTransmission() should only be used when writing data and only in combination with Wire.beginTransmission() and almost always with Wire.write().
To test if valid data was received, the return value could be used, as is done in the other functions. However the function getRegister() can not return a 'false' like the other function.
This is not okay:
Perhaps this is better:
But I'm not sure if that is how you want to deal with an error.