Adafruit_TSL2591_Library
Adafruit_TSL2591_Library copied to clipboard
Fix possible division by zero
Adafruit_TSL2591::calculateLux function: It's dangerous in case ch0 is 0! In case it is 0 use the next greater number 1 for the formula, which should least falsify the calculated result.
I got a lot inf in late night, this fix is necessary.
Recreated issue using library example: https://github.com/adafruit/Adafruit_TSL2591_Library/blob/master/examples/tsl2591/tsl2591.ino and setting gain and integration time to lowest settings.
In dim light with finger over sensor:
Just to point out, the lux calculation for this sensor is a point of on going discussion: https://github.com/adafruit/Adafruit_TSL2591_Library/issues/14 with the current assessment that it should be taken as a nominal lux value.
Would a better behavior here be just to return 0 for lux if the ch0 value is 0 (or below some low threshold)?
It also looks like #42 is an attempt to fix this same behavior.
Ha, some progress after +2years! Thx @DeqingSun
@caternuson It's....not.....the most frequent discussion in #14 :-D I think the result is that the current implementation is not good but there is no better one. This is not a good thing.
OK, we can still improve the current low light behavior. I'd suggest checking the values and returning 0 instead of altering the value so it's not dividing by zero.
No progress here?