Skip to content

"and" versus "&&" #1

Description

@Koepel

In the file "src/TCA95x5.cpp" there is a "and" in a if-statement instead of a "&&".

You test the Wire.available() for each byte. It is possible to do that once. I prefer to check if all the bytes are received by the Wire.requestFrom() function and only then read all the bytes. You have no check if the Wire.requestFrom() failed.

The code below is not better, only to show an alternative way. To check for I2C bus errors does not capture all bus problems, it is therefor trivial to check for all bus errors.

Wire.requestFrom(_device_address, uint8_t(length));
if (Wire.available() != length) {
  success = false;
} else {
  for (size_t i = 0; i < length; i++) {
    output[i] = (uint8_t) Wire.read();
  }
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions