@@ -70,10 +70,6 @@ class TSL2561(object):
70
70
* integrationTime - The integration time in milliseconds for a sensor
71
71
reading. See the `integrationTime` class property for more information
72
72
and acceptable values. Defaults to 402.
73
- * package - A string indicating which TSL2561 package is in use. Takes one
74
- of two values:
75
- * 'T' - TMB package. This is the default.
76
- * 'CS' - Chipscale package.
77
73
* debug - Controls whether additional debugging information is printed as
78
74
the class performs its functions. Defaults to False.
79
75
@@ -158,17 +154,44 @@ def reset_sensor(cls, address):
158
154
TSL2561 ._REGISTER ['CONTROL' ] | TSL2561 ._REG_MOD ['COMMAND' ],
159
155
TSL2561 ._CONTROL ['OFF' ])
160
156
161
- def __init__ (self , address = ADDR_FLOAT , mode = MODE_CONTINUOUS , gain = _gain , integrationTime = _integrationTime .key , package = 'T' , debug = False ):
157
+ def __init__ (self , address = ADDR_FLOAT , mode = MODE_CONTINUOUS , gain = _gain , integrationTime = _integrationTime .key , debug = False ):
162
158
if mode not in self ._MODES :
163
159
raise ValueError ('Incorrect value passed as operating mode.' )
164
160
if not address in [TSL2561 .ADDR_LOW , TSL2561 .ADDR_FLOAT , TSL2561 .ADDR_HIGH ]:
165
161
addr_msg = '0x{0:x} is not a standard TSL2561 address; continuing anyway' .format (address )
166
162
warnings .warn (addr_msg )
167
163
self .debug = debug
168
164
self ._i2c = Adafruit_I2C (address , debug = debug )
165
+ # The datasheet says that the ID register has a product identifier in
166
+ # bits 4-7 and a revision number in bits 0-3. Testing on my (PMG)
167
+ # sensor indicates that the bits are completely reversed. I get a value
168
+ # of 0x0A (0b00001010) for my TSL2561T when the datasheet says I should
169
+ # get 0x50 (0b01010000). The Adafruit Arduino code also checks for
170
+ # 0x0A, so the datasheet is probably just wrong.
171
+ # Additionally, the even though the datasheet says the ID register never
172
+ # changes, it only appears to return the product identifier if the
173
+ # sensor is powered off. If the sensor is on, the register returns
174
+ # 0x00. Consequently, if we get a 0x00 result (which is also what a
175
+ # TSL2560CS returns when it's off), we try turning the sensor off and
176
+ # reading the value again, just to check what we're talking to.
169
177
id = self ._i2c .readU8 (TSL2561 ._REGISTER ['ID' ])
170
- if id < 0 or not id & 0x0A :
178
+ if id == 0 :
179
+ self ._poweroff ()
180
+ id = self ._i2c .readU8 (TSL2561 ._REGISTER ['ID' ])
181
+ if id < 0 :
182
+ raise EnvironmentError , 'Device at 0x{0:x} does not appear to be a TSL2561.' .format (address )
183
+ elif id & 0x0F in (0x0A , 0x02 ):
184
+ # 0x0A - TSL2561T
185
+ # 0x02 - TSL2560T
186
+ package = 'T'
187
+ elif id & 0x0F in (0x08 , 0x00 ):
188
+ # 0x08 - TSL2561CS
189
+ # 0x00 - TSL2560CS
190
+ package = 'CS'
191
+ else :
171
192
raise EnvironmentError , 'Device at 0x{0:x} does not appear to be a TSL2561.' .format (address )
193
+ if self .debug :
194
+ print 'Device uses "{0}" packaging.' .format (package )
172
195
173
196
self .mode = mode
174
197
if self .mode == TSL2561 .MODE_CONTINUOUS :
0 commit comments