Skip to content

Commit 50ce4fd

Browse files
committed
Changed read8 and read16 to use unsigned I2C methods and removed autogain hack
1 parent 3f3979f commit 50ce4fd

File tree

2 files changed

+34
-10
lines changed

2 files changed

+34
-10
lines changed

.idea/dictionaries/iainc.xml

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Adafruit_TSL2561/Adafruit_TSL2561.py

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,24 @@
1414
#
1515
# Changes by Iain Colledge
1616
#
17-
# Removed commented out C++ code
18-
# Added calculateAvgLux
19-
# Changed main method to use calculateAvgLux and loop argument support added.
20-
# Ported "Extended delays to take into account loose timing with 'delay'" update from CPP code
21-
# Added hack so that with autogain every sample goes from 1x to 16x as going from 16x to 1x does not work
17+
2218
#
2319
# This was checked against a 10 UKP lux meter from Amazon and was withing 10% up and down the range, the meter
2420
# had a stated accuracy of 5% but then again, 10 UKP meter.
2521
#
22+
# Changelog:
23+
#
24+
# 1.1 - Fixes from https://forums.adafruit.com/viewtopic.php?f=8&t=34922&p=430795#p430782 - Iain Colledge
25+
# Bug #1: The class name has the middle two digits transposed - Adafruit_TSL2651 should be Adafruit_TSL2561
26+
# Bug #2: The read8 and read16 methods (functions) call the I2C readS8 and readS16 methods respectively.
27+
# They should call the readU8 and readU16 (i.e. unsigned) methods.
28+
# 1.0 - Initial release - Iain Colledge
29+
# Removed commented out C++ code
30+
# Added calculateAvgLux
31+
# Changed main method to use calculateAvgLux and loop argument support added.
32+
# Ported "Extended delays to take into account loose timing with 'delay'" update from CPP code
33+
# Added hack so that with autogain every sample goes from 1x to 16x as going from 16x to 1x does not work
34+
#
2635

2736
import sys
2837
import time
@@ -164,15 +173,15 @@ def write8 (self, reg, value):
164173
#**************************************************************************/
165174
def read8(self, reg):
166175
if (self._debug == True): print "read8"
167-
return self._i2c.readS8(reg)
176+
return self._i2c.readU8(reg)
168177
if (self._debug == True): print "read8_end"
169178

170179
#**************************************************************************/
171180
# Reads a 16 bit values over I2C
172181
#**************************************************************************/
173182
def read16(self, reg):
174183
if (self._debug == True): print "read16"
175-
return self._i2c.readS16(reg)
184+
return self._i2c.readU16(reg)
176185
if (self._debug == True): print "read16_end"
177186

178187
#**************************************************************************/
@@ -322,8 +331,8 @@ def getLuminosity (self):
322331
# This is a hack to ensure that when looping with autogain the gain can go up and down as without
323332
# setting the gain to 1X before every reading it doesn't seem able to go from 16X
324333
# back to 1X again. Going from 1X to 16X works fine. - IC
325-
if (self._tsl2561AutoGain):
326-
self.setGain(self.TSL2561_GAIN_1X)
334+
# if (self._tsl2561AutoGain):
335+
# self.setGain(self.TSL2561_GAIN_1X)
327336

328337
if (self._debug == True): print "getLuminosity"
329338
valid = False
@@ -409,7 +418,7 @@ def calculateLux(self):
409418
chScale = (1 << self.TSL2561_LUX_CHSCALE)
410419

411420
# Scale for gain (1x or 16x) */
412-
if (not self._tsl2561Gain):
421+
if (not self._tsl2561Gain):
413422
chScale = chScale << 4
414423

415424
# Scale the channel values */

0 commit comments

Comments
 (0)