Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Bug: Wrong use of integration time #4

Merged
merged 1 commit into from
Jan 4, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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