add support for long lines (one single LED strip)

master
Raphaël Vinot 2015-03-09 21:31:24 +01:00
parent db4bd6927b
commit 460c89f459
1 changed files with 21 additions and 20 deletions

View File

@ -8,7 +8,7 @@ errorCount = 0
framerate = 30 framerate = 30
dimension = 0 dimension = 0
long_line = False long_line = True
ledSerial = None ledSerial = None
data = None data = None
@ -42,27 +42,28 @@ def serialConfigure(portName):
def image2data(data): def image2data(data):
offset = 3 offset = 3
for x in xrange(0, dimension, 1): pixel_nb = 0
pixel = [colorWiring(pixels[x]) for i in range(0, 8)] for x in range(0, height):
imgmask = 0x800000 pixel_line = pixels[pixel_nb:pixel_nb+width]
while imgmask != 0: if long_line and pixel_nb/width%2 == 1:
b = 0 pixel_line = reversed(pixel_line)
for i in range(0, 8): for px in pixel_line:
if ((pixel[i] & imgmask) != 0): pixel = [colorWiring(px) for i in range(0, 8)]
b |= (1 << i) imgmask = 0x800000
if b > 127: while imgmask != 0:
# Convert to signed bytes (expected by jarray) b = 0
b -= 2**8 for i in range(0, 8):
if long_line: if ((pixel[i] & imgmask) != 0):
if x/width%2 == 0: b |= (1 << i)
if b > 127:
# Convert to signed bytes (expected by jarray)
b -= 2**8
data[offset] = b data[offset] = b
else: else:
# TODO: write data in the opposite order data[offset] = b
pass offset += 1
else: imgmask >>= 1
data[offset] = b pixel_nb +=1
offset += 1
imgmask >>= 1
def colorWiring(c): def colorWiring(c):
red = (c & 0xFF0000) >> 16 red = (c & 0xFF0000) >> 16