-
Notifications
You must be signed in to change notification settings - Fork 0
/
neopixel_emu.py
52 lines (40 loc) · 1.15 KB
/
neopixel_emu.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import tcolorpy
import adafruit_pixelbuf
__version__ = "0.1.0"
RGB = "RGB"
GRB = "GRB"
RGBW = "RGBW"
GRBW = "GRBW"
class NeoPixel(adafruit_pixelbuf.PixelBuf):
"""NeoPixel Emulator
Semi-compatible with the Adafruit CircuitPython Neopixel Module
"""
def __init__(
self,
pin,
n: int,
*,
bpp: int = 3,
brightness: float = 1.0,
auto_write: bool = True,
pixel_order: str = "RGB"
):
super().__init__(n, byteorder=pixel_order, brightness=brightness, auto_write=auto_write)
def deinit(self) -> None:
pass
def __enter__(self):
return self
def __repr__(self):
return "[" + ", ".join([str(x) for x in self]) + "]"
@property
def n(self) -> int:
""" Get the number of pixels """
return len(self)
def write(self) -> None:
""" Same as .show(), deprecated """
self.show()
def _transmit(self, _: bytearray) -> None:
termout = ""
for pixel in self:
termout += tcolorpy.tcolor("█", '#{:02x}{:02x}{:02x}'.format(*[int(i * self.brightness) for i in pixel]))
print(termout)