Merge pull request #20 from mvn23/mvn23-patch-1

Fix negative lux value check.
This commit is contained in:
Limor "Ladyada" Fried
2019-07-18 11:45:53 -04:00
committed by GitHub

View File

@ -443,10 +443,12 @@ uint32_t Adafruit_TSL2561_Unified::calculateLux(uint16_t broadband, uint16_t ir)
#endif
unsigned long temp;
temp = ((channel0 * b) - (channel1 * m));
channel0 = channel0 * b;
channel1 = channel1 * m;
temp = 0;
/* Do not allow negative lux value */
if (temp < 0) temp = 0;
if (channel0 > channel1) temp = channel0 - channel1;
/* Round lsb (2^(LUX_SCALE-1)) */
temp += (1 << (TSL2561_LUX_LUXSCALE-1));