24
24
except ImportError :
25
25
import adafruit_pypixelbuf as adafruit_pixelbuf
26
26
27
+ try :
28
+ from typing import Optional , Type
29
+ from types import TracebackType
30
+ from circuitpython_typing import ReadableBuffer
31
+ from microcontroller import Pin
32
+ except ImportError :
33
+ pass
34
+
27
35
__version__ = "0.0.0-auto.0"
28
36
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_DotStar.git"
29
37
@@ -95,15 +103,15 @@ class DotStar(adafruit_pixelbuf.PixelBuf):
95
103
96
104
def __init__ (
97
105
self ,
98
- clock ,
99
- data ,
100
- n ,
106
+ clock : Pin ,
107
+ data : Pin ,
108
+ n : int ,
101
109
* ,
102
- brightness = 1.0 ,
103
- auto_write = True ,
104
- pixel_order = BGR ,
105
- baudrate = 4000000
106
- ):
110
+ brightness : float = 1.0 ,
111
+ auto_write : bool = True ,
112
+ pixel_order : str = BGR ,
113
+ baudrate : int = 4000000
114
+ ) -> None :
107
115
self ._spi = None
108
116
try :
109
117
self ._spi = busio .SPI (clock , MOSI = data )
@@ -137,7 +145,7 @@ def __init__(
137
145
trailer = trailer ,
138
146
)
139
147
140
- def deinit (self ):
148
+ def deinit (self ) -> None :
141
149
"""Blank out the DotStars and release the resources."""
142
150
self .fill (0 )
143
151
self .show ()
@@ -147,29 +155,34 @@ def deinit(self):
147
155
self .dpin .deinit ()
148
156
self .cpin .deinit ()
149
157
150
- def __enter__ (self ):
158
+ def __enter__ (self ) -> "DotStar" :
151
159
return self
152
160
153
- def __exit__ (self , exception_type , exception_value , traceback ):
161
+ def __exit__ (
162
+ self ,
163
+ exception_type : Optional [Type [type ]],
164
+ exception_value : Optional [BaseException ],
165
+ traceback : Optional [TracebackType ],
166
+ ) -> None :
154
167
self .deinit ()
155
168
156
- def __repr__ (self ):
169
+ def __repr__ (self ) -> str :
157
170
return "[" + ", " .join ([str (x ) for x in self ]) + "]"
158
171
159
172
@property
160
- def n (self ):
173
+ def n (self ) -> int :
161
174
"""
162
175
The number of dotstars in the chain (read-only)
163
176
"""
164
177
return len (self )
165
178
166
- def _transmit (self , buffer ) :
179
+ def _transmit (self , buffer : ReadableBuffer ) -> None :
167
180
if self ._spi :
168
181
self ._spi .write (buffer )
169
182
else :
170
183
self ._ds_writebytes (buffer )
171
184
172
- def _ds_writebytes (self , buffer ) :
185
+ def _ds_writebytes (self , buffer : ReadableBuffer ) -> None :
173
186
for b in buffer :
174
187
for _ in range (8 ):
175
188
self .dpin .value = b & 0x80
0 commit comments