LVMakerHub / LINX

LabVIEW Community Edition LINX
Other
109 stars 114 forks source link

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

Open Koepel opened 6 years ago

Koepel commented 6 years ago

The file "LinxWiringDevice.cpp" is used about 16 times in this repository. In the function i2cRead() there is waiting with and a timeout with millis(). You may remove that. Explanation: Common-mistakes#1

You may delete this part:

//Wait For Data, Potentially Timeout
unsigned long tickCount = millis();
while(Wire.available() < numBytes)
{
    if( (millis() - tickCount) > timeout)
    {
        return LI2C_READ_FAIL;
    }
}

It is possible to add a check for the number of received bytes. Since you do not check the return value of Wire.endTransmission(), there is no need to check the number of received bytes. But if you want to do that, you could do this:

if( Wire.available() != numBytes)
{
  return LI2C_READ_FAIL;
}

Do you think that there is someone who still uses a very old Arduino version before 1.00 ? I think you can remove that from the code.