|
14 | 14 | #
|
15 | 15 | # Changes by Iain Colledge
|
16 | 16 | #
|
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 | + |
22 | 18 | #
|
23 | 19 | # This was checked against a 10 UKP lux meter from Amazon and was withing 10% up and down the range, the meter
|
24 | 20 | # had a stated accuracy of 5% but then again, 10 UKP meter.
|
25 | 21 | #
|
| 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 | +# |
26 | 35 |
|
27 | 36 | import sys
|
28 | 37 | import time
|
@@ -164,15 +173,15 @@ def write8 (self, reg, value):
|
164 | 173 | #**************************************************************************/
|
165 | 174 | def read8(self, reg):
|
166 | 175 | if (self._debug == True): print "read8"
|
167 |
| - return self._i2c.readS8(reg) |
| 176 | + return self._i2c.readU8(reg) |
168 | 177 | if (self._debug == True): print "read8_end"
|
169 | 178 |
|
170 | 179 | #**************************************************************************/
|
171 | 180 | # Reads a 16 bit values over I2C
|
172 | 181 | #**************************************************************************/
|
173 | 182 | def read16(self, reg):
|
174 | 183 | if (self._debug == True): print "read16"
|
175 |
| - return self._i2c.readS16(reg) |
| 184 | + return self._i2c.readU16(reg) |
176 | 185 | if (self._debug == True): print "read16_end"
|
177 | 186 |
|
178 | 187 | #**************************************************************************/
|
@@ -322,8 +331,8 @@ def getLuminosity (self):
|
322 | 331 | # This is a hack to ensure that when looping with autogain the gain can go up and down as without
|
323 | 332 | # setting the gain to 1X before every reading it doesn't seem able to go from 16X
|
324 | 333 | # 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) |
327 | 336 |
|
328 | 337 | if (self._debug == True): print "getLuminosity"
|
329 | 338 | valid = False
|
@@ -409,7 +418,7 @@ def calculateLux(self):
|
409 | 418 | chScale = (1 << self.TSL2561_LUX_CHSCALE)
|
410 | 419 |
|
411 | 420 | # Scale for gain (1x or 16x) */
|
412 |
| - if (not self._tsl2561Gain): |
| 421 | + if (not self._tsl2561Gain): |
413 | 422 | chScale = chScale << 4
|
414 | 423 |
|
415 | 424 | # Scale the channel values */
|
|
0 commit comments