28
28
29
29
* Author(s): Tony DiCola
30
30
"""
31
- import time
32
-
33
31
from micropython import const
34
32
35
33
import adafruit_bus_device .i2c_device as i2c_device
@@ -96,9 +94,8 @@ def __init__(self, i2c, address=_TSL2591_ADDR):
96
94
# Set default gain and integration times.
97
95
self .gain = GAIN_MED
98
96
self .integration_time = INTEGRATIONTIME_100MS
99
- # Put the device in a disabled state after initialization.
100
- # Future calls will enable and disable as necessary.
101
- self .disable ()
97
+ # Put the device in a powered on state after initialization.
98
+ self .enable ()
102
99
103
100
def _read_u8 (self , address ):
104
101
# Read an 8-bit unsigned value from the specified 8-bit address.
@@ -149,24 +146,19 @@ def gain(self):
149
146
- GAIN_HIGH (428x)
150
147
- GAIN_MAX (9876x)
151
148
"""
152
- self .enable ()
153
149
control = self ._read_u8 (_TSL2591_REGISTER_CONTROL )
154
- self .disable ()
155
150
return control & 0b00110000
156
151
157
152
@gain .setter
158
153
def gain (self , val ):
159
154
assert val in (GAIN_LOW , GAIN_MED , GAIN_HIGH , GAIN_MAX )
160
- # Enable chip, set appropriate gain value.
161
- self .enable ()
155
+ # Set appropriate gain value.
162
156
control = self ._read_u8 (_TSL2591_REGISTER_CONTROL )
163
157
control &= 0b11001111
164
158
control |= val
165
159
self ._write_u8 (_TSL2591_REGISTER_CONTROL , control )
166
160
# Keep track of gain for future lux calculations.
167
161
self ._gain = val
168
- # Go back to low power mode.
169
- self .disable ()
170
162
171
163
@property
172
164
def integration_time (self ):
@@ -178,24 +170,19 @@ def integration_time(self):
178
170
- INTEGRATIONTIME_500MS (500 millis)
179
171
- INTEGRATIONTIME_600MS (600 millis)
180
172
"""
181
- self .enable ()
182
173
control = self ._read_u8 (_TSL2591_REGISTER_CONTROL )
183
- self .disable ()
184
174
return control & 0b00000111
185
175
186
176
@integration_time .setter
187
177
def integration_time (self , val ):
188
178
assert 0 <= val <= 5
189
- # Enable chip, set control bits appropriately.
190
- self .enable ()
179
+ # Set control bits appropriately.
191
180
control = self ._read_u8 (_TSL2591_REGISTER_CONTROL )
192
181
control &= 0b11111000
193
182
control |= val
194
183
self ._write_u8 (_TSL2591_REGISTER_CONTROL , control )
195
184
# Keep track of integration time for future reading delay times.
196
185
self ._integration_time = val
197
- # Go back to low power mode.
198
- self .disable ()
199
186
200
187
@property
201
188
def raw_luminosity (self ):
@@ -204,14 +191,9 @@ def raw_luminosity(self):
204
191
is IR + visible luminosity (channel 0) and the second is the IR only
205
192
(channel 1). Both values are 16-bit unsigned numbers (0-65535).
206
193
"""
207
- # Enable then wait for the integration time to pass.
208
- self .enable ()
209
- time .sleep (120.0 * self ._integration_time / 1000.0 )
210
- # Now read both the luminosity channels.
194
+ # Read both the luminosity channels.
211
195
channel_0 = self ._read_u16LE (_TSL2591_REGISTER_CHAN0_LOW )
212
196
channel_1 = self ._read_u16LE (_TSL2591_REGISTER_CHAN1_LOW )
213
- # Go back to low power mode and return result.
214
- self .disable ()
215
197
return (channel_0 , channel_1 )
216
198
217
199
@property
@@ -231,7 +213,7 @@ def infrared(self):
231
213
232
214
@property
233
215
def visible (self ):
234
- """Read the visible light and return its value as a 16 -bit unsigned number.
216
+ """Read the visible light and return its value as a 32 -bit unsigned number.
235
217
"""
236
218
channel_0 , channel_1 = self .raw_luminosity
237
219
full = (channel_1 << 16 ) | channel_0
0 commit comments