Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Koepel opened this issue May 22, 2018 · 0 comments
Open

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

Koepel opened this issue May 22, 2018 · 0 comments

Comments

@Koepel
Copy link

Koepel commented May 22, 2018

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant