36
36
__version__ = "0.0.0-auto.0"
37
37
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_DotStar.git"
38
38
39
+ START_HEADER_SIZE = 4
40
+
39
41
# Pixel color order constants
40
42
RGB = (0 , 1 , 2 )
41
43
RBG = (0 , 2 , 1 )
@@ -89,19 +91,18 @@ def __init__(self, clock, data, n, *, brightness=1.0, auto_write=True, pixel_ord
89
91
self .cpin .direction = digitalio .Direction .OUTPUT
90
92
self .cpin .value = False
91
93
self ._n = n
92
- self .start_header_size = 4
93
94
# Supply one extra clock cycle for each two pixels in the strip.
94
95
self .end_header_size = n // 16
95
96
if n % 16 != 0 :
96
97
self .end_header_size += 1
97
- self ._buf = bytearray (n * 4 + self . start_header_size + self .end_header_size )
98
+ self ._buf = bytearray (n * 4 + START_HEADER_SIZE + self .end_header_size )
98
99
self .end_header_index = len (self ._buf ) - self .end_header_size
99
100
self .pixel_order = pixel_order
100
101
# Four empty bytes to start.
101
- for i in range (self . start_header_size ):
102
+ for i in range (START_HEADER_SIZE ):
102
103
self ._buf [i ] = 0x00
103
104
# Mark the beginnings of each pixel.
104
- for i in range (self . start_header_size , self .end_header_index , 4 ):
105
+ for i in range (START_HEADER_SIZE , self .end_header_index , 4 ):
105
106
self ._buf [i ] = 0xff
106
107
# 0xff bytes at the end.
107
108
for i in range (self .end_header_index , len (self ._buf )):
@@ -116,7 +117,7 @@ def __init__(self, clock, data, n, *, brightness=1.0, auto_write=True, pixel_ord
116
117
def deinit (self ):
117
118
"""Blank out the DotStars and release the resources."""
118
119
self .auto_write = False
119
- for i in range (self . start_header_size , self .end_header_index ):
120
+ for i in range (START_HEADER_SIZE , self .end_header_index ):
120
121
if i % 4 != 0 :
121
122
self ._buf [i ] = 0
122
123
self .show ()
@@ -136,7 +137,7 @@ def __repr__(self):
136
137
return "[" + ", " .join ([str (x ) for x in self ]) + "]"
137
138
138
139
def _set_item (self , index , value ):
139
- offset = index * 4 + self . start_header_size
140
+ offset = index * 4 + START_HEADER_SIZE
140
141
rgb = value
141
142
if isinstance (value , int ):
142
143
rgb = (value >> 16 , (value >> 8 ) & 0xff , value & 0xff )
@@ -171,14 +172,14 @@ def __getitem__(self, index):
171
172
out = []
172
173
for in_i in range (* index .indices (len (self ._buf ) // 4 )):
173
174
out .append (
174
- tuple (self ._buf [in_i * 4 + (3 - i ) + self . start_header_size ] for i in range (3 )))
175
+ tuple (self ._buf [in_i * 4 + (3 - i ) + START_HEADER_SIZE ] for i in range (3 )))
175
176
return out
176
177
if index < 0 :
177
178
index += len (self )
178
179
if index >= self ._n or index < 0 :
179
180
raise IndexError
180
181
offset = index * 4
181
- return tuple (self ._buf [offset + (3 - i ) + self . start_header_size ]
182
+ return tuple (self ._buf [offset + (3 - i ) + START_HEADER_SIZE ]
182
183
for i in range (3 ))
183
184
184
185
def __len__ (self ):
@@ -224,9 +225,9 @@ def show(self):
224
225
if self .brightness < 1.0 :
225
226
buf = bytearray (self ._buf )
226
227
# Four empty bytes to start.
227
- for i in range (self . start_header_size ):
228
+ for i in range (START_HEADER_SIZE ):
228
229
buf [i ] = 0x00
229
- for i in range (self . start_header_size , self .end_header_index ):
230
+ for i in range (START_HEADER_SIZE , self .end_header_index ):
230
231
buf [i ] = self ._buf [i ] if i % 4 == 0 else int (self ._buf [i ] * self ._brightness )
231
232
# Four 0xff bytes at the end.
232
233
for i in range (self .end_header_index , len (buf )):
0 commit comments