You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
839 B
34 lines
839 B
7 years ago
|
import gex
|
||
|
|
||
|
class Neopixel(gex.Unit):
|
||
|
"""
|
||
|
Raw access to a neopixel strip.
|
||
|
"""
|
||
|
|
||
|
def _type(self):
|
||
7 years ago
|
return 'NPX'
|
||
7 years ago
|
|
||
|
def get_len(self):
|
||
|
""" Get the neopixel strip length """
|
||
7 years ago
|
resp = self._query(10)
|
||
7 years ago
|
pp = gex.PayloadParser(resp)
|
||
|
return pp.u16()
|
||
|
|
||
7 years ago
|
def load(self, colors, reverse=True, confirm=True):
|
||
7 years ago
|
"""
|
||
|
Load colors to the strip.
|
||
|
|
||
|
The numbers are normally 0xRRGGBB
|
||
|
If 'reverse' is false, they're treated as little-endian: 0xBBGGRR.
|
||
|
"""
|
||
|
pb = gex.PayloadBuilder(endian='big' if reverse else 'little')
|
||
|
for c in colors:
|
||
|
pb.u24(c)
|
||
7 years ago
|
self._send(1, pb.close(), confirm=confirm)
|
||
7 years ago
|
|
||
7 years ago
|
def clear(self, confirm=True):
|
||
7 years ago
|
"""
|
||
|
Reset the strip (set all to black)
|
||
|
"""
|
||
7 years ago
|
self._send(0, confirm=confirm)
|