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

Improve error handling #26

Open
claws opened this issue Dec 29, 2017 · 4 comments
Open

Improve error handling #26

claws opened this issue Dec 29, 2017 · 4 comments

Comments

@claws
Copy link
Owner

claws commented Dec 29, 2017

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).

@coelner
Copy link
Contributor

coelner commented Jan 5, 2018

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

@bjung82
Copy link

bjung82 commented Feb 26, 2018

I added an else-path at BH1750.cpp:183
with

Wire.reset();

Without this the I2C bus was held down forever. It took me some hours
because the problem was not easily reproducible.

Here is the PR
#41

@coelner
Copy link
Contributor

coelner commented Feb 28, 2018

@bjung82 explanation @ #41

@coelner
Copy link
Contributor

coelner commented Oct 25, 2018

Any issue left or should this topic be closed?

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

No branches or pull requests

3 participants