ferguman / openag-firmware

OpenAg firmware with diagnostics and alternative sensor and actuator configurabilty.
GNU General Public License v3.0
1 stars 0 forks source link

No need to wait after Wire.requestFrom(). #1

Closed Koepel closed 6 years ago

Koepel commented 6 years ago

In the file "openag-firmware/lib/tsl2561/tsl2561.cpp", there is a timeout with millis() in the function "readRegister()". You may remove that. Explanation: Common-mistakes#1

The returned error code from Wire.endTransmission() is not handled, therefor you might read data without checking for errors as well. But if you still want to check if data was received, you could do this:

  Wire.requestFrom(deviceAddress, 1); // read a byte
  if (Wire.available() != 1) {
    return 0;
  }
  value = Wire.read();
  return value;
ferguman commented 6 years ago

I've updated the code to incorporate your comments above. Much thanks!