From a95e0305aeaffadf071e963863c102b30b76993a Mon Sep 17 00:00:00 2001 From: jaseg Date: Fri, 27 Dec 2013 03:02:26 +0100 Subject: Some fixes to the host software geom stuff, added a small demo script --- host/matelight/config.py | 22 +++++++++++++--------- host/matelight/host.py | 21 ++++++++++++--------- host/matelight/nyancat-test.py | 29 +++++++++++++++++++++++++++++ host/nyancat.png | Bin 0 -> 483 bytes host/nyancat.xcf | Bin 0 -> 1658 bytes host/nyancat2.png | Bin 0 -> 477 bytes host/nyancat2.xcf | Bin 0 -> 1655 bytes host/scroller.png | Bin 0 -> 1557 bytes 8 files changed, 54 insertions(+), 18 deletions(-) create mode 100755 host/matelight/nyancat-test.py create mode 100644 host/nyancat.png create mode 100644 host/nyancat.xcf create mode 100644 host/nyancat2.png create mode 100644 host/nyancat2.xcf create mode 100644 host/scroller.png (limited to 'host') diff --git a/host/matelight/config.py b/host/matelight/config.py index 2177292..2bc97c1 100644 --- a/host/matelight/config.py +++ b/host/matelight/config.py @@ -9,23 +9,27 @@ DEFAULT_SCROLL_SPEED = 4 # Pixels to leave blank between two letters LETTER_SPACING = 1 -FONT = bdflib.reader.read_bdf(open('fonts/5x8.bdf').readlines()) -FONT_WIDTH = 5 +#FONT = bdflib.reader.read_bdf(open('fonts/5x8.bdf').readlines()) +#FONT_WIDTH = 5 # Computed value -FONT_PADDED_BINARY = ('{:0'+str(FONT_WIDTH+'b}').format +#FONT_PADDED_BINARY = ('{:0'+str(FONT_WIDTH+'b}').format # Display geometry # ┌─────────┐ ┌───┬───┬ ⋯ ┬───┬───┐ -# │1 o o o 5│ │ 1 │ │ │ │16 │ +# │1 o o o 5│ │ 1 │ │ │ │ 8│ # │6 o o o o│ ├───┼───┼ ⋯ ┼───┼───┤ -# │o o o o o│ │17 │ │ │ │32 │ -# │o o o o20│ └───┴───┴ ⋯ ┴───┴───┘ -# └─────────┘ +# │o o o o o│ │ 9 │ │ │ │16 │ +# │o o o o20│ ├───┼───┼ ⋯ ┼───┼───┤ +# └─────────┘ │17 │ │ │ │24 │ +# ├───┼───┼ ⋯ ┼───┼───┤ +# │25 │ │ │ │32 │ +# └───┴───┴ ⋯ ┴───┴───┘ + CRATE_WIDTH = 5 CRATE_HEIGHT = 4 -CRATES_X = 16 -CRATES_Y = 2 +CRATES_X = 8 +CRATES_Y = 4 # Computed values DISPLAY_WIDTH = CRATES_X * CRATE_WIDTH diff --git a/host/matelight/host.py b/host/matelight/host.py index 461a4fa..394c299 100644 --- a/host/matelight/host.py +++ b/host/matelight/host.py @@ -1,16 +1,19 @@ -from pyusb import usb +import usb import colorsys import numpy as np +from config import * +import itertools dev = usb.core.find(idVendor=0x1cbe, idProduct=0x0003) def sendframe(framedata): - if not isinstance(framedata, np.array) or framedata.shape != (DISPLAY_WIDTH, DISPLAY_HEIGHT, 3) or framedata.dtype != np.int8: - raise ValueError('framedata must be a ({}, {}, 3)-numpy array of int8s'.format(DISPLAY_WIDTH, DISPLAY_HEIGHT)) + # not isinstance(framedata, np.array) or + if framedata.shape != (DISPLAY_HEIGHT, DISPLAY_WIDTH, 3) or framedata.dtype != np.uint8: + raise ValueError('framedata must be a ({}, {}, 3)-numpy array of int8s. Got a {}-numpy array of {}'.format(DISPLAY_WIDTH, DISPLAY_HEIGHT, framedata.shape, framedata.dtype)) - for cx, cy in itertools.product(range(16), range(2)): - cratedata = framedata[cx*CRATE_WIDTH:(cx+1)*CRATE_WIDTH, cy*CRATE_HEIGHT:(cy+1)*CRATE_HEIGHT] - # Send framebuffer data - dev.write(0x01, bytes([0, x, y])+bytes(list(cratedata.flatten()))) - # Send latch command - dev.write(0x01, b'\x01') + for cy, cx in itertools.product(range(CRATES_Y), range(CRATES_X)): + cratedata = framedata[cy*CRATE_HEIGHT:(cy+1)*CRATE_HEIGHT, cx*CRATE_WIDTH:(cx+1)*CRATE_WIDTH] + # Send framebuffer data + dev.write(0x01, bytes([0, cx, cy])+bytes(list(cratedata.flatten()))) + # Send latch command + dev.write(0x01, b'\x01') diff --git a/host/matelight/nyancat-test.py b/host/matelight/nyancat-test.py new file mode 100755 index 0000000..aaabe85 --- /dev/null +++ b/host/matelight/nyancat-test.py @@ -0,0 +1,29 @@ +#!/usr/bin/env python3 +import host +import numpy as np +from config import * +from PIL import Image, ImageSequence +import time + +img1 = Image.open(open('../nyancat.png', 'rb')) +img2 = Image.open(open('../nyancat2.png', 'rb')) +scroller = Image.open(open('../scroller.png', 'rb')) +datas = [] +for img in [img1, img2]: + im = img.convert("RGB") + im.thumbnail((DISPLAY_WIDTH, DISPLAY_HEIGHT), Image.NEAREST) + data = np.array(im.getdata(), dtype=np.uint8) + datas += [data.reshape((DISPLAY_HEIGHT, DISPLAY_WIDTH, 3))] + +im = scroller.convert("RGB") +bar = np.array(im.getdata(), dtype=np.uint8) +foo = bar.reshape((DISPLAY_HEIGHT, 300, 3)) + +while True: + for i in range(20): + for data in datas: + host.sendframe(data) + time.sleep(0.1) + for i in range(260): + host.sendframe(foo[:, i:i+40, :]) + diff --git a/host/nyancat.png b/host/nyancat.png new file mode 100644 index 0000000..1e0bf80 Binary files /dev/null and b/host/nyancat.png differ diff --git a/host/nyancat.xcf b/host/nyancat.xcf new file mode 100644 index 0000000..af439e2 Binary files /dev/null and b/host/nyancat.xcf differ diff --git a/host/nyancat2.png b/host/nyancat2.png new file mode 100644 index 0000000..7e4cbd4 Binary files /dev/null and b/host/nyancat2.png differ diff --git a/host/nyancat2.xcf b/host/nyancat2.xcf new file mode 100644 index 0000000..e340edd Binary files /dev/null and b/host/nyancat2.xcf differ diff --git a/host/scroller.png b/host/scroller.png new file mode 100644 index 0000000..2257626 Binary files /dev/null and b/host/scroller.png differ -- cgit