44
44
from adafruit_register .i2c_bits import ROBits , RWBits
45
45
46
46
try :
47
+ from typing import Tuple , Optional , Any , Callable , TypeVar
48
+
47
49
# Only needed for typing
48
50
import busio # pylint: disable=unused-import
49
- from typing import Tuple , Optional
51
+
52
+ TCallable = TypeVar ('TCallable' , bound = Callable [..., Any ])
53
+
50
54
except ImportError :
51
55
pass
52
56
53
-
54
- _AS7341_DEVICE_ID : int = const (0b001001 ) # Correct content of WHO_AM_I register
57
+ # Correct content of WHO_AM_I register
58
+ _AS7341_DEVICE_ID : int = const (0b001001 )
55
59
_AS7341_I2CADDR_DEFAULT : int = const (0x39 ) # AS7341 default i2c address
56
60
_AS7341_CHIP_ID : int = const (0x09 ) # AS7341 default device id from WHOAMI
57
61
_AS7341_WHOAMI : int = const (0x92 ) # Chip ID register
58
- _AS7341_CONFIG : int = const (0x70 ) # Enables LED control and sets light sensing mode
62
+ # Enables LED control and sets light sensing mode
63
+ _AS7341_CONFIG : int = const (0x70 )
59
64
_AS7341_GPIO : int = const (0x73 ) # Connects photo diode to GPIO or INT pins
60
65
_AS7341_LED : int = const (0x74 ) # LED Register; Enables and sets current limit
61
66
_AS7341_ENABLE : int = const (
62
67
0x80
63
68
) # Main enable register. Controls SMUX, Flicker Detection,Spectral and
64
69
# Power
65
70
_AS7341_ATIME : int = const (0x81 ) # Sets ADC integration step count
66
- _AS7341_SP_LOW_TH_L : int = const (0x84 ) # Spectral measurement Low Threshold low byte
67
- _AS7341_SP_LOW_TH_H : int = const (0x85 ) # 0 Spectral measurement Low Threshold high byte
68
- _AS7341_SP_HIGH_TH_L : int = const (0x86 ) # Spectral measurement High Threshold low byte
69
- _AS7341_SP_HIGH_TH_H : int = const (0x87 ) # Spectral measurement High Threshold low byte
71
+ # Spectral measurement Low Threshold low byte
72
+ _AS7341_SP_LOW_TH_L : int = const (0x84 )
73
+ # 0 Spectral measurement Low Threshold high byte
74
+ _AS7341_SP_LOW_TH_H : int = const (0x85 )
75
+ # Spectral measurement High Threshold low byte
76
+ _AS7341_SP_HIGH_TH_L : int = const (0x86 )
77
+ # Spectral measurement High Threshold low byte
78
+ _AS7341_SP_HIGH_TH_H : int = const (0x87 )
70
79
_AS7341_STATUS : int = const (
71
80
0x93
72
81
) # Interrupt status registers. Indicates the occourance of an interrupt
104
113
) # GPIO Settings and status: polarity, direction, sets output, reads
105
114
_AS7341_ASTEP_L : int = const (0xCA ) # Integration step size ow byte
106
115
_AS7341_ASTEP_H : int = const (0xCB ) # Integration step size high byte
107
- _AS7341_FD_TIME1 : int = const (0xD8 ) # Flicker detection integration time low byte
116
+ _AS7341_FD_TIME1 : int = const (
117
+ 0xD8
118
+ ) # Flicker detection integration time low byte
108
119
_AS7341_FD_TIME2 : int = const (0xDA ) # Flicker detection gain and high nibble
109
120
_AS7341_FD_STATUS : int = const (
110
121
0xDB
114
125
_AS7341_FD_CFG0 : int = const (0xD7 ) # Enables FIFO for flicker detection
115
126
116
127
117
- def _low_bank (func ) -> any :
128
+ def _low_bank (func : TCallable ) -> Callable [[ Any ], TCallable ] :
118
129
# pylint:disable=protected-access
119
- def _decorator (self , * args , ** kwargs ):
130
+ def _decorator (self , * args , ** kwargs ) -> TCallable :
120
131
self ._low_bank_active = True
121
132
retval = func (self , * args , ** kwargs )
122
133
self ._low_bank_active = False
@@ -131,7 +142,7 @@ class CV:
131
142
@classmethod
132
143
def add_values (
133
144
cls ,
134
- value_tuples : Tuple [str , int , any , any ],
145
+ value_tuples : Tuple [str , int , int , Optional [ float ] ],
135
146
) -> None :
136
147
"""Add CV values to the class"""
137
148
cls .string = {}
@@ -309,8 +320,8 @@ class AS7341: # pylint:disable=too-many-instance-attributes, no-member
309
320
"""
310
321
311
322
def __init__ (
312
- self , i2c_bus : busio .I2C , address : Optional [ int ] = _AS7341_I2CADDR_DEFAULT
313
- ):
323
+ self , i2c_bus : busio .I2C , address : int = _AS7341_I2CADDR_DEFAULT
324
+ ) -> None :
314
325
315
326
self .i2c_device = i2c_device .I2CDevice (i2c_bus , address )
316
327
if not self ._device_id in [_AS7341_DEVICE_ID ]:
@@ -331,7 +342,7 @@ def initialize(self) -> None:
331
342
self .gain = Gain .GAIN_128X # pylint:disable=no-member
332
343
333
344
@property
334
- def all_channels (self ) -> Struct :
345
+ def all_channels (self ) -> Tuple [ int , ...] :
335
346
"""The current readings for all six ADC channels"""
336
347
337
348
self ._configure_f1_f4 ()
@@ -345,66 +356,66 @@ def all_channels(self) -> Struct:
345
356
return reads
346
357
347
358
@property
348
- def channel_415nm (self ) -> UnaryStruct :
359
+ def channel_415nm (self ) -> int :
349
360
"""The current reading for the 415nm band"""
350
361
self ._configure_f1_f4 ()
351
362
return self ._channel_0_data
352
363
353
364
@property
354
- def channel_445nm (self ) -> UnaryStruct :
365
+ def channel_445nm (self ) -> int :
355
366
"""The current reading for the 445nm band"""
356
367
self ._configure_f1_f4 ()
357
368
return self ._channel_1_data
358
369
359
370
@property
360
- def channel_480nm (self ) -> UnaryStruct :
371
+ def channel_480nm (self ) -> int :
361
372
"""The current reading for the 480nm band"""
362
373
self ._configure_f1_f4 ()
363
374
return self ._channel_2_data
364
375
365
376
@property
366
- def channel_515nm (self ) -> UnaryStruct :
377
+ def channel_515nm (self ) -> int :
367
378
"""The current reading for the 515nm band"""
368
379
self ._configure_f1_f4 ()
369
380
return self ._channel_3_data
370
381
371
382
@property
372
- def channel_555nm (self ) -> UnaryStruct :
383
+ def channel_555nm (self ) -> int :
373
384
"""The current reading for the 555nm band"""
374
385
self ._configure_f5_f8 ()
375
386
return self ._channel_0_data
376
387
377
388
@property
378
- def channel_590nm (self ) -> UnaryStruct :
389
+ def channel_590nm (self ) -> int :
379
390
"""The current reading for the 590nm band"""
380
391
self ._configure_f5_f8 ()
381
392
return self ._channel_1_data
382
393
383
394
@property
384
- def channel_630nm (self ) -> UnaryStruct :
395
+ def channel_630nm (self ) -> int :
385
396
"""The current reading for the 630nm band"""
386
397
self ._configure_f5_f8 ()
387
398
return self ._channel_2_data
388
399
389
400
@property
390
- def channel_680nm (self ) -> UnaryStruct :
401
+ def channel_680nm (self ) -> int :
391
402
"""The current reading for the 680nm band"""
392
403
self ._configure_f5_f8 ()
393
404
return self ._channel_3_data
394
405
395
406
@property
396
- def channel_clear (self ) -> UnaryStruct :
407
+ def channel_clear (self ) -> int :
397
408
"""The current reading for the clear sensor"""
398
409
self ._configure_f5_f8 ()
399
410
return self ._channel_4_data
400
411
401
412
@property
402
- def channel_nir (self ) -> UnaryStruct :
413
+ def channel_nir (self ) -> int :
403
414
"""The current reading for the NIR (near-IR) sensor"""
404
415
self ._configure_f5_f8 ()
405
416
return self ._channel_5_data
406
417
407
- def _wait_for_data (self , timeout : int = 1.0 ) -> None :
418
+ def _wait_for_data (self , timeout : Optional [ int ] = 1.0 ) -> None :
408
419
"""Wait for sensor data to be ready"""
409
420
start = monotonic ()
410
421
while not self ._data_ready_bit :
0 commit comments