Skip to content

Commit 1a61196

Browse files
committed
Remove trailing / on comments and added space after = on constant definitions at start of class
1 parent 947c96a commit 1a61196

File tree

1 file changed

+104
-104
lines changed

1 file changed

+104
-104
lines changed

Adafruit_TSL2561/Adafruit_TSL2561.py

Lines changed: 104 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -38,97 +38,97 @@
3838
from Adafruit_I2C import Adafruit_I2C
3939

4040
class Adafruit_TSL2561(Adafruit_I2C):
41-
TSL2561_VISIBLE =2 # channel 0 - channel 1
42-
TSL2561_INFRARED =1 # channel 1
43-
TSL2561_FULLSPECTRUM =0 # channel 0
41+
TSL2561_VISIBLE = 2 # channel 0 - channel 1
42+
TSL2561_INFRARED = 1 # channel 1
43+
TSL2561_FULLSPECTRUM = 0 # channel 0
4444

4545
# I2C address options
46-
TSL2561_ADDR_LOW =0x29
47-
TSL2561_ADDR_FLOAT =0x39 # Default address (pin left floating)
48-
TSL2561_ADDR_HIGH =0x49
46+
TSL2561_ADDR_LOW = 0x29
47+
TSL2561_ADDR_FLOAT = 0x39 # Default address (pin left floating)
48+
TSL2561_ADDR_HIGH = 0x49
4949

5050
# Lux calculations differ slightly for CS package
51-
TSL2561_PACKAGE_CS =0
52-
TSL2561_PACKAGE_T_FN_CL =1
51+
TSL2561_PACKAGE_CS = 0
52+
TSL2561_PACKAGE_T_FN_CL = 1
5353

54-
TSL2561_COMMAND_BIT =0x80 # Must be 1
55-
TSL2561_CLEAR_BIT =0x40 # Clears any pending interrupt (write 1 to clear)
56-
TSL2561_WORD_BIT =0x20 # 1 = read/write word (rather than byte)
57-
TSL2561_BLOCK_BIT =0x10 # 1 = using block read/write
54+
TSL2561_COMMAND_BIT = 0x80 # Must be 1
55+
TSL2561_CLEAR_BIT = 0x40 # Clears any pending interrupt (write 1 to clear)
56+
TSL2561_WORD_BIT = 0x20 # 1 = read/write word (rather than byte)
57+
TSL2561_BLOCK_BIT = 0x10 # 1 = using block read/write
5858

59-
TSL2561_CONTROL_POWERON =0x03
60-
TSL2561_CONTROL_POWEROFF =0x00
59+
TSL2561_CONTROL_POWERON = 0x03
60+
TSL2561_CONTROL_POWEROFF = 0x00
6161

62-
TSL2561_LUX_LUXSCALE =14 # Scale by 2^14
63-
TSL2561_LUX_RATIOSCALE =9 # Scale ratio by 2^9
64-
TSL2561_LUX_CHSCALE =10 # Scale channel values by 2^10
65-
TSL2561_LUX_CHSCALE_TINT0 =0x7517 # 322/11 * 2^TSL2561_LUX_CHSCALE
66-
TSL2561_LUX_CHSCALE_TINT1 =0x0FE7 # 322/81 * 2^TSL2561_LUX_CHSCALE
62+
TSL2561_LUX_LUXSCALE = 14 # Scale by 2^14
63+
TSL2561_LUX_RATIOSCALE = 9 # Scale ratio by 2^9
64+
TSL2561_LUX_CHSCALE = 10 # Scale channel values by 2^10
65+
TSL2561_LUX_CHSCALE_TINT0 = 0x7517 # 322/11 * 2^TSL2561_LUX_CHSCALE
66+
TSL2561_LUX_CHSCALE_TINT1 = 0x0FE7 # 322/81 * 2^TSL2561_LUX_CHSCALE
6767

