From 4325e74a391e5c79a9fb19f4a0c210c5fc7ccd36 Mon Sep 17 00:00:00 2001 From: zYeoman Date: Thu, 1 Sep 2016 06:31:11 +0000 Subject: [PATCH] Fix Bug: Wrong use of integration time --- tsl2561/tsl2561.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/tsl2561/tsl2561.py b/tsl2561/tsl2561.py index ccf2512..06f7032 100644 --- a/tsl2561/tsl2561.py +++ b/tsl2561/tsl2561.py @@ -15,7 +15,7 @@ from __future__ import absolute_import import time from Adafruit_GPIO import I2C -from .constants import * # pylint: disable=unused-wildcard-import +from constants import * # pylint: disable=unused-wildcard-import __author__ = 'Georges Toth ' __credits__ = ['K.Townsend (Adafruit Industries)'] @@ -33,7 +33,7 @@ class TSL2561(object): '''Driver for the TSL2561 digital luminosity (light) sensors.''' def __init__(self, address=None, busnum=None, - integration_time=TSL2561_DELAY_INTTIME_402MS, + integration_time=TSL2561_INTEGRATIONTIME_402MS, gain=TSL2561_GAIN_1X, autogain=False, debug=False): if address is not None: self.address = address @@ -47,6 +47,12 @@ def __init__(self, address=None, busnum=None, self.gain = gain self.autogain = autogain + if self.integration_time == TSL2561_INTEGRATIONTIME_402MS: + self.delay_time = TSL2561_DELAY_INTTIME_402MS + elif self.integration_time == TSL2561_INTEGRATIONTIME_101MS: + self.delay_time = TSL2561_DELAY_INTTIME_101MS + elif self.integration_time == TSL2561_INTEGRATIONTIME_13MS: + self.delay_time = TSL2561_DELAY_INTTIME_13MS self._begin() def _begin(self): @@ -92,7 +98,7 @@ def _get_data(self): self.enable() # Wait x ms for ADC to complete - TSL2561.delay(self.integration_time) + TSL2561.delay(self.delay_time) # Reads a two byte value from channel 0 (visible + infrared) broadband = self.i2c.readU16(TSL2561_COMMAND_BIT | TSL2561_WORD_BIT |