def handle(self): try: # Housekeeping - FIXME: This is *so* the wrong place for this. for k,v in conns.items(): if time() - v.timestamp > UDP_TIMEOUT: del conns[k] global current_entry, conns data = self.request[0].strip() if len(data) != FRAME_SIZE*3+4: #raise ValueError('Invalid frame size: Expected {}, got {}'.format(FRAME_SIZE+4, len(data))) return frame = data[:-4] #crc1, = struct.unpack('!I', data[-4:]) #crc2, = zlib.crc32(frame, 0), #if crc1 != crc2: # raise ValueError('Invalid frame CRC checksum: Expected {}, got {}'.format(crc2, crc1)) #socket.sendto(b'ACK', self.client_address) a = np.array(list(frame), dtype=np.uint8) timestamp = time() addr = self.client_address[0] conn = QueueEntry('udp', addr, timestamp, '') if addr not in conns: log('New UDP connection from', addr) current_entry = conn conns[addr] = current_entry if current_entry.entrytype == 'udp' and current_entry.remote == addr: current_entry = conn frame = a.reshape((DISPLAY_HEIGHT, DISPLAY_WIDTH, 3)) sendframe(frame) printframe(np.pad(frame, ((0,0),(0,0),(0,1)), 'constant', constant_values=(0,0))) except Exception as e: log('Error receiving UDP frame:', e)
def scroll(text): """ Returns whether it could scroll all the text uninterrupted """ fb = render_text(text); h,w,_ = fb.shape for i in range(-DISPLAY_WIDTH,w+1): if current_entry.entrytype == 'udp' or (current_entry in defaulttexts and textqueue): return False leftpad = np.zeros((DISPLAY_HEIGHT, max(-i, 0), 4), dtype=np.uint8) framedata = fb[:, max(0, i):min(i+DISPLAY_WIDTH, w)] rightpad = np.zeros((DISPLAY_HEIGHT, min(DISPLAY_WIDTH, max(0, i+DISPLAY_WIDTH-w)), 4), dtype=np.uint8) dice = np.concatenate((leftpad, framedata, rightpad), 1) sendframe(dice) printframe(dice) fb = render_text(text); return True
def scroll(text): """ Returns whether it could scroll all the text uninterrupted """ fb = render_text(text) h, w, _ = fb.shape for i in range(-DISPLAY_WIDTH, w + 1): if current_entry.entrytype == 'udp' or (current_entry in defaulttexts and textqueue): return False leftpad = np.zeros((DISPLAY_HEIGHT, max(-i, 0), 4), dtype=np.uint8) framedata = fb[:, max(0, i):min(i + DISPLAY_WIDTH, w)] rightpad = np.zeros( (DISPLAY_HEIGHT, min(DISPLAY_WIDTH, max( 0, i + DISPLAY_WIDTH - w)), 4), dtype=np.uint8) dice = np.concatenate((leftpad, framedata, rightpad), 1) sendframe(dice) printframe(dice) fb = render_text(text) return True
def handle(self): try: # Housekeeping - FIXME: This is *so* the wrong place for this. for k, v in conns.items(): if time() - v.timestamp > UDP_TIMEOUT: del conns[k] global current_entry, conns data = self.request[0].strip() if len(data) != FRAME_SIZE * 3 + 4: #raise ValueError('Invalid frame size: Expected {}, got {}'.format(FRAME_SIZE+4, len(data))) return frame = data[:-4] #crc1, = struct.unpack('!I', data[-4:]) #crc2, = zlib.crc32(frame, 0), #if crc1 != crc2: # raise ValueError('Invalid frame CRC checksum: Expected {}, got {}'.format(crc2, crc1)) #socket.sendto(b'ACK', self.client_address) a = np.array(list(frame), dtype=np.uint8) timestamp = time() addr = self.client_address[0] conn = QueueEntry('udp', addr, timestamp, '') if addr not in conns: log('New UDP connection from', addr) current_entry = conn conns[addr] = current_entry if current_entry.entrytype == 'udp' and current_entry.remote == addr: current_entry = conn frame = a.reshape((DISPLAY_HEIGHT, DISPLAY_WIDTH, 3)) sendframe(frame) printframe( np.pad(frame, ((0, 0), (0, 0), (0, 1)), 'constant', constant_values=(0, 0))) except Exception as e: log('Error receiving UDP frame:', e)
#!/usr/bin/env python from socketserver import * import socket import struct import zlib from time import time, strftime, sleep from collections import namedtuple, deque import itertools import threading import random import os from ctypes import * from matelight import sendframe, DISPLAY_WIDTH, DISPLAY_HEIGHT, FRAME_SIZE if __name__ == '__main__': sendframe(bytes([0, 0, 0] * FRAME_SIZE))
defaultlines = [ TextRenderer(l[:-1].replace('\\x1B', '\x1B')) for l in open('default.lines').readlines() ] random.shuffle(defaultlines) defaulttexts = itertools.cycle(itertools.chain(*defaultlines)) if __name__ == '__main__': #print('\033[?1049h'+'\n'*9) while True: if renderqueue: renderer = renderqueue.popleft() elif userver.frame_da(): renderer = userver else: static_noise = time() % 300 < 60 if static_noise: foo = os.urandom(640) frame = bytes([ v for c in zip(list(foo), list(foo), list(foo)) for v in c ]) else: frame = next(defaulttexts) sendframe(frame) #printframe(next(defaulttexts)) continue for frame in renderer: sendframe(frame) #printframe(frame)
#!/usr/bin/env python from socketserver import * import socket import struct import zlib from time import time, strftime, sleep from collections import namedtuple, deque import itertools import threading import random import os from ctypes import * from matelight import sendframe, DISPLAY_WIDTH, DISPLAY_HEIGHT, FRAME_SIZE if __name__ == '__main__': sendframe(bytes([0, 0, 0]*FRAME_SIZE))
if __name__ == '__main__': print('\033[?1049h'+'\n'*9) while True: if renderqueue: renderer = renderqueue.popleft() elif userver.frame_da(): renderer = userver else: static_noise = time() % 300 < 60 if False: foo = os.urandom(640) frame = bytes([v for c in zip(list(foo), list(foo), list(foo)) for v in c ]) sleep(0.05) else: try: frame = next(defaulttexts) except StopIteration: defaultlines = [ TextRenderer(l[:-1].replace('\\x1B', '\x1B')) for l in open('default.lines').readlines() ] #random.shuffle(defaultlines) defaulttexts = itertools.chain(*defaultlines) sendframe(frame) # printframe(frame) continue # sleep(0.1) for frame in renderer: sendframe(frame) # printframe(frame) # sleep(0.1)