6868
# T, FN and CL package values
69-
TSL2561_LUX_K1T =0x0040 # 0.125 * 2^RATIO_SCALE
70-
TSL2561_LUX_B1T =0x01f2 # 0.0304 * 2^LUX_SCALE
71-
TSL2561_LUX_M1T =0x01be # 0.0272 * 2^LUX_SCALE
72-
TSL2561_LUX_K2T =0x0080 # 0.250 * 2^RATIO_SCALE
73-
TSL2561_LUX_B2T =0x0214 # 0.0325 * 2^LUX_SCALE
74-
TSL2561_LUX_M2T =0x02d1 # 0.0440 * 2^LUX_SCALE
75-
TSL2561_LUX_K3T =0x00c0 # 0.375 * 2^RATIO_SCALE
76-
TSL2561_LUX_B3T =0x023f # 0.0351 * 2^LUX_SCALE
77-
TSL2561_LUX_M3T =0x037b # 0.0544 * 2^LUX_SCALE
78-
TSL2561_LUX_K4T =0x0100 # 0.50 * 2^RATIO_SCALE
79-
TSL2561_LUX_B4T =0x0270 # 0.0381 * 2^LUX_SCALE
80-
TSL2561_LUX_M4T =0x03fe # 0.0624 * 2^LUX_SCALE
81-
TSL2561_LUX_K5T =0x0138 # 0.61 * 2^RATIO_SCALE
82-
TSL2561_LUX_B5T =0x016f # 0.0224 * 2^LUX_SCALE
83-
TSL2561_LUX_M5T =0x01fc # 0.0310 * 2^LUX_SCALE
84-
TSL2561_LUX_K6T =0x019a # 0.80 * 2^RATIO_SCALE
85-
TSL2561_LUX_B6T =0x00d2 # 0.0128 * 2^LUX_SCALE
86-
TSL2561_LUX_M6T =0x00fb # 0.0153 * 2^LUX_SCALE
87-
TSL2561_LUX_K7T =0x029a # 1.3 * 2^RATIO_SCALE
88-
TSL2561_LUX_B7T =0x0018 # 0.00146 * 2^LUX_SCALE
89-
TSL2561_LUX_M7T =0x0012 # 0.00112 * 2^LUX_SCALE
90-
TSL2561_LUX_K8T =0x029a # 1.3 * 2^RATIO_SCALE
91-
TSL2561_LUX_B8T =0x0000 # 0.000 * 2^LUX_SCALE
92-
TSL2561_LUX_M8T =0x0000 # 0.000 * 2^LUX_SCALE
69+
TSL2561_LUX_K1T = 0x0040 # 0.125 * 2^RATIO_SCALE
70+
TSL2561_LUX_B1T = 0x01f2 # 0.0304 * 2^LUX_SCALE
71+
TSL2561_LUX_M1T = 0x01be # 0.0272 * 2^LUX_SCALE
72+
TSL2561_LUX_K2T = 0x0080 # 0.250 * 2^RATIO_SCALE
73+
TSL2561_LUX_B2T = 0x0214 # 0.0325 * 2^LUX_SCALE
74+
TSL2561_LUX_M2T = 0x02d1 # 0.0440 * 2^LUX_SCALE
75+
TSL2561_LUX_K3T = 0x00c0 # 0.375 * 2^RATIO_SCALE
76+
TSL2561_LUX_B3T = 0x023f # 0.0351 * 2^LUX_SCALE
77+
TSL2561_LUX_M3T = 0x037b # 0.0544 * 2^LUX_SCALE
78+
TSL2561_LUX_K4T = 0x0100 # 0.50 * 2^RATIO_SCALE
79+
TSL2561_LUX_B4T = 0x0270 # 0.0381 * 2^LUX_SCALE
80+
TSL2561_LUX_M4T = 0x03fe # 0.0624 * 2^LUX_SCALE
81+
TSL2561_LUX_K5T = 0x0138 # 0.61 * 2^RATIO_SCALE
82+
TSL2561_LUX_B5T = 0x016f # 0.0224 * 2^LUX_SCALE
83+
TSL2561_LUX_M5T = 0x01fc # 0.0310 * 2^LUX_SCALE
84+
TSL2561_LUX_K6T = 0x019a # 0.80 * 2^RATIO_SCALE
85+
TSL2561_LUX_B6T = 0x00d2 # 0.0128 * 2^LUX_SCALE
86+
TSL2561_LUX_M6T = 0x00fb # 0.0153 * 2^LUX_SCALE
87+
TSL2561_LUX_K7T = 0x029a # 1.3 * 2^RATIO_SCALE
88+
TSL2561_LUX_B7T = 0x0018 # 0.00146 * 2^LUX_SCALE
89+
TSL2561_LUX_M7T = 0x0012 # 0.00112 * 2^LUX_SCALE
90+
TSL2561_LUX_K8T = 0x029a # 1.3 * 2^RATIO_SCALE
91+
TSL2561_LUX_B8T = 0x0000 # 0.000 * 2^LUX_SCALE
92+
TSL2561_LUX_M8T = 0x0000 # 0.000 * 2^LUX_SCALE
9393

