From 18fd12e916c8a33007a8ccd305d280493e8cd27d Mon Sep 17 00:00:00 2001 From: jaseg Date: Mon, 17 Feb 2014 00:57:47 +0100 Subject: ctypes pointer narf working now --- host/matelight.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'host/matelight.py') diff --git a/host/matelight.py b/host/matelight.py index f75ae80..55295f6 100644 --- a/host/matelight.py +++ b/host/matelight.py @@ -1,7 +1,7 @@ import usb import colorsys import numpy as np -import itertools +from itertools import product CRATE_WIDTH = 5 CRATE_HEIGHT = 4 @@ -20,16 +20,20 @@ def sendframe(framedata): The argument contains a h * w array of 3-tuples of (r, g, b)-data or 4-tuples of (r, g, b, a)-data where the a channel is ignored. """ - def chunks(l, n): - for i in xrange(0, len(l), n): - yield l[i:i+n] - - for cx, cy in itertools.product(range(DISPLAY_WIDTH), range(DISPLAY_HEIGHT)): + for cx, cy in product(range(CRATES_X), range(CRATES_Y)): data = [ v for x in range(CRATE_WIDTH) for y in range(CRATE_HEIGHT) for v in framedata[cy*CRATE_HEIGHT + y][cx*CRATE_WIDTH + x][:3] ] +# data = [0,0,0]*CRATE_WIDTH*CRATE_HEIGHT +# for x, y in product(range(CRATE_WIDTH), range(CRATE_HEIGHT)): +# r, g, b, _ = framedata[cy*CRATE_HEIGHT + y][cx*CRATE_WIDTH + x] +# data[x*3 + y*CRATE_WIDTH*3 + 0] = r +# data[x*3 + y*CRATE_WIDTH*3 + 1] = g +# data[x*3 + y*CRATE_WIDTH*3 + 2] = b +# print(r, g, b) + #data = [ framedata[DISPLAY_WIDTH*3*(cy*CRATE_HEIGHT + y) + 3*(cx*CRATE_WIDTH + x)+c] for x in range(CRATE_WIDTH) for y in range(CRATE_HEIGHT) for c in range(3) ] if len(data) != FRAME_SIZE: raise ValueError('Invalid frame data. Expected {} bytes, got {}.'.format(FRAME_SIZE, len(data))) # Send framebuffer data - dev.write(0x01, bytes([0, x, y])+bytes(data)) + dev.write(0x01, bytes([0, cx, cy])+bytes(data)) # Send latch command dev.write(0x01, b'\x01') -- cgit