29
29
https://github.com/adafruit/Adafruit_CircuitPython_BusDevice
30
30
31
31
"""
32
+ import circuitpython_typing
32
33
33
34
try :
34
35
from typing import Union , Optional , List , Sequence
@@ -90,7 +91,7 @@ def _set_bit(byte_value: int, position: int, val: bool) -> int:
90
91
return ret
91
92
92
93
93
- def _map (xval : int , in_min : int , in_max : int , out_min : int , out_max : int ) -> float :
94
+ def _map (xval : float , in_min : float , in_max : float , out_min : float , out_max : float ) -> float :
94
95
# Affine transfer/map with constrained output.
95
96
outrange = float (out_max - out_min )
96
97
inrange = float (in_max - in_min )
@@ -489,7 +490,7 @@ def create_char(self, location: int, pattern: Sequence[int]) -> None:
489
490
To show your custom character use, for example, ``lcd.message = "\x01 "``
490
491
491
492
:param int location: Integer in range(8) to store the created character.
492
- :param Sequence pattern: len(8) describes created character.
493
+ :param Sequence[int] pattern: len(8) describes created character.
493
494
494
495
"""
495
496
# only position 0..7 are allowed
@@ -498,9 +499,9 @@ def create_char(self, location: int, pattern: Sequence[int]) -> None:
498
499
for i in range (8 ):
499
500
self ._write8 (pattern [i ], char_mode = True )
500
501
501
- def _write8 (self , value : [ int ] , char_mode : bool = False ) -> None :
502
+ def _write8 (self , value : int , char_mode : bool = False ) -> None :
502
503
# Sends 8b ``value`` in ``char_mode``.
503
- # :param value: bytes
504
+ # :param value: int
504
505
# :param char_mode: character/data mode selector. False (default) for
505
506
# data only, True for character bits.
506
507
# one ms delay to prevent writing too quickly.
@@ -708,15 +709,15 @@ def color(self) -> List[int]:
708
709
return self ._color
709
710
710
711
@color .setter
711
- def color (self , color : Union [List [int ], int ]) -> None :
712
+ def color (self , color : Union [List [float ], int ]) -> None :
712
713
if isinstance (color , int ):
713
714
if color >> 24 :
714
715
raise ValueError ("Integer color value must be positive and 24 bits max" )
715
716
# NOTE: convert to 0-100
716
- r = int (( color >> 16 ) / 2.55 )
717
- g = int ((( color >> 8 ) & 0xFF ) / 2.55 )
718
- b = int (( color & 0xFF ) / 2.55 )
719
- color = [r , g , b ] # This is List[float], should be List[int]
717
+ r = ( color >> 16 ) / 2.55
718
+ g = (( color >> 8 ) & 0xFF ) / 2.55
719
+ b = ( color & 0xFF ) / 2.55
720
+ color = [r , g , b ]
720
721
self ._color = color
721
722
for number , pin in enumerate (self .rgb_led ):
722
723
if hasattr (pin , "duty_cycle" ):
0 commit comments