10
10
"""
11
11
from adafruit_ht16k33 .ht16k33 import HT16K33
12
12
13
+ try :
14
+ from typing import Optional , Tuple , Union , List
15
+ from circuitpython_typing .pil import Image
16
+ from busio import I2C
17
+ except ImportError :
18
+ pass
19
+
13
20
14
21
__version__ = "0.0.0+auto.0"
15
22
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_HT16K33.git"
@@ -21,7 +28,7 @@ class Matrix8x8(HT16K33):
21
28
_columns = 8
22
29
_rows = 8
23
30
24
- def pixel (self , x , y , color = None ):
31
+ def pixel (self , x : int , y : int , color : Optional [ bool ] = None ) -> Optional [ bool ] :
25
32
"""Get or set the color of a given pixel.
26
33
27
34
:param int x: The x coordinate of the pixel
@@ -37,16 +44,16 @@ def pixel(self, x, y, color = None):
37
44
x = (x - 1 ) % 8
38
45
return super ()._pixel (x , y , color )
39
46
40
- def __getitem__ (self , key ) :
47
+ def __getitem__ (self , key : Tuple [ int , int ]) -> Optional [ bool ] :
41
48
x , y = key
42
49
return self .pixel (x , y )
43
50
44
- def __setitem__ (self , key , value ) :
51
+ def __setitem__ (self , key : Tuple [ int , int ], value : Optional [ bool ]) -> None :
45
52
x , y = key
46
53
self .pixel (x , y , value )
47
54
48
55
# pylint: disable=too-many-branches
49
- def shift (self , x , y , rotate = False ):
56
+ def shift (self , x : int , y : int , rotate : bool = False ) -> None :
50
57
"""
51
58
Shift pixels by x and y
52
59
@@ -90,39 +97,39 @@ def shift(self, x, y, rotate = False):
90
97
91
98
# pylint: enable=too-many-branches
92
99
93
- def shift_right (self , rotate = False ):
100
+ def shift_right (self , rotate : bool = False ) -> None :
94
101
"""
95
102
Shift all pixels right
96
103
97
104
:param rotate: (Optional) Rotate the shifted pixels to the left side (default=False)
98
105
"""
99
106
self .shift (1 , 0 , rotate )
100
107
101
- def shift_left (self , rotate = False ):
108
+ def shift_left (self , rotate : bool = False ) -> None :
102
109
"""
103
110
Shift all pixels left
104
111
105
112
:param rotate: (Optional) Rotate the shifted pixels to the right side (default=False)
106
113
"""
107
114
self .shift (- 1 , 0 , rotate )
108
115
109
- def shift_up (self , rotate = False ):
116
+ def shift_up (self , rotate : bool = False ) -> None :
110
117
"""
111
118
Shift all pixels up
112
119
113
120
:param rotate: (Optional) Rotate the shifted pixels to bottom (default=False)
114
121
"""
115
122
self .shift (0 , 1 , rotate )
116
123
117
- def shift_down (self , rotate = False ):
124
+ def shift_down (self , rotate : bool = False ) -> None :
118
125
"""
119
126
Shift all pixels down
120
127
121
128
:param rotate: (Optional) Rotate the shifted pixels to top (default=False)
122
129
"""
123
130
self .shift (0 , - 1 , rotate )
124
131
125
- def image (self , img ):
132
+ def image (self , img : Image ):
126
133
"""Set buffer to value of Python Imaging Library image. The image should
127
134
be in 1 bit mode and a size equal to the display size.
128
135
@@ -149,12 +156,12 @@ def image(self, img):
149
156
self .show ()
150
157
151
158
@property
152
- def columns (self ):
159
+ def columns (self ) -> int :
153
160
"""Read-only property for number of columns"""
154
161
return self ._columns
155
162
156
163
@property
157
- def rows (self ):
164
+ def rows (self ) -> int :
158
165
"""Read-only property for number of rows"""
159
166
return self ._rows
160
167
@@ -166,15 +173,15 @@ class Matrix16x8(Matrix8x8):
166
173
167
174
def __init__ (
168
175
self ,
169
- i2c ,
170
- address = 0x70 ,
171
- auto_write = True ,
172
- brightness = 1.0 ,
173
- ):
176
+ i2c : I2C ,
177
+ address : Union [ int , List [ int ], Tuple [ int , ...]] = 0x70 ,
178
+ auto_write : bool = True ,
179
+ brightness : float = 1.0 ,
180
+ ) -> None :
174
181
super ().__init__ (i2c , address , auto_write , brightness )
175
182
self ._columns *= len (self .i2c_device )
176
183
177
- def pixel (self , x , y , color = None ):
184
+ def pixel (self , x : int , y : int , color : Optional [ bool ] = None ) -> Optional [ bool ] :
178
185
"""Get or set the color of a given pixel.
179
186
180
187
:param int x: The x coordinate of the pixel
@@ -198,7 +205,7 @@ def pixel(self, x, y, color = None):
198
205
class MatrixBackpack16x8 (Matrix16x8 ):
199
206
"""A double matrix backpack."""
200
207
201
- def pixel (self , x , y , color = None ):
208
+ def pixel (self , x : int , y : int , color : Optional [ bool ] = None ) -> Optional [ bool ] :
202
209
"""Get or set the color of a given pixel.
203
210
204
211
:param int x: The x coordinate of the pixel
@@ -223,7 +230,7 @@ class Matrix8x8x2(Matrix8x8):
223
230
LED_GREEN = 2
224
231
LED_YELLOW = 3
225
232
226
- def pixel (self , x , y , color = None ):
233
+ def pixel (self , x : int , y : int , color : Optional [ int ] = None ) -> Optional [ int ] :
227
234
"""Get or set the color of a given pixel.
228
235
229
236
:param int x: The x coordinate of the pixel
@@ -243,7 +250,7 @@ def pixel(self, x, y, color = None):
243
250
return super ()._pixel (y , x ) | super ()._pixel (y + 8 , x ) << 1
244
251
return None
245
252
246
- def fill (self , color ) :
253
+ def fill (self , color : int ) -> None :
247
254
"""Fill the whole display with the given color.
248
255
249
256
:param bool color: Whether to fill the display
@@ -257,7 +264,7 @@ def fill(self, color):
257
264
if self ._auto_write :
258
265
self .show ()
259
266
260
- def image (self , img ) :
267
+ def image (self , img : Image ) -> None :
261
268
"""Set buffer to value of Python Imaging Library image. The image should
262
269
be a size equal to the display size.
263
270
0 commit comments