9494
# CS package values
95-
TSL2561_LUX_K1C =0x0043 # 0.130 * 2^RATIO_SCALE
96-
TSL2561_LUX_B1C =0x0204 # 0.0315 * 2^LUX_SCALE
97-
TSL2561_LUX_M1C =0x01ad # 0.0262 * 2^LUX_SCALE
98-
TSL2561_LUX_K2C =0x0085 # 0.260 * 2^RATIO_SCALE
99-
TSL2561_LUX_B2C =0x0228 # 0.0337 * 2^LUX_SCALE
100-
TSL2561_LUX_M2C =0x02c1 # 0.0430 * 2^LUX_SCALE
101-
TSL2561_LUX_K3C =0x00c8 # 0.390 * 2^RATIO_SCALE
102-
TSL2561_LUX_B3C =0x0253 # 0.0363 * 2^LUX_SCALE
103-
TSL2561_LUX_M3C =0x0363 # 0.0529 * 2^LUX_SCALE
104-
TSL2561_LUX_K4C =0x010a # 0.520 * 2^RATIO_SCALE
105-
TSL2561_LUX_B4C =0x0282 # 0.0392 * 2^LUX_SCALE
106-
TSL2561_LUX_M4C =0x03df # 0.0605 * 2^LUX_SCALE
107-
TSL2561_LUX_K5C =0x014d # 0.65 * 2^RATIO_SCALE
108-
TSL2561_LUX_B5C =0x0177 # 0.0229 * 2^LUX_SCALE
109-
TSL2561_LUX_M5C =0x01dd # 0.0291 * 2^LUX_SCALE
110-
TSL2561_LUX_K6C =0x019a # 0.80 * 2^RATIO_SCALE
111-
TSL2561_LUX_B6C =0x0101 # 0.0157 * 2^LUX_SCALE
112-
TSL2561_LUX_M6C =0x0127 # 0.0180 * 2^LUX_SCALE
113-
TSL2561_LUX_K7C =0x029a # 1.3 * 2^RATIO_SCALE
114-
TSL2561_LUX_B7C =0x0037 # 0.00338 * 2^LUX_SCALE
115-
TSL2561_LUX_M7C =0x002b # 0.00260 * 2^LUX_SCALE
116-
TSL2561_LUX_K8C =0x029a # 1.3 * 2^RATIO_SCALE
117-
TSL2561_LUX_B8C =0x0000 # 0.000 * 2^LUX_SCALE
118-
TSL2561_LUX_M8C =0x0000 # 0.000 * 2^LUX_SCALE
95+
TSL2561_LUX_K1C = 0x0043 # 0.130 * 2^RATIO_SCALE
96+
TSL2561_LUX_B1C = 0x0204 # 0.0315 * 2^LUX_SCALE
97+
TSL2561_LUX_M1C = 0x01ad # 0.0262 * 2^LUX_SCALE
98+
TSL2561_LUX_K2C = 0x0085 # 0.260 * 2^RATIO_SCALE
99+
TSL2561_LUX_B2C = 0x0228 # 0.0337 * 2^LUX_SCALE
100+
TSL2561_LUX_M2C = 0x02c1 # 0.0430 * 2^LUX_SCALE
101+
TSL2561_LUX_K3C = 0x00c8 # 0.390 * 2^RATIO_SCALE
102+
TSL2561_LUX_B3C = 0x0253 # 0.0363 * 2^LUX_SCALE
103+
TSL2561_LUX_M3C = 0x0363 # 0.0529 * 2^LUX_SCALE
104+
TSL2561_LUX_K4C = 0x010a # 0.520 * 2^RATIO_SCALE
105+
TSL2561_LUX_B4C = 0x0282 # 0.0392 * 2^LUX_SCALE
106+
TSL2561_LUX_M4C = 0x03df # 0.0605 * 2^LUX_SCALE
107+
TSL2561_LUX_K5C = 0x014d # 0.65 * 2^RATIO_SCALE
108+
TSL2561_LUX_B5C = 0x0177 # 0.0229 * 2^LUX_SCALE
109+
TSL2561_LUX_M5C = 0x01dd # 0.0291 * 2^LUX_SCALE
110+
TSL2561_LUX_K6C = 0x019a # 0.80 * 2^RATIO_SCALE
111+
TSL2561_LUX_B6C = 0x0101 # 0.0157 * 2^LUX_SCALE
112+
TSL2561_LUX_M6C = 0x0127 # 0.0180 * 2^LUX_SCALE
113+
TSL2561_LUX_K7C = 0x029a # 1.3 * 2^RATIO_SCALE
114+
TSL2561_LUX_B7C = 0x0037 # 0.00338 * 2^LUX_SCALE
115+
TSL2561_LUX_M7C = 0x002b # 0.00260 * 2^LUX_SCALE
116+
TSL2561_LUX_K8C = 0x029a # 1.3 * 2^RATIO_SCALE
117+
TSL2561_LUX_B8C = 0x0000 # 0.000 * 2^LUX_SCALE
118+
TSL2561_LUX_M8C = 0x0000 # 0.000 * 2^LUX_SCALE
119119

