38
38
"""
39
39
40
40
# imports
41
+ try :
42
+ from typing import Union
43
+
44
+ from adafruit_dotstar import DotStar
45
+ from neopixel import NeoPixel
46
+ except ImportError :
47
+ pass
41
48
42
- from micropython import const
43
49
import adafruit_framebuf
44
50
from adafruit_led_animation .grid import PixelGrid
51
+ from micropython import const
45
52
46
53
__version__ = "0.0.0+auto.0"
47
54
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_Pixel_Framebuf.git"
48
55
49
- HORIZONTAL = const (1 )
50
- VERTICAL = const (2 )
56
+ HORIZONTAL : int = const (1 )
57
+ VERTICAL : int = const (2 )
58
+
51
59
52
60
# pylint: disable=too-many-function-args
53
61
class PixelFramebuffer (adafruit_framebuf .FrameBuffer ):
@@ -59,6 +67,7 @@ class PixelFramebuffer(adafruit_framebuf.FrameBuffer):
59
67
:param width: Framebuffer width.
60
68
:param height: Framebuffer height.
61
69
:param orientation: Orientation of the strip pixels - HORIZONTAL (default) or VERTICAL.
70
+ HORIZONTAL and VERTICAL are primitive integers created by micropython.const(x).
62
71
:param alternating: Whether the strip alternates direction from row to row (default True).
63
72
:param reverse_x: Whether the strip X origin is on the right side (default False).
64
73
:param reverse_y: Whether the strip Y origin is on the bottom (default False).
@@ -70,17 +79,17 @@ class PixelFramebuffer(adafruit_framebuf.FrameBuffer):
70
79
71
80
def __init__ (
72
81
self ,
73
- pixels ,
74
- width ,
75
- height ,
76
- orientation = HORIZONTAL ,
77
- alternating = True ,
78
- reverse_x = False ,
79
- reverse_y = False ,
80
- top = 0 ,
81
- bottom = 0 ,
82
- rotation = 0 ,
83
- ): # pylint: disable=too-many-arguments
82
+ pixels : Union [ NeoPixel , DotStar ] ,
83
+ width : int ,
84
+ height : int ,
85
+ orientation : int = HORIZONTAL ,
86
+ alternating : bool = True ,
87
+ reverse_x : bool = False ,
88
+ reverse_y : bool = False ,
89
+ top : int = 0 ,
90
+ bottom : int = 0 ,
91
+ rotation : int = 0 ,
92
+ ) -> None : # pylint: disable=too-many-arguments
84
93
self ._width = width
85
94
self ._height = height
86
95
@@ -98,26 +107,19 @@ def __init__(
98
107
99
108
self ._buffer = bytearray (width * height * 3 )
100
109
self ._double_buffer = bytearray (width * height * 3 )
101
- super ().__init__ (
102
- self ._buffer , width , height , buf_format = adafruit_framebuf .RGB888
103
- )
110
+ super ().__init__ (self ._buffer , width , height , buf_format = adafruit_framebuf .RGB888 )
104
111
self .rotation = rotation
105
112
106
- def blit (self ):
113
+ def blit (self ) -> None :
107
114
"""blit is not yet implemented"""
108
115
raise NotImplementedError ()
109
116
110
- def display (self ):
117
+ def display (self ) -> None :
111
118
"""Copy the raw buffer changes to the grid and show"""
112
119
for _y in range (self ._height ):
113
120
for _x in range (self ._width ):
114
121
index = (_y * self .stride + _x ) * 3
115
- if (
116
- self ._buffer [index : index + 3 ]
117
- != self ._double_buffer [index : index + 3 ]
118
- ):
122
+ if self ._buffer [index : index + 3 ] != self ._double_buffer [index : index + 3 ]:
119
123
self ._grid [(_x , _y )] = tuple (self ._buffer [index : index + 3 ])
120
- self ._double_buffer [index : index + 3 ] = self ._buffer [
121
- index : index + 3
122
- ]
124
+ self ._double_buffer [index : index + 3 ] = self ._buffer [index : index + 3 ]
123
125
self ._grid .show ()
0 commit comments