Update pixelcontrol with most recent datagen
parent
423d9f66b3
commit
d30db8879f
|
@ -4,15 +4,19 @@ from prepare import prepare
|
||||||
|
|
||||||
# Config, will be checked upstream
|
# Config, will be checked upstream
|
||||||
height = 25
|
height = 25
|
||||||
width = 20
|
width = 15
|
||||||
framerate = 40
|
framerate = 10
|
||||||
brightness = 0.1
|
brightness = 0.4
|
||||||
#####################################
|
#####################################
|
||||||
receiver_IP = "127.0.0.1"
|
#receiver_IP = "10.2.113.151"
|
||||||
|
receiver_IP = "10.24.146.53"
|
||||||
|
#receiver_IP = "127.0.0.1"
|
||||||
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 = True
|
||||||
|
# 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
|
||||||
|
@ -26,7 +30,7 @@ def setup():
|
||||||
global data
|
global data
|
||||||
ledTCP, data = prepare(Client, receiver_IP, receiver_port, height, width, framerate, brightness)
|
ledTCP, data = prepare(Client, receiver_IP, receiver_port, height, width, framerate, brightness)
|
||||||
background(0)
|
background(0)
|
||||||
send_TCP(ledTCP, data, long_line)
|
send_TCP(ledTCP, data, long_line, type)
|
||||||
|
|
||||||
def draw():
|
def draw():
|
||||||
global current_px
|
global current_px
|
||||||
|
@ -40,4 +44,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)
|
||||||
|
|
|
@ -47,16 +47,81 @@ 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()
|
||||||
|
inline_image = []
|
||||||
|
if type in [0, 2, 4, 6]:
|
||||||
|
# Organized up or down
|
||||||
|
for x in range(0, width):
|
||||||
|
inline_image += make_line(type, x, long_line)
|
||||||
|
elif type in [1, 3, 5, 7]:
|
||||||
|
# Organized left or right
|
||||||
for x in range(0, height):
|
for x in range(0, height):
|
||||||
pixel_line = pixels[pixel_nb:pixel_nb+width]
|
inline_image += make_line(type, x, long_line)
|
||||||
if long_line and pixel_nb/width%2 == 1:
|
for img_px in inline_image:
|
||||||
pixel_line = reversed(pixel_line)
|
py_bytes = _encode_pixel(img_px)
|
||||||
for px in pixel_line:
|
|
||||||
py_bytes = _encode_pixel(px)
|
|
||||||
for b in py_bytes:
|
for b in py_bytes:
|
||||||
if b > 127:
|
if b > 127:
|
||||||
# Convert to signed bytes (expected by jarray)
|
# Convert to signed bytes (expected by jarray)
|
||||||
|
@ -65,7 +130,6 @@ def image2data(data, long_line):
|
||||||
else:
|
else:
|
||||||
data[offset] = b
|
data[offset] = b
|
||||||
offset += 1
|
offset += 1
|
||||||
pixel_nb +=1
|
|
||||||
# New line
|
# New line
|
||||||
data[-1] = 10
|
data[-1] = 10
|
||||||
return data
|
return data
|
||||||
|
|
|
@ -28,6 +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):
|
||||||
image2data(data, long_line)
|
if socket is None:
|
||||||
|
# Dummy mode
|
||||||
|
return
|
||||||
|
image2data(data, type, long_line)
|
||||||
socket.write(data)
|
socket.write(data)
|
||||||
|
|
|
@ -12,7 +12,10 @@ def check_config(max_height, max_width, max_framerate, height, width, framerate)
|
||||||
|
|
||||||
def prepare(cl_class, server_ip, server_port, height, width, framerate, brightness):
|
def prepare(cl_class, server_ip, server_port, height, width, framerate, brightness):
|
||||||
# Just to make sure pixels[] is initialized.
|
# Just to make sure pixels[] is initialized.
|
||||||
|
if server_ip == 'dummy':
|
||||||
|
size(width, height)
|
||||||
loadPixels()
|
loadPixels()
|
||||||
|
return None, None
|
||||||
ledTCP = TCPConfigure(cl_class, server_ip, server_port)
|
ledTCP = TCPConfigure(cl_class, server_ip, server_port)
|
||||||
max_height, max_width, max_framerate = receive_config(ledTCP)
|
max_height, max_width, max_framerate = receive_config(ledTCP)
|
||||||
good, reason = check_config(max_height, max_width, max_framerate, height, width, framerate)
|
good, reason = check_config(max_height, max_width, max_framerate, height, width, framerate)
|
||||||
|
@ -20,6 +23,7 @@ def prepare(cl_class, server_ip, server_port, height, width, framerate, brightne
|
||||||
raise Exception(reason)
|
raise Exception(reason)
|
||||||
send_config(ledTCP, height, width, framerate)
|
send_config(ledTCP, height, width, framerate)
|
||||||
size(width, height)
|
size(width, height)
|
||||||
|
loadPixels()
|
||||||
dimension = width * height
|
dimension = width * height
|
||||||
data = prepare_data(dimension, brightness)
|
data = prepare_data(dimension, brightness)
|
||||||
return ledTCP, data
|
return ledTCP, data
|
||||||
|
|
Loading…
Reference in New Issue