-
Notifications
You must be signed in to change notification settings - Fork 108
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
Improve error handling #26
Comments
Maybe there is another flaw: If we use H-Resolution Mode2 we get a 0.5 resolution. Therefore we need a float as return value. And in that case we could use negative numbers |
I added an else-path at BH1750.cpp:183 Wire.reset(); Without this the I2C bus was held down forever. It took me some hours Here is the PR |
Any issue left or should this topic be closed? |
The problem highlighted in this issue is pretty unlikely and has never been reported before so is likely very low priority.
When reading a light value there is a possibility that the data read is not the expected 2 bytes. The implementation assumes that 2 bytes are read, even if they are not, and continues progressing through the function which could then use garbage data in the uninitialised
level
variable.Only a happy path is really accommodated for in the implementation and Arduino does not seem to really support error handling (e.g. exceptions). Perhaps we could consider returning a negative number to signal an error - though the existing return value type does not support that. Perhaps in this condition it could return 65535 which is well above the maximum possible lux value (which is raw/1.2 = 54612).
The text was updated successfully, but these errors were encountered: