Initial tries to support different screen configurations.

master
Raphaël Vinot 2015-05-10 03:39:20 +02:00
parent 761a191da6
commit e2df6a69ef
3 changed files with 102 additions and 38 deletions

View File

@ -4,10 +4,10 @@ from prepare import prepare
import random import random
# Config, will be checked upstream # Config, will be checked upstream
height = 25 height = 15
width = 15 width = 25
framerate = 10 framerate = 30
brightness = 0.5 brightness = 1
##################################### #####################################
#receiver_IP = "10.2.113.151" #receiver_IP = "10.2.113.151"
#receiver_IP = "10.24.147.20" #receiver_IP = "10.24.147.20"
@ -15,7 +15,9 @@ receiver_IP = "dummy"
receiver_port = 9999 receiver_port = 9999
# Do we have one single long line? # Do we have one single long line?
long_line = True long_line = False
# Type of installation (see details in data_generator)
type = 2
# TODO: test with real serial # TODO: test with real serial
# https://www.pjrc.com/teensy/td_uart.html # https://www.pjrc.com/teensy/td_uart.html
@ -38,25 +40,24 @@ def setup():
cur_color = color(random.randint(0, 255), random.randint(0, 255), random.randint(0, 255)) cur_color = color(random.randint(0, 255), random.randint(0, 255), random.randint(0, 255))
ledTCP, data = prepare(Client, receiver_IP, receiver_port, height, width, framerate, brightness) ledTCP, data = prepare(Client, receiver_IP, receiver_port, height, width, framerate, brightness)
send_TCP(ledTCP, data, long_line) send_TCP(ledTCP, data, long_line, type)
def draw(): def draw():
global cur_len global cur_len
global current_px global current_px
global cur_color global cur_color
global len_change global len_change
if cur_len == 0: pixels[current_px] = cur_color
pixels[current_px] = cur_color px = current_px - 1
else: for i in range(cur_len + 1):
px = current_px if px == 0:
for i in range(cur_len): col = pixels[len(pixels) -1]
if px == 0: else:
prec_col = pixels[len(pixels) - 1] col = pixels[px]
else: if i == cur_len:
prec_col = pixels[px - 1] col = color(red(col) * 0.9, green(col) * 0.9, blue(col) * 0.9)
col = color(red(prec_col) / 1.1, green(prec_col) / 1.1, blue(prec_col) / 1.1) pixels[px] = col
pixels[px] = col px -=1
px -=1
updatePixels() updatePixels()
if cur_len == len_change: if cur_len == len_change:
@ -69,4 +70,4 @@ def draw():
current_px = 0 current_px = 0
else: else:
current_px += 1 current_px += 1
send_TCP(ledTCP, data, long_line) send_TCP(ledTCP, data, long_line, type)

View File

@ -47,25 +47,88 @@ def prepare_data(dimension, b):
data = jarray.zeros(dimension * 24 + 1, "b") data = jarray.zeros(dimension * 24 + 1, "b")
return data return data
def image2data(data, long_line): '''
Possibilities:
Start: Top left / Top Right / Bottom Left / Bottom Right
Direction: Up / Down / Right / Left
'''
def make_line(type, nb, long_line):
'''
If moving up or down: 0 <= nb <= height
If moving right or left: 0 <= nb <= width
'''
indexes = []
if type == 0:
# top left -> down / OK
pxstart = nb
for h in range(height):
indexes.append(pxstart + width * h)
elif type == 1:
# top left -> right / OK
pxstart = nb * width
for w in range((width)):
indexes.append(pxstart + w)
elif type == 2:
# bottom left -> up / OK
pxstart = width * (height - 1) + nb
for h in range(height):
indexes.append(pxstart - width * h)
elif type == 3:
# bottom left -> right / OK
pxstart = width * (height - 1) - nb * width
for w in range((width)):
indexes.append(pxstart + w)
elif type == 4:
# top right -> down / OK
pxstart = width - 1 - nb
for h in range(height):
indexes.append(pxstart + width * h)
elif type == 5:
# top right -> left / OK
pxstart = width - 1 + nb * width
for w in range((width)):
indexes.append(pxstart - w)
elif type == 6:
# bottom right -> up / OK
pxstart = width * height - 1 - nb * height
for h in range(height):
indexes.append(pxstart - width * h)
elif type == 7:
# bottom right -> left / OK
pxstart = width * height - 1 - nb * width
for w in range((width)):
indexes.append(pxstart - w)
else:
raise Exception("Invalid Type")
if long_line and nb % 2 == 1:
return reversed([pixels[px] for px in indexes])
return [pixels[px] for px in indexes]
def image2data(data, type, long_line):
offset = 0 offset = 0
pixel_nb = 0
loadPixels() loadPixels()
for x in range(0, height): inline_image = []
pixel_line = pixels[pixel_nb:pixel_nb+width] if type in [0, 2, 4, 6]:
if long_line and pixel_nb/width%2 == 1: # Organized up or down
pixel_line = reversed(pixel_line) for x in range(0, width):
for px in pixel_line: inline_image += make_line(type, x, long_line)
py_bytes = _encode_pixel(px) elif type in [1, 3, 5, 7]:
for b in py_bytes: # Organized left or right
if b > 127: for x in range(0, height):
# Convert to signed bytes (expected by jarray) inline_image += make_line(type, x, long_line)
b -= 256 for img_px in inline_image:
data[offset] = b py_bytes = _encode_pixel(img_px)
else: for b in py_bytes:
data[offset] = b if b > 127:
offset += 1 # Convert to signed bytes (expected by jarray)
pixel_nb +=1 b -= 256
data[offset] = b
else:
data[offset] = b
offset += 1
# New line # New line
data[-1] = 10 data[-1] = 10
return data return data

View File

@ -28,9 +28,9 @@ def send_config(socket, height, width, framerate):
socket.write(struct.pack('<i', width)) socket.write(struct.pack('<i', width))
socket.write(struct.pack('<i', framerate)) socket.write(struct.pack('<i', framerate))
def send_TCP(socket, data, long_line): def send_TCP(socket, data, long_line, type):
if socket is None: if socket is None:
# Dummy mode # Dummy mode
return return
image2data(data, long_line) image2data(data, type, long_line)
socket.write(data) socket.write(data)