From 7e2c51dc2645c4dffe7cc33e8533f0667b8775a6 Mon Sep 17 00:00:00 2001 From: jaseg Date: Sun, 29 Dec 2013 02:52:28 +0100 Subject: Added basic text rendering & TCP server --- firmware/main.c | 9 +++++ host/matelight/config.py | 9 +---- host/matelight/host.py | 2 +- host/matelight/listeners.py | 80 ++++++++++++++++++++++++++++++++++++------ host/matelight/nyancat-test.py | 2 +- host/matelight/renderers.py | 55 ++++++++++++++++------------- 6 files changed, 113 insertions(+), 44 deletions(-) mode change 100644 => 100755 host/matelight/listeners.py diff --git a/firmware/main.c b/firmware/main.c index 93351cb..5abb851 100644 --- a/firmware/main.c +++ b/firmware/main.c @@ -61,6 +61,13 @@ unsigned const char const BOTTLE_MAP[CRATE_SIZE] = { 0, 1, 2, 3, 4 }; +unsigned const char const FUCKED_UP_BOTTLE_MAP[CRATE_SIZE] = { + 3, 4, 5, 6, 7, + 2, 11, 10, 9, 8, + 1, 12, 13, 14, 15, + 0, 19, 18, 17, 16 +}; + unsigned const char const CRATE_MAP[CRATE_COUNT] = { 0x37, 0x35, 0x33, 0x31, 0x21, 0x23, 0x25, 0x27, 0x36, 0x34, 0x32, 0x30, 0x20, 0x22, 0x24, 0x26, @@ -157,6 +164,8 @@ unsigned long framebuffer_read(void *data, unsigned long len) { for(unsigned int x=0; x 140: + self.request.sendall('TOO MUCH INFORMATION!\n') + return + global renderer, count + print(data+'\x1B[0m') + renderer = renderers.TextRenderer(data) + count = 3 + self.request.sendall(b'KTHXBYE!\n') + except: + pass + +TCPServer.allow_reuse_address = True +server = TCPServer(('', 1337), MateLightTCPTextHandler) +t = threading.Thread(target=server.serve_forever) +t.daemon = True +t.start() + +UDPServer.allow_reuse_address = True +userver = UDPServer(('', 1337), MateLightUDPHandler) +t = threading.Thread(target=userver.serve_forever) +t.daemon = True +t.start() + +while True: + global renderer, count + foo = renderer + if count == 0: + renderer = default_renderer + else: + count = count - 1 + for frame, delay in foo.frames(): + #print(list(frame.flatten())) + host.sendframe(np.swapaxes(frame, 0, 1)) + #time.sleep(delay) diff --git a/host/matelight/nyancat-test.py b/host/matelight/nyancat-test.py index aaabe85..73fd28e 100755 --- a/host/matelight/nyancat-test.py +++ b/host/matelight/nyancat-test.py @@ -20,7 +20,7 @@ bar = np.array(im.getdata(), dtype=np.uint8) foo = bar.reshape((DISPLAY_HEIGHT, 300, 3)) while True: - for i in range(20): + for i in range(60): for data in datas: host.sendframe(data) time.sleep(0.1) diff --git a/host/matelight/renderers.py b/host/matelight/renderers.py index 0e223a2..f507513 100644 --- a/host/matelight/renderers.py +++ b/host/matelight/renderers.py @@ -1,11 +1,13 @@ -import numpy as np +import time try: import re2 as re except ImportError: import re +import numpy as np from PIL import Image from pixelterm import xtermcolors from config import * +from font import * default_palette = [ (0x00, 0x00, 0x00), # 0 normal colors @@ -24,17 +26,19 @@ default_palette = [ (0xff, 0x00, 0xff), # 13 (0x00, 0xff, 0xff), # 14 (0xff, 0xff, 0xff)] # 15 +default_colors = (default_palette[8], default_palette[0]) class CharGenerator: def __init__(self, seq=None, lg=None, text=''): - settings = False, False, False, default_palette[8], default_palette[0] + settings = False, False, False, default_colors if lg: - settings = lg,bold, lg.blink, lg.underscore, lg.fg, lg.bg - self.bold, self.blink, self.underscore, self.fg, self.bg = settings + settings = lg.bold, lg.blink, lg.underscore, (lg.fg, lg.bg) + self.bold, self.blink, self.underscore, (self.fg, self.bg) = settings self.text = text - self.parse_escape_sequence(seq) + if seq: + self.parse_escape_sequence(seq) - def parse_escape_sequence(seq): + def parse_escape_sequence(self, seq): codes = list(map(int, seq[2:-1].split(';'))) fg, bg, reverse, i = self.fg, self.bg, False, 0 while i