Skip to content

Commit

Permalink
Merge pull request #4 from zYeoman/master
Browse files Browse the repository at this point in the history
Fix Bug: Wrong use of integration time
  • Loading branch information
sim0nx authored Jan 4, 2017
2 parents fefa172 + 4325e74 commit 7e7eb55
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions tsl2561/tsl2561.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 <[email protected]>'
__credits__ = ['K.Townsend (Adafruit Industries)']
Expand All @@ -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
Expand All @@ -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):
Expand Down Expand Up @@ -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 |
Expand Down

0 comments on commit 7e7eb55

Please sign in to comment.