14
14
from adafruit_bus_device import i2c_device
15
15
from micropython import const
16
16
17
+ try :
18
+ from typing import Union , List , Tuple , Optional
19
+ from busio import I2C
20
+ except ImportError :
21
+ pass
22
+
17
23
18
24
__version__ = "0.0.0+auto.0"
19
25
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_HT16K33.git"
@@ -28,7 +34,7 @@ class HT16K33:
28
34
"""
29
35
The base class for all displays. Contains common methods.
30
36
31
- :param I2C i2c: The I2C bus object
37
+ :param ~busio. I2C i2c: The I2C bus object
32
38
:param int address: The I2C addess of the HT16K33.
33
39
:param bool auto_write: True if the display should immediately change when
34
40
set. If False, `show` must be called explicitly.
@@ -37,11 +43,11 @@ class HT16K33:
37
43
38
44
def __init__ (
39
45
self ,
40
- i2c ,
41
- address = 0x70 ,
42
- auto_write = True ,
43
- brightness = 1.0 ,
44
- ):
46
+ i2c : I2C ,
47
+ address : Union [ int , List [ int ], Tuple [ int , ...]] = 0x70 ,
48
+ auto_write : bool = True ,
49
+ brightness : float = 1.0 ,
50
+ ) -> None :
45
51
if isinstance (address , (tuple , list )):
46
52
self .i2c_device = []
47
53
for addr in address :
@@ -60,18 +66,18 @@ def __init__(
60
66
self .blink_rate = 0
61
67
self .brightness = brightness
62
68
63
- def _write_cmd (self , byte , i2c_index = 0 ):
69
+ def _write_cmd (self , byte : int , i2c_index : int = 0 ) -> None :
64
70
self ._temp [0 ] = byte
65
71
with self .i2c_device [i2c_index ]:
66
72
self .i2c_device [i2c_index ].write (self ._temp )
67
73
68
74
@property
69
- def blink_rate (self ):
75
+ def blink_rate (self ) -> int :
70
76
"""The blink rate. Range 0-3."""
71
77
return self ._blink_rate
72
78
73
79
@blink_rate .setter
74
- def blink_rate (self , rate = None ) :
80
+ def blink_rate (self , rate : int ) -> None :
75
81
if not 0 <= rate <= 3 :
76
82
raise ValueError ("Blink rate must be an integer in the range: 0-3" )
77
83
rate = rate & 0x03
@@ -82,12 +88,12 @@ def blink_rate(self, rate = None):
82
88
)
83
89
84
90
@property
85
- def brightness (self ):
91
+ def brightness (self ) -> float :
86
92
"""The brightness. Range 0.0-1.0"""
87
93
return self ._brightness
88
94
89
95
@brightness .setter
90
- def brightness (self , brightness ) :
96
+ def brightness (self , brightness : float ) -> None :
91
97
if not 0.0 <= brightness <= 1.0 :
92
98
raise ValueError (
93
99
"Brightness must be a decimal number in the range: 0.0-1.0"
@@ -100,18 +106,18 @@ def brightness(self, brightness):
100
106
self ._write_cmd (_HT16K33_CMD_BRIGHTNESS | xbright , index )
101
107
102
108
@property
103
- def auto_write (self ):
109
+ def auto_write (self ) -> bool :
104
110
"""Auto write updates to the display."""
105
111
return self ._auto_write
106
112
107
113
@auto_write .setter
108
- def auto_write (self , auto_write ) :
114
+ def auto_write (self , auto_write : bool ) -> None :
109
115
if isinstance (auto_write , bool ):
110
116
self ._auto_write = auto_write
111
117
else :
112
118
raise ValueError ("Must set to either True or False." )
113
119
114
- def show (self ):
120
+ def show (self ) -> None :
115
121
"""Refresh the display and show the changes."""
116
122
for index , i2c_dev in enumerate (self .i2c_device ):
117
123
with i2c_dev :
@@ -121,7 +127,7 @@ def show(self):
121
127
buffer = self ._buffer [offset : offset + self ._buffer_size ]
122
128
i2c_dev .write (buffer )
123
129
124
- def fill (self , color ) :
130
+ def fill (self , color : bool ) -> None :
125
131
"""Fill the whole display with the given color.
126
132
127
133
:param bool color: Whether to fill the display
@@ -134,7 +140,7 @@ def fill(self, color):
134
140
if self ._auto_write :
135
141
self .show ()
136
142
137
- def _pixel (self , x , y , color = None ):
143
+ def _pixel (self , x : int , y : int , color : Optional [ bool ] = None ) -> Optional [ bool ] :
138
144
offset = ((x // 16 ) + (y // 8 )) * self ._buffer_size
139
145
addr = 2 * (y % 8 ) + ((x % 16 ) // 8 )
140
146
addr = (addr % 16 ) + offset
@@ -151,8 +157,8 @@ def _pixel(self, x, y, color = None):
151
157
self .show ()
152
158
return None
153
159
154
- def _set_buffer (self , i , value ) :
160
+ def _set_buffer (self , i : int , value : int ) -> None :
155
161
self ._buffer [i + 1 ] = value # Offset by 1 to move past register address.
156
162
157
- def _get_buffer (self , i ) :
163
+ def _get_buffer (self , i : int ) -> int :
158
164
return self ._buffer [i + 1 ] # Offset by 1 to move past register address.
0 commit comments