Marquee is working now
This commit is contained in:
parent
ec0233f756
commit
6578445931
2 changed files with 19 additions and 30 deletions
|
|
@ -14,35 +14,17 @@ FRAME_SIZE = CRATE_WIDTH*CRATE_HEIGHT*3
|
|||
|
||||
dev = usb.core.find(idVendor=0x1cbe, idProduct=0x0003)
|
||||
|
||||
def sendframe(framedata, index):
|
||||
def sendframe(framedata):
|
||||
""" Send a frame to the display
|
||||
|
||||
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.
|
||||
"""
|
||||
for y in range(DISPLAY_HEIGHT):
|
||||
for x in range(DISPLAY_WIDTH):
|
||||
r, g, b, _ = framedata[y][x]
|
||||
print('#' if r > 10 else ' ', end='')
|
||||
print()
|
||||
# Gamma correction
|
||||
framedata = (((framedata/255) ** 2.5) * 255).astype(np.uint8)
|
||||
for cx, cy in product(range(CRATES_X), range(CRATES_Y)):
|
||||
data = [0,0,0]*CRATE_WIDTH*CRATE_HEIGHT
|
||||
print('CRATE X {} Y {}'.format(cx, cy))
|
||||
for y in range(CRATE_HEIGHT):
|
||||
for x in range(CRATE_WIDTH):
|
||||
r, g, b, _ = framedata[cy*CRATE_HEIGHT + y][cx*CRATE_WIDTH + x]
|
||||
# import colorsys
|
||||
# r,g,b = colorsys.hsv_to_rgb(cx*0.1+cy*0.2, 1, 1)
|
||||
# r,g,b = int(r*255), int(g*255), int(b*255)
|
||||
#r,g,b = (255,0,255) if cy*CRATES_X+cx == index else (0,0,0)
|
||||
#print('#' if r > 10 else ' ', end='')
|
||||
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()
|
||||
#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 = [ 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) ]
|
||||
data = framedata[cy*CRATE_HEIGHT:(cy+1)*CRATE_HEIGHT, cx*CRATE_WIDTH:(cx+1)*CRATE_WIDTH, :3].flat
|
||||
datar = framedata[cy*CRATE_HEIGHT:(cy+1)*CRATE_HEIGHT, cx*CRATE_WIDTH:(cx+1)*CRATE_WIDTH, :3]
|
||||
data = datar.flat
|
||||
if len(data) != FRAME_SIZE:
|
||||
raise ValueError('Invalid frame data. Expected {} bytes, got {}.'.format(FRAME_SIZE, len(data)))
|
||||
# Send framebuffer data
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
from ctypes import CDLL, POINTER, c_void_p, Structure, c_uint8, c_size_t, cast, addressof
|
||||
import numpy as np
|
||||
from itertools import product
|
||||
from matelight import sendframe
|
||||
from matelight import sendframe, DISPLAY_WIDTH, DISPLAY_HEIGHT
|
||||
from terminal import printframe
|
||||
|
||||
class COLOR(Structure):
|
||||
|
|
@ -25,18 +25,25 @@ def render_text(text):
|
|||
buf = np.ctypeslib.as_array(cast(fbd.data, POINTER(c_uint8)), shape=(fbd.h, fbd.w, 4))
|
||||
# Set data pointer to NULL before freeing framebuffer struct to prevent free_framebuffer from also freeing the data
|
||||
# buffer that is now used by numpy
|
||||
bdf.console_render_buffer(fb)
|
||||
#bdf.console_render_buffer(fb)
|
||||
fbd.data = cast(c_void_p(), POINTER(COLOR))
|
||||
bdf.free_framebuffer(fb)
|
||||
return buf
|
||||
|
||||
def printframe(fb):
|
||||
h,w,_ = fb.shape
|
||||
bdf.console_render_buffer(fb.ctypes.data_as(ctypes.POINTER(ctypes.c_uint8)), w, h)
|
||||
print('\033[H\033[2J')
|
||||
bdf.console_render_buffer(fb.ctypes.data_as(POINTER(c_uint8)), w, h)
|
||||
|
||||
if __name__ == '__main__':
|
||||
fb = render_text('foobarbaz');
|
||||
sendframe(fb)
|
||||
# printframe(fb)
|
||||
|
||||
fb = render_text('\033[31;48;5;167;4;6mfoo\033[0;91mbar\033[93;106;5mbaz\033[0m\033[0;94;6m♥♥♥');
|
||||
h,w,_ = fb.shape
|
||||
for i in range(-DISPLAY_WIDTH,w+1):
|
||||
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('\033[31;48;5;167;4;6mfoo\033[0;91mbar\033[93;106;5mbaz\033[0m\033[0;94;6m♥♥♥');
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue