From 6aec8b6d7fabb574593fd91fa8d5873a115f7177 Mon Sep 17 00:00:00 2001 From: Jerry Needell Date: Fri, 22 Dec 2017 14:23:59 -0500 Subject: [PATCH 1/2] revise lux calculation to accept 0 reading without error --- adafruit_tsl2561.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/adafruit_tsl2561.py b/adafruit_tsl2561.py index fe0ec9a..6dbe936 100644 --- a/adafruit_tsl2561.py +++ b/adafruit_tsl2561.py @@ -148,15 +148,15 @@ def _compute_lux(self): if ch1 > _CLIP_THRESHOLD[self.integration_time]: return None ratio = ch1 / ch0 - if ratio > 0 and ratio <= 0.50: + if ratio >= 0 and ratio <= 0.50: lux = 0.0304 * ch0 - 0.062 * ch0 * ratio**1.4 - elif ratio > 0.50 and ratio <= 0.61: + elif ratio <= 0.61: lux = 0.0224 * ch0 - 0.031 * ch1 - elif ratio > 0.61 and ratio <= 0.80: + elif ratio <= 0.80: lux = 0.0128 * ch0 - 0.0153 * ch1 - elif ratio > 0.80 and ratio <= 1.30: + elif ratio <= 1.30: lux = 0.00146 * ch0 - 0.00112 * ch1 - elif ratio > 1.30: + else : lux = 0 # Pretty sure the floating point math formula on pg. 23 of datasheet # is based on 16x gain and 402ms integration time. Need to scale From 127ec4ca53749f710bee8145e265a9f2a3202802 Mon Sep 17 00:00:00 2001 From: Jerry Needell Date: Fri, 22 Dec 2017 14:32:50 -0500 Subject: [PATCH 2/2] fix whitespace for pylint --- adafruit_tsl2561.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_tsl2561.py b/adafruit_tsl2561.py index 6dbe936..376a913 100644 --- a/adafruit_tsl2561.py +++ b/adafruit_tsl2561.py @@ -156,7 +156,7 @@ def _compute_lux(self): lux = 0.0128 * ch0 - 0.0153 * ch1 elif ratio <= 1.30: lux = 0.00146 * ch0 - 0.00112 * ch1 - else : + else: lux = 0 # Pretty sure the floating point math formula on pg. 23 of datasheet # is based on 16x gain and 402ms integration time. Need to scale