3838__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_VCNL4040.git"
3939
4040
41+ try :
42+ from busio import I2C
43+ except ImportError :
44+ pass
45+
46+
4147class VCNL4040 : # pylint: disable=too-few-public-methods
4248 """Driver for the VCNL4040 proximity and ambient light sensor.
4349
@@ -141,13 +147,13 @@ class VCNL4040: # pylint: disable=too-few-public-methods
141147
142148 # INT_FLAG - PS interrupt flag
143149 @property
144- def proximity_high_interrupt (self ):
150+ def proximity_high_interrupt (self ) -> bool :
145151 """If interrupt is set to ``PS_INT_CLOSE`` or ``PS_INT_CLOSE_AWAY``, trigger event when
146152 proximity rises above high threshold interrupt."""
147153 return self ._get_and_clear_cached_interrupt_state (self .PS_IF_CLOSE )
148154
149155 @property
150- def proximity_low_interrupt (self ):
156+ def proximity_low_interrupt (self ) -> bool :
151157 """If interrupt is set to ``PS_INT_AWAY`` or ``PS_INT_CLOSE_AWAY``, trigger event when
152158 proximity drops below low threshold."""
153159 return self ._get_and_clear_cached_interrupt_state (self .PS_IF_AWAY )
@@ -167,7 +173,7 @@ def proximity_low_interrupt(self):
167173 """
168174
169175 @property
170- def lux (self ):
176+ def lux (self ) -> float :
171177 """Ambient light data in lux. Represents the raw sensor data scaled according to the current
172178 integration time and gain settings.
173179
@@ -195,7 +201,7 @@ def lux(self):
195201 _light_integration_time = RWBits (2 , 0x00 , 6 , register_width = 2 )
196202
197203 @property
198- def light_integration_time (self ):
204+ def light_integration_time (self ) -> int :
199205 """Ambient light sensor integration time setting. Longer time has higher sensitivity.
200206 Can be: ALS_80MS, ALS_160MS, ALS_320MS or ALS_640MS.
201207
@@ -219,7 +225,7 @@ def light_integration_time(self):
219225 return self ._light_integration_time
220226
221227 @light_integration_time .setter
222- def light_integration_time (self , new_it ) :
228+ def light_integration_time (self , new_it : int ) -> None :
223229 from time import sleep # pylint: disable=import-outside-toplevel
224230
225231 # IT values are in 0-3 -> 80-640ms
@@ -242,19 +248,19 @@ def light_integration_time(self, new_it):
242248 # INT_FLAG - ALS interrupt flag
243249
244250 @property
245- def light_high_interrupt (self ):
251+ def light_high_interrupt (self ) -> bool :
246252 """High interrupt event. Triggered when ambient light value exceeds high threshold."""
247253 return self ._get_and_clear_cached_interrupt_state (self .ALS_IF_H )
248254
249255 @property
250- def light_low_interrupt (self ):
256+ def light_low_interrupt (self ) -> bool :
251257 """Low interrupt event. Triggered when ambient light value drops below low threshold."""
252258 return self ._get_and_clear_cached_interrupt_state (self .ALS_IF_L )
253259
254260 _raw_white = ROUnaryStruct (0x0A , "<H" )
255261
256262 @property
257- def white (self ):
263+ def white (self ) -> float :
258264 """White light data scaled according to the current integration time and gain settings.
259265
260266 This example prints the white light data. Cover the sensor to see the values change.
@@ -279,7 +285,7 @@ def white(self):
279285 white_shutdown = RWBit (0x04 , 15 , register_width = 2 )
280286 """White light channel shutdown. When `True`, white light data is disabled."""
281287
282- def __init__ (self , i2c , address = 0x60 ):
288+ def __init__ (self , i2c : I2C , address : int = 0x60 ):
283289 self .i2c_device = i2cdevice .I2CDevice (i2c , address )
284290 if self ._device_id != 0x186 :
285291 raise RuntimeError ("Failed to find VCNL4040 - check wiring!" )
@@ -295,15 +301,15 @@ def __init__(self, i2c, address=0x60):
295301 self .light_shutdown = False
296302 self .white_shutdown = False
297303
298- def _update_interrupt_state (self ):
304+ def _update_interrupt_state (self ) -> None :
299305 interrupts = [self .PS_IF_AWAY , self .PS_IF_CLOSE , self .ALS_IF_H , self .ALS_IF_L ]
300306 new_interrupt_state = self .interrupt_state
301307 for interrupt in interrupts :
302308 new_state = new_interrupt_state & (1 << interrupt ) > 0
303309 if new_state :
304310 self .cached_interrupt_state [interrupt ] = new_state
305311
306- def _get_and_clear_cached_interrupt_state (self , interrupt_offset ) :
312+ def _get_and_clear_cached_interrupt_state (self , interrupt_offset : int ) -> bool :
307313 self ._update_interrupt_state ()
308314 new_interrupt_state = self .cached_interrupt_state [interrupt_offset ]
309315 self .cached_interrupt_state [interrupt_offset ] = False
0 commit comments