2828
2929* Author(s): Tony DiCola
3030"""
31- import time
32-
3331from micropython import const
3432
3533import adafruit_bus_device .i2c_device as i2c_device
@@ -96,9 +94,8 @@ def __init__(self, i2c, address=_TSL2591_ADDR):
9694 # Set default gain and integration times.
9795 self .gain = GAIN_MED
9896 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 ()
10299
103100 def _read_u8 (self , address ):
104101 # Read an 8-bit unsigned value from the specified 8-bit address.
@@ -149,24 +146,19 @@ def gain(self):
149146 - GAIN_HIGH (428x)
150147 - GAIN_MAX (9876x)
151148 """
152- self .enable ()
153149 control = self ._read_u8 (_TSL2591_REGISTER_CONTROL )
154- self .disable ()
155150 return control & 0b00110000
156151
157152 @gain .setter
158153 def gain (self , val ):
159154 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.
162156 control = self ._read_u8 (_TSL2591_REGISTER_CONTROL )
163157 control &= 0b11001111
164158 control |= val
165159 self ._write_u8 (_TSL2591_REGISTER_CONTROL , control )
166160 # Keep track of gain for future lux calculations.
167161 self ._gain = val
168- # Go back to low power mode.
169- self .disable ()
170162
171163 @property
172164 def integration_time (self ):
@@ -178,24 +170,19 @@ def integration_time(self):
178170 - INTEGRATIONTIME_500MS (500 millis)
179171 - INTEGRATIONTIME_600MS (600 millis)
180172 """
181- self .enable ()
182173 control = self ._read_u8 (_TSL2591_REGISTER_CONTROL )
183- self .disable ()
184174 return control & 0b00000111
185175
186176 @integration_time .setter
187177 def integration_time (self , val ):
188178 assert 0 <= val <= 5
189- # Enable chip, set control bits appropriately.
190- self .enable ()
179+ # Set control bits appropriately.
191180 control = self ._read_u8 (_TSL2591_REGISTER_CONTROL )
192181 control &= 0b11111000
193182 control |= val
194183 self ._write_u8 (_TSL2591_REGISTER_CONTROL , control )
195184 # Keep track of integration time for future reading delay times.
196185 self ._integration_time = val
197- # Go back to low power mode.
198- self .disable ()
199186
200187 @property
201188 def raw_luminosity (self ):
@@ -204,14 +191,9 @@ def raw_luminosity(self):
204191 is IR + visible luminosity (channel 0) and the second is the IR only
205192 (channel 1). Both values are 16-bit unsigned numbers (0-65535).
206193 """
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.
211195 channel_0 = self ._read_u16LE (_TSL2591_REGISTER_CHAN0_LOW )
212196 channel_1 = self ._read_u16LE (_TSL2591_REGISTER_CHAN1_LOW )
213- # Go back to low power mode and return result.
214- self .disable ()
215197 return (channel_0 , channel_1 )
216198
217199 @property
@@ -231,7 +213,7 @@ def infrared(self):
231213
232214 @property
233215 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.
235217 """
236218 channel_0 , channel_1 = self .raw_luminosity
237219 full = (channel_1 << 16 ) | channel_0
0 commit comments