5151__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_VL6180X.git"
5252
5353
54- #pylint: disable=bad-whitespace
54+ # pylint: disable=bad-whitespace
5555# Internal constants:
56- _VL6180X_DEFAULT_I2C_ADDR = const (0x29 )
57- _VL6180X_REG_IDENTIFICATION_MODEL_ID = const (0x000 )
58- _VL6180X_REG_SYSTEM_INTERRUPT_CONFIG = const (0x014 )
59- _VL6180X_REG_SYSTEM_INTERRUPT_CLEAR = const (0x015 )
60- _VL6180X_REG_SYSTEM_FRESH_OUT_OF_RESET = const (0x016 )
61- _VL6180X_REG_SYSRANGE_START = const (0x018 )
62- _VL6180X_REG_SYSALS_START = const (0x038 )
63- _VL6180X_REG_SYSALS_ANALOGUE_GAIN = const (0x03F )
64- _VL6180X_REG_SYSALS_INTEGRATION_PERIOD_HI = const (0x040 )
65- _VL6180X_REG_SYSALS_INTEGRATION_PERIOD_LO = const (0x041 )
66- _VL6180X_REG_RESULT_ALS_VAL = const (0x050 )
67- _VL6180X_REG_RESULT_RANGE_VAL = const (0x062 )
68- _VL6180X_REG_RESULT_RANGE_STATUS = const (0x04d )
69- _VL6180X_REG_RESULT_INTERRUPT_STATUS_GPIO = const (0x04f )
56+ _VL6180X_DEFAULT_I2C_ADDR = const (0x29 )
57+ _VL6180X_REG_IDENTIFICATION_MODEL_ID = const (0x000 )
58+ _VL6180X_REG_SYSTEM_INTERRUPT_CONFIG = const (0x014 )
59+ _VL6180X_REG_SYSTEM_INTERRUPT_CLEAR = const (0x015 )
60+ _VL6180X_REG_SYSTEM_FRESH_OUT_OF_RESET = const (0x016 )
61+ _VL6180X_REG_SYSRANGE_START = const (0x018 )
62+ _VL6180X_REG_SYSALS_START = const (0x038 )
63+ _VL6180X_REG_SYSALS_ANALOGUE_GAIN = const (0x03F )
64+ _VL6180X_REG_SYSALS_INTEGRATION_PERIOD_HI = const (0x040 )
65+ _VL6180X_REG_SYSALS_INTEGRATION_PERIOD_LO = const (0x041 )
66+ _VL6180X_REG_RESULT_ALS_VAL = const (0x050 )
67+ _VL6180X_REG_RESULT_RANGE_VAL = const (0x062 )
68+ _VL6180X_REG_RESULT_RANGE_STATUS = const (0x04D )
69+ _VL6180X_REG_RESULT_INTERRUPT_STATUS_GPIO = const (0x04F )
7070
7171# User-facing constants:
72- ALS_GAIN_1 = const (0x06 )
73- ALS_GAIN_1_25 = const (0x05 )
74- ALS_GAIN_1_67 = const (0x04 )
75- ALS_GAIN_2_5 = const (0x03 )
76- ALS_GAIN_5 = const (0x02 )
77- ALS_GAIN_10 = const (0x01 )
78- ALS_GAIN_20 = const (0x00 )
79- ALS_GAIN_40 = const (0x07 )
72+ ALS_GAIN_1 = const (0x06 )
73+ ALS_GAIN_1_25 = const (0x05 )
74+ ALS_GAIN_1_67 = const (0x04 )
75+ ALS_GAIN_2_5 = const (0x03 )
76+ ALS_GAIN_5 = const (0x02 )
77+ ALS_GAIN_10 = const (0x01 )
78+ ALS_GAIN_20 = const (0x00 )
79+ ALS_GAIN_40 = const (0x07 )
8080
81- ERROR_NONE = const (0 )
82- ERROR_SYSERR_1 = const (1 )
83- ERROR_SYSERR_5 = const (5 )
84- ERROR_ECEFAIL = const (6 )
85- ERROR_NOCONVERGE = const (7 )
86- ERROR_RANGEIGNORE = const (8 )
87- ERROR_SNR = const (11 )
88- ERROR_RAWUFLOW = const (12 )
89- ERROR_RAWOFLOW = const (13 )
90- ERROR_RANGEUFLOW = const (14 )
91- ERROR_RANGEOFLOW = const (15 )
92- #pylint: enable=bad-whitespace
81+ ERROR_NONE = const (0 )
82+ ERROR_SYSERR_1 = const (1 )
83+ ERROR_SYSERR_5 = const (5 )
84+ ERROR_ECEFAIL = const (6 )
85+ ERROR_NOCONVERGE = const (7 )
86+ ERROR_RANGEIGNORE = const (8 )
87+ ERROR_SNR = const (11 )
88+ ERROR_RAWUFLOW = const (12 )
89+ ERROR_RAWOFLOW = const (13 )
90+ ERROR_RANGEUFLOW = const (14 )
91+ ERROR_RANGEOFLOW = const (15 )
92+ # pylint: enable=bad-whitespace
9393
9494
9595class VL6180X :
@@ -107,7 +107,7 @@ class VL6180X:
107107 def __init__ (self , i2c , address = _VL6180X_DEFAULT_I2C_ADDR ):
108108 self ._device = i2c_device .I2CDevice (i2c , address )
109109 if self ._read_8 (_VL6180X_REG_IDENTIFICATION_MODEL_ID ) != 0xB4 :
110- raise RuntimeError (' Could not find VL6180X, is it connected and powered?' )
110+ raise RuntimeError (" Could not find VL6180X, is it connected and powered?" )
111111 self ._load_settings ()
112112 self ._write_8 (_VL6180X_REG_SYSTEM_FRESH_OUT_OF_RESET , 0x00 )
113113
@@ -142,7 +142,7 @@ def read_lux(self, gain):
142142 """
143143 reg = self ._read_8 (_VL6180X_REG_SYSTEM_INTERRUPT_CONFIG )
144144 reg &= ~ 0x38
145- reg |= ( 0x4 << 3 ) # IRQ on ALS ready
145+ reg |= 0x4 << 3 # IRQ on ALS ready
146146 self ._write_8 (_VL6180X_REG_SYSTEM_INTERRUPT_CONFIG , reg )
147147 # 100 ms integration period
148148 self ._write_8 (_VL6180X_REG_SYSALS_INTEGRATION_PERIOD_HI , 0 )
@@ -154,13 +154,15 @@ def read_lux(self, gain):
154154 # start ALS
155155 self ._write_8 (_VL6180X_REG_SYSALS_START , 0x1 )
156156 # Poll until "New Sample Ready threshold event" is set
157- while ((self ._read_8 (_VL6180X_REG_RESULT_INTERRUPT_STATUS_GPIO ) >> 3 ) & 0x7 ) != 4 :
157+ while (
158+ (self ._read_8 (_VL6180X_REG_RESULT_INTERRUPT_STATUS_GPIO ) >> 3 ) & 0x7
159+ ) != 4 :
158160 pass
159161 # read lux!
160162 lux = self ._read_16 (_VL6180X_REG_RESULT_ALS_VAL )
161163 # clear interrupt
162164 self ._write_8 (_VL6180X_REG_SYSTEM_INTERRUPT_CLEAR , 0x07 )
163- lux *= 0.32 # calibrated count/lux
165+ lux *= 0.32 # calibrated count/lux
164166 if gain == ALS_GAIN_1 :
165167 pass
166168 elif gain == ALS_GAIN_1_25 :
@@ -178,7 +180,7 @@ def read_lux(self, gain):
178180 elif gain == ALS_GAIN_40 :
179181 lux /= 20
180182 lux *= 100
181- lux /= 100 # integration time in ms
183+ lux /= 100 # integration time in ms
182184 return lux
183185
184186 @property
@@ -205,72 +207,76 @@ def _load_settings(self):
205207 self ._write_8 (0x0207 , 0x01 )
206208 self ._write_8 (0x0208 , 0x01 )
207209 self ._write_8 (0x0096 , 0x00 )
208- self ._write_8 (0x0097 , 0xfd )
209- self ._write_8 (0x00e3 , 0x00 )
210- self ._write_8 (0x00e4 , 0x04 )
211- self ._write_8 (0x00e5 , 0x02 )
212- self ._write_8 (0x00e6 , 0x01 )
213- self ._write_8 (0x00e7 , 0x03 )
214- self ._write_8 (0x00f5 , 0x02 )
215- self ._write_8 (0x00d9 , 0x05 )
216- self ._write_8 (0x00db , 0xce )
217- self ._write_8 (0x00dc , 0x03 )
218- self ._write_8 (0x00dd , 0xf8 )
219- self ._write_8 (0x009f , 0x00 )
220- self ._write_8 (0x00a3 , 0x3c )
221- self ._write_8 (0x00b7 , 0x00 )
222- self ._write_8 (0x00bb , 0x3c )
223- self ._write_8 (0x00b2 , 0x09 )
224- self ._write_8 (0x00ca , 0x09 )
210+ self ._write_8 (0x0097 , 0xFD )
211+ self ._write_8 (0x00E3 , 0x00 )
212+ self ._write_8 (0x00E4 , 0x04 )
213+ self ._write_8 (0x00E5 , 0x02 )
214+ self ._write_8 (0x00E6 , 0x01 )
215+ self ._write_8 (0x00E7 , 0x03 )
216+ self ._write_8 (0x00F5 , 0x02 )
217+ self ._write_8 (0x00D9 , 0x05 )
218+ self ._write_8 (0x00DB , 0xCE )
219+ self ._write_8 (0x00DC , 0x03 )
220+ self ._write_8 (0x00DD , 0xF8 )
221+ self ._write_8 (0x009F , 0x00 )
222+ self ._write_8 (0x00A3 , 0x3C )
223+ self ._write_8 (0x00B7 , 0x00 )
224+ self ._write_8 (0x00BB , 0x3C )
225+ self ._write_8 (0x00B2 , 0x09 )
226+ self ._write_8 (0x00CA , 0x09 )
225227 self ._write_8 (0x0198 , 0x01 )
226- self ._write_8 (0x01b0 , 0x17 )
227- self ._write_8 (0x01ad , 0x00 )
228- self ._write_8 (0x00ff , 0x05 )
228+ self ._write_8 (0x01B0 , 0x17 )
229+ self ._write_8 (0x01AD , 0x00 )
230+ self ._write_8 (0x00FF , 0x05 )
229231 self ._write_8 (0x0100 , 0x05 )
230232 self ._write_8 (0x0199 , 0x05 )
231- self ._write_8 (0x01a6 , 0x1b )
232- self ._write_8 (0x01ac , 0x3e )
233- self ._write_8 (0x01a7 , 0x1f )
233+ self ._write_8 (0x01A6 , 0x1B )
234+ self ._write_8 (0x01AC , 0x3E )
235+ self ._write_8 (0x01A7 , 0x1F )
234236 self ._write_8 (0x0030 , 0x00 )
235237 # Recommended : Public registers - See data sheet for more detail
236- self ._write_8 (0x0011 , 0x10 ) # Enables polling for 'New Sample ready'
237- # when measurement completes
238- self ._write_8 (0x010a , 0x30 ) # Set the averaging sample period
239- # (compromise between lower noise and
240- # increased execution time)
241- self ._write_8 (0x003f , 0x46 ) # Sets the light and dark gain (upper
242- # nibble). Dark gain should not be
243- # changed.
244- self ._write_8 (0x0031 , 0xFF ) # sets the # of range measurements after
245- # which auto calibration of system is
246- # performed
247- self ._write_8 (0x0040 , 0x63 ) # Set ALS integration time to 100ms
248- self ._write_8 (0x002e , 0x01 ) # perform a single temperature calibration
249- # of the ranging sensor
238+ self ._write_8 (0x0011 , 0x10 ) # Enables polling for 'New Sample ready'
239+ # when measurement completes
240+ self ._write_8 (0x010A , 0x30 ) # Set the averaging sample period
241+ # (compromise between lower noise and
242+ # increased execution time)
243+ self ._write_8 (0x003F , 0x46 ) # Sets the light and dark gain (upper
244+ # nibble). Dark gain should not be
245+ # changed.
246+ self ._write_8 (0x0031 , 0xFF ) # sets the # of range measurements after
247+ # which auto calibration of system is
248+ # performed
249+ self ._write_8 (0x0040 , 0x63 ) # Set ALS integration time to 100ms
250+ self ._write_8 (0x002E , 0x01 ) # perform a single temperature calibration
251+ # of the ranging sensor
250252
251253 # Optional: Public registers - See data sheet for more detail
252- self ._write_8 (0x001b , 0x09 ) # Set default ranging inter-measurement
253- # period to 100ms
254- self ._write_8 (0x003e , 0x31 ) # Set default ALS inter-measurement period
255- # to 500ms
256- self ._write_8 (0x0014 , 0x24 ) # Configures interrupt on 'New Sample
257- # Ready threshold event'
254+ self ._write_8 (0x001B , 0x09 ) # Set default ranging inter-measurement
255+ # period to 100ms
256+ self ._write_8 (0x003E , 0x31 ) # Set default ALS inter-measurement period
257+ # to 500ms
258+ self ._write_8 (0x0014 , 0x24 ) # Configures interrupt on 'New Sample
259+ # Ready threshold event'
258260
259261 def _write_8 (self , address , data ):
260262 # Write 1 byte of data from the specified 16-bit register address.
261263 with self ._device :
262- self ._device .write (bytes ([(address >> 8 ) & 0xFF ,
263- address & 0xFF ,
264- data ]))
264+ self ._device .write (bytes ([(address >> 8 ) & 0xFF , address & 0xFF , data ]))
265265
266266 def _write_16 (self , address , data ):
267267 # Write a 16-bit big endian value to the specified 16-bit register
268268 # address.
269269 with self ._device as i2c :
270- i2c .write (bytes ([(address >> 8 ) & 0xFF ,
271- address & 0xFF ,
272- (data >> 8 ) & 0xFF ,
273- data & 0xFF ]))
270+ i2c .write (
271+ bytes (
272+ [
273+ (address >> 8 ) & 0xFF ,
274+ address & 0xFF ,
275+ (data >> 8 ) & 0xFF ,
276+ data & 0xFF ,
277+ ]
278+ )
279+ )
274280
275281 def _read_8 (self , address ):
276282 # Read and return a byte from the specified 16-bit register address.
0 commit comments