120120
# Auto-gain thresholds
121-
TSL2561_AGC_THI_13MS =4850 # Max value at Ti 13ms = 5047
122-
TSL2561_AGC_TLO_13MS =100
123-
TSL2561_AGC_THI_101MS =36000 # Max value at Ti 101ms = 37177
124-
TSL2561_AGC_TLO_101MS =200
125-
TSL2561_AGC_THI_402MS =63000 # Max value at Ti 402ms = 65535
126-
TSL2561_AGC_TLO_402MS =500
121+
TSL2561_AGC_THI_13MS = 4850 # Max value at Ti 13ms = 5047
122+
TSL2561_AGC_TLO_13MS = 100
123+
TSL2561_AGC_THI_101MS = 36000 # Max value at Ti 101ms = 37177
124+
TSL2561_AGC_TLO_101MS = 200
125+
TSL2561_AGC_THI_402MS = 63000 # Max value at Ti 402ms = 65535
126+
TSL2561_AGC_TLO_402MS = 500
127127

128128
# Clipping thresholds
129-
TSL2561_CLIPPING_13MS =4900
130-
TSL2561_CLIPPING_101MS =37000
131-
TSL2561_CLIPPING_402MS =65000
129+
TSL2561_CLIPPING_13MS = 4900
130+
TSL2561_CLIPPING_101MS = 37000
131+
TSL2561_CLIPPING_402MS = 65000
132132

133133
TSL2561_REGISTER_CONTROL = 0x00
134134
TSL2561_REGISTER_TIMING = 0x01
@@ -160,51 +160,51 @@ class Adafruit_TSL2561(Adafruit_I2C):
160160

161161

162162

163-
#**************************************************************************/
163+
#**************************************************************************
164164
# Writes a register and an 8 bit value over I2C
165-
#**************************************************************************/
165+
#**************************************************************************
166166
def write8 (self, reg, value):
167167
if (self._debug == True): print "write8"
168168
self._i2c.write8(reg, value)
169169
if (self._debug == True): print "write8_end"
170170

171-
#**************************************************************************/
171+
#**************************************************************************
172172
# Reads an 8 bit value over I2C
173-
#**************************************************************************/
173+
#**************************************************************************
174174
def read8(self, reg):
175175
if (self._debug == True): print "read8"
176176
return self._i2c.readU8(reg)
177177
if (self._debug == True): print "read8_end"
178178

179-
#**************************************************************************/
179+
#**************************************************************************
180180
# Reads a 16 bit values over I2C
181-
#**************************************************************************/
181+
#**************************************************************************
182182
def read16(self, reg):
183183
if (self._debug == True): print "read16"
184184
return self._i2c.readU16(reg)
185185
if (self._debug == True): print "read16_end"
186186

187-
#**************************************************************************/
187+
#**************************************************************************
188188
# Enables the device
189-
#**************************************************************************/
189+
#**************************************************************************
190190
def enable(self):
191191
if (self._debug == True): print "enable"
192192
# Enable the device by setting the control bit to 0x03 */
193193
self._i2c.write8(self.TSL2561_COMMAND_BIT | self.TSL2561_REGISTER_CONTROL, self.TSL2561_CONTROL_POWERON)
194194
if (self._debug == True): print "enable_end"
195195

196-
#**************************************************************************/
196+
#**************************************************************************
197197
# Disables the device (putting it in lower power sleep mode)
198-
#**************************************************************************/
198+
#**************************************************************************
199199
def disable(self):
200200
if (self._debug == True): print "disable"
201201
# Turn the device off to save power */
202202
self._i2c.write8(self.TSL2561_COMMAND_BIT | self.TSL2561_REGISTER_CONTROL, self.TSL2561_CONTROL_POWEROFF)
203203
if (self._debug == True): print "disable_end"
204204

