Seeed-Studio / Grove_Digital_Light_Sensor

TSL2561 & ISL29035
MIT License
13 stars 14 forks source link

Add an optional read timout to the TSL2561_CalculateLux class #7

Open Abestanis opened 2 years ago

Abestanis commented 2 years ago

This allows not to loop endlessly and to detect not responding light sensors. Closes #5.

This change is backwards compatible, because by default the timeout is disabled. ~The only incompatible change is the undefinition of the max macro in the header, which was required to get the value for the TSL2561_NO_READ_TIMEOUT macro.~ ~We could get around that problem by not including <Arduino.h> and include <cstdint> instead. That could also be a breaking change if someone relied on the implicit import of the <Arduino.h> header, but I think it would be the better solution here. What's your opinion on this?~

I noticed that the availability check for the ISL29035 is commented out: https://github.com/Seeed-Studio/Grove_Digital_Light_Sensor/blob/69f7175ed1349276364994d1d45041c6e90a129b/Digital_Light_ISL29035.cpp#L59 Therefore I didn't add a timeout for that class. But if you want to have a loop with a timeout for the ISL29035 as well, we could add a common base class and put the timeout functionality in there. What do you think?

Abestanis commented 2 years ago

Also, do you prefer the timeout parameter to be in the init function?

LynnL4 commented 2 years ago

Hi, How about not enabling timeout when timeout=0。 This is how most timeout mechanisms are designed, so that is not needed.

Abestanis commented 2 years ago

How about not enabling timeout when timeout=0

Good idea, done.

Abestanis commented 1 year ago

Hey @lakshanthad, sorry to ping you but you said in #5 that you might review this. Is this blocked by anything?