32
32
from micropython import const
33
33
34
34
try :
35
- from typing import Tuple
35
+ from typing import Tuple , Optional , Union
36
36
37
37
# This is only needed for typing
38
38
import busio # pylint: disable=unused-import
@@ -267,12 +267,12 @@ def conversion_mode(self, val: int) -> None:
267
267
self ._virtual_write (_AS726X_CONTROL_SETUP , state | (val << 2 ))
268
268
269
269
@property
270
- def gain (self ) -> int :
270
+ def gain (self ) -> float :
271
271
"""The gain for the sensor"""
272
272
return self ._gain
273
273
274
274
@gain .setter
275
- def gain (self , val : int ) -> None :
275
+ def gain (self , val : float ) -> None :
276
276
if val not in AS726x .GAIN :
277
277
raise ValueError ("Must be 1, 3.7, 16 or 64" )
278
278
if self ._gain == val :
@@ -394,10 +394,10 @@ def raw_red(self) -> int:
394
394
"""Raw red (650nm) 16-bit value"""
395
395
return self .read_channel (_AS7262_RED )
396
396
397
- def _virtual_read (self , addr : int ) -> int :
397
+ def _virtual_read (self , addr : int ) -> Union [ int , float ] :
398
398
raise NotImplementedError ("Must be implemented." )
399
399
400
- def _virtual_write (self , addr : int , value : int ) -> None :
400
+ def _virtual_write (self , addr : int , value : Union [ int , float ] ) -> None :
401
401
raise NotImplementedError ("Must be implemented." )
402
402
403
403
@@ -439,7 +439,7 @@ class AS726x_I2C(AS726x):
439
439
440
440
"""
441
441
442
- def __init__ (self , i2c_bus : busio .I2C , address : int = _AS726X_ADDRESS ):
442
+ def __init__ (self , i2c_bus : busio .I2C , address : int = _AS726X_ADDRESS ) -> None :
443
443
self .i2c_device = I2CDevice (i2c_bus , address )
444
444
super ().__init__ ()
445
445
@@ -460,7 +460,7 @@ def __write_u8(self, command: int, abyte: int) -> None:
460
460
with self .i2c_device as i2c :
461
461
i2c .write (buf )
462
462
463
- def _virtual_read (self , addr : int ) -> int :
463
+ def _virtual_read (self , addr : int ) -> Union [ int , float ] :
464
464
"""read a virtual register"""
465
465
while True :
466
466
# Read slave I2C status to see if the read buffer is ready.
@@ -480,7 +480,7 @@ def _virtual_read(self, addr: int) -> int:
480
480
data = self ._read_u8 (_AS726X_SLAVE_READ_REG )
481
481
return data
482
482
483
- def _virtual_write (self , addr : int , value : int ) -> None :
483
+ def _virtual_write (self , addr : int , value : Union [ int , float ] ) -> None :
484
484
"""write a virtual register"""
485
485
while True :
486
486
# Read slave I2C status to see if the write buffer is ready.
@@ -536,20 +536,20 @@ class AS726x_UART(AS726x):
536
536
537
537
"""
538
538
539
- def __init__ (self , uart : busio .UART ):
539
+ def __init__ (self , uart : busio .UART ) -> None :
540
540
self ._uart = uart
541
541
self ._uart .baudrate = 115200
542
542
super ().__init__ ()
543
543
544
- def read_channel (self , channel : int ) -> int :
544
+ def read_channel (self , channel : int ) -> float :
545
545
"""Read an individual sensor channel"""
546
546
return self ._virtual_read (channel )
547
547
548
548
def read_calibrated_value (self , channel : int ) -> float :
549
549
"""Read a calibrated sensor channel"""
550
550
return self ._virtual_read (channel )
551
551
552
- def _uart_xfer (self , cmd : int ) -> int :
552
+ def _uart_xfer (self , cmd : Optional [ str ] ) -> str :
553
553
self ._uart .reset_input_buffer ()
554
554
cmd += "\n "
555
555
self ._uart .write (cmd .encode ())
@@ -559,7 +559,7 @@ def _uart_xfer(self, cmd: int) -> int:
559
559
return resp .rstrip (b" OK\n " )
560
560
return None
561
561
562
- def _virtual_read (self , addr : int ) -> int :
562
+ def _virtual_read (self , addr : int ) -> Union [ int , float ] :
563
563
if addr == _AS726X_HW_VERSION :
564
564
# just return what is expected
565
565
return 0x40
@@ -582,7 +582,7 @@ def _virtual_read(self, addr: int) -> int:
582
582
resp = resp .decode ().split ("," )
583
583
return float (resp [_COLOR_REGS_CALIBRATED .index (addr )])
584
584
585
- def _virtual_write (self , addr : int , value : int ) -> None :
585
+ def _virtual_write (self , addr : int , value : Union [ int , float ] ) -> None :
586
586
if addr == _AS726X_CONTROL_SETUP :
587
587
# check for reset
588
588
if (value >> 7 ) & 0x01 :
0 commit comments