205-
#**************************************************************************/
205+
#**************************************************************************
206206
# Private function to read luminosity on both channels
207-
#**************************************************************************/
207+
#**************************************************************************
208208
def getData (self):
209209
if (self._debug == True): print "getData"
210210
# Enable the device by setting the control bit to 0x03 */
@@ -229,9 +229,9 @@ def getData (self):
229229
self.disable();
230230
if (self._debug == True): print "getData_end"
231231

232-
#**************************************************************************/
232+
#**************************************************************************
233233
# Constructor
234-
#**************************************************************************/
234+
#**************************************************************************
235235
def __init__(self, addr=TSL2561_ADDR_FLOAT, debug=False):
236236
self._debug = debug
237237
if (self._debug == True): print "__init__"
@@ -246,10 +246,10 @@ def __init__(self, addr=TSL2561_ADDR_FLOAT, debug=False):
246246
self._ir = 0
247247
if (self._debug == True): print "__init___end"
248248

249-
#**************************************************************************/
249+
#**************************************************************************
250250
# Initializes I2C and configures the sensor (call this function before
251251
# doing anything else)
252-
#**************************************************************************/
252+
#**************************************************************************
253253
def begin(self):
254254
if (self._debug == True): print "begin"
255255
# Make sure we're actually connected */
@@ -268,10 +268,10 @@ def begin(self):
268268

269269
return True
270270

271-
#**************************************************************************/
271+
#**************************************************************************
272272
# Enables or disables the auto-gain settings when reading
273273
# data from the sensor
274-
#**************************************************************************/
274+
#**************************************************************************
275275
def enableAutoGain(self, enable):
276276
if (self._debug == True): print "enableAutoGain"
277277
self._tsl2561AutoGain = enable if True else False
@@ -281,9 +281,9 @@ def enableAutoGain(self, enable):
281281
self._tsl2561AutoGain = False
282282
if (self._debug == True): print "enableAutoGain_end"
283283

284-
#**************************************************************************/
284+
#**************************************************************************
285285
# Sets the integration time for the TSL2561
286-
#**************************************************************************/
286+
#**************************************************************************
287287
def setIntegrationTime(self, time):
288288
if (self._debug == True): print "setIntegrationTime"
289289
if (not self._tsl2561Initialised):
@@ -302,9 +302,9 @@ def setIntegrationTime(self, time):
302302
self.disable()
303303
if (self._debug == True): print "setIntegrationTime_end"
304304

305-
#**************************************************************************/
305+
#**************************************************************************
306306
# Adjusts the gain on the TSL2561 (adjusts the sensitivity to light)
307-
#**************************************************************************/
307+
#**************************************************************************
308308
def setGain(self, gain):
309309
if (self._debug == True): print "setGain"
310310
if (not self._tsl2561Initialised):
@@ -323,10 +323,10 @@ def setGain(self, gain):
323323
self.disable()
324324
if (self._debug == True): print "setGain_end"
325325

326-
#**************************************************************************/
326+
#**************************************************************************
327327
# Gets the broadband (mixed lighting) and IR only values from
328328
# the TSL2561, adjusting gain if auto-gain is enabled
329-
#**************************************************************************/
329+
#**************************************************************************
330330
def getLuminosity (self):
331331
# This is a hack to ensure that when looping with autogain the gain can go up and down as without
332332
# setting the gain to 1X before every reading it doesn't seem able to go from 16X
@@ -390,10 +390,10 @@ def getLuminosity (self):
390390
valid = True
391391
if (self._debug == True): print "getLuminosity_end"
392392

393-
#**************************************************************************/
393+
#**************************************************************************
394394
# Converts the raw sensor values to the standard SI lux equivalent.
395395
# Returns 0 if the sensor is saturated and the values are unreliable.
396-
#**************************************************************************/
396+
#**************************************************************************
397397
def calculateLux(self):
398398
if (self._debug == True): print "calculateLux"
399399
self.getLuminosity()
@@ -501,9 +501,9 @@ def calculateLux(self):
501501
if (self._debug == True): print "calculateLux_end"
502502
return lux
503503

504-
#**************************************************************************/
504+
#**************************************************************************
505505
# Calculates an averaged Lux value over default 25 samples
506-
#**************************************************************************/
506+
#**************************************************************************
507507
def calculateAvgLux(self, testavg=TSL2561_NO_OF_AVG_SAMPLES):
508508
# Set initial vars
509509
count = 0

0 commit comments

Comments
 (0)