aboutsummaryrefslogtreecommitdiff
path: root/host
diff options
context:
space:
mode:
authorjaseg <jaseg@jaseg.net>2013-12-17 21:22:16 +0100
committerjaseg <jaseg@jaseg.net>2013-12-17 21:22:16 +0100
commit037b3fc1d453e60a3cca0cf0775f6397bd7337cb (patch)
treef3ebcedb4ec92b73f7e6aedb21342f8f61dd4811 /host
parent0bbcab655c9c8c4a08c4e18d1a20fd91b44b7612 (diff)
downloadmatelight-037b3fc1d453e60a3cca0cf0775f6397bd7337cb.tar.gz
matelight-037b3fc1d453e60a3cca0cf0775f6397bd7337cb.tar.bz2
matelight-037b3fc1d453e60a3cca0cf0775f6397bd7337cb.zip
First draft of transmit function based on standard python
Diffstat (limited to 'host')
-rw-r--r--host/host.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/host/host.py b/host/host.py
new file mode 100644
index 0000000..b19dc7a
--- /dev/null
+++ b/host/host.py
@@ -0,0 +1,32 @@
+from pyusb import usb
+import colorsys
+import numpy as np
+
+CRATE_WIDTH = 5
+CRATE_HEIGHT = 4
+CRATES_X = 16
+CRATES_Y = 2
+DISPLAY_WIDTH = CRATES_X * CRATE_WIDTH
+DISPLAY_HEIGHT = CRATES_Y * CRATE_HEIGHT
+FRAME_SIZE = CRATE_WIDTH*CRATE_HEIGHT*3
+
+dev = usb.core.find(idVendor=0x1cbe, idProduct=0x0003)
+
+def sendframe(framedata):
+ """ Send a frame to the display
+
+ The argument contains a h * w array of 3-tuples of (r, g, b)-data
+ """
+ def chunks(l, n):
+ for i in xrange(0, len(l), n):
+ yield l[i:i+n]
+
+ for cx, cy in itertools.product(range(16), range(2)):
+ 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] ]
+ 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))
+ # Send latch command
+ dev.write(0x01, b'\x01')
+