diff options
author | jaseg <jaseg@jaseg.net> | 2014-02-17 01:53:08 +0100 |
---|---|---|
committer | jaseg <jaseg@jaseg.net> | 2014-02-17 01:53:08 +0100 |
commit | ec0233f756bd25232f1a5d5c88a758e6efed9c5a (patch) | |
tree | 4d8cdf337e5fe877105f2bdaacb290bb2daa1665 | |
parent | 18fd12e916c8a33007a8ccd305d280493e8cd27d (diff) | |
download | matelight-ec0233f756bd25232f1a5d5c88a758e6efed9c5a.tar.gz matelight-ec0233f756bd25232f1a5d5c88a758e6efed9c5a.tar.bz2 matelight-ec0233f756bd25232f1a5d5c88a758e6efed9c5a.zip |
Niiiice glitch art...
-rw-r--r-- | firmware/main.c | 12 | ||||
-rw-r--r-- | host/main.c | 7 | ||||
-rw-r--r-- | host/main.h | 2 | ||||
-rw-r--r-- | host/matelight.py | 31 | ||||
-rwxr-xr-x | host/server.py | 27 |
5 files changed, 35 insertions, 44 deletions
diff --git a/firmware/main.c b/firmware/main.c index 945e0af..52b6360 100644 --- a/firmware/main.c +++ b/firmware/main.c @@ -54,10 +54,10 @@ unsigned const char const FUCKED_UP_BOTTLE_MAP[CRATE_SIZE] = { }; unsigned const char const CRATE_MAP[CRATE_COUNT] = { - 0x37, 0x35, 0x33, 0x31, 0x21, 0x23, 0x25, 0x27, - 0x36, 0x34, 0x32, 0x30, 0x20, 0x22, 0x24, 0x26, - 0x16, 0x14, 0x12, 0x10, 0x00, 0x02, 0x04, 0x06, - 0x17, 0x15, 0x13, 0x11, 0x01, 0x03, 0x05, 0x07 + 0x07, 0x05, 0x03, 0x01, 0x10, 0x12, 0x14, 0x16, + 0x06, 0x04, 0x02, 0x00, 0x11, 0x13, 0x15, 0x17, + 0x26, 0x24, 0x22, 0x20, 0x31, 0x33, 0x35, 0x37, + 0x27, 0x25, 0x23, 0x21, 0x30, 0x32, 0x34, 0x36 }; #define SYSTICKS_PER_SECOND 100 @@ -149,8 +149,8 @@ unsigned long framebuffer_read(void *data, unsigned long len) { for(unsigned int x=0; x<CRATE_WIDTH; x++){ for(unsigned int y=0; y<CRATE_HEIGHT; y++){ unsigned int bottle = BOTTLE_MAP[x + y*CRATE_WIDTH]; - if(idx == 0x07) - bottle = FUCKED_UP_BOTTLE_MAP[x + y*CRATE_WIDTH]; +// if(idx == 0x07) +// bottle = FUCKED_UP_BOTTLE_MAP[x + y*CRATE_WIDTH]; unsigned int dst = bus*BUS_SIZE + (crate*CRATE_SIZE + bottle)*3; unsigned int src = (y*CRATE_WIDTH + x)*3; // Copy r, g and b data diff --git a/host/main.c b/host/main.c index fbe126a..9648a26 100644 --- a/host/main.c +++ b/host/main.c @@ -20,7 +20,6 @@ void free_framebuffer(framebuffer_t *fb){ - printf("Freeing %lx and %lx\n", fb->data, fb); free(fb->data); free(fb); } @@ -303,20 +302,16 @@ framebuffer_t *framebuffer_render_text(char *s, glyphtable_t *glyph_table){ fb->w = gbufwidth; fb->h = gbufheight; fb->data = gbuf; - printf("Returning buffer with w %ld h %ld memory location %lx\n", gbufwidth, gbufheight, gbuf); return fb; error: free(gbuf); return 0; } -void console_render_buffer(framebuffer_t *fb){ +void console_render_buffer(color_t *data, size_t w, size_t h){ /* Render framebuffer to terminal, two pixels per character using Unicode box drawing stuff */ color_t lastfg = {0, 0, 0}, lastbg = {0, 0, 0}; printf("\e[38;5;0;48;5;0m"); - color_t *data = fb->data; - size_t w = fb->w; - size_t h = fb->h; for(size_t y=0; y < h; y+=2){ for(size_t x=0; x < w; x++){ /* Da magicks: ▀█▄ */ diff --git a/host/main.h b/host/main.h index cf1dba7..5ace45e 100644 --- a/host/main.h +++ b/host/main.h @@ -5,6 +5,6 @@ #include "font.h" framebuffer_t *framebuffer_render_text(char *s, glyphtable_t *glyph_table); -void console_render_buffer(framebuffer_t *fb); +void console_render_buffer(color_t *data, size_t w, size_t h); #endif//__MAIN_H__ diff --git a/host/matelight.py b/host/matelight.py index 55295f6..3059230 100644 --- a/host/matelight.py +++ b/host/matelight.py @@ -14,22 +14,35 @@ FRAME_SIZE = CRATE_WIDTH*CRATE_HEIGHT*3 dev = usb.core.find(idVendor=0x1cbe, idProduct=0x0003) -def sendframe(framedata): +def sendframe(framedata, index): """ 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() for cx, cy in product(range(CRATES_X), range(CRATES_Y)): - 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 = [0,0,0]*CRATE_WIDTH*CRATE_HEIGHT -# for x, y in product(range(CRATE_WIDTH), range(CRATE_HEIGHT)): -# r, g, b, _ = framedata[cy*CRATE_HEIGHT + y][cx*CRATE_WIDTH + x] -# 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(r, g, b) + 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 if len(data) != FRAME_SIZE: raise ValueError('Invalid frame data. Expected {} bytes, got {}.'.format(FRAME_SIZE, len(data))) # Send framebuffer data diff --git a/host/server.py b/host/server.py index 70afdf9..2f751c2 100755 --- a/host/server.py +++ b/host/server.py @@ -22,38 +22,21 @@ def render_text(text): assert unifont fb = bdf.framebuffer_render_text(bytes(str(text), 'UTF-8'), unifont) fbd = fb.contents - print('FB STRUCT: w {} h {} memory location {:x}'.format(fbd.w, fbd.h, addressof(fbd.data.contents))) - print("TYPE:", type(fbd.data)) - casted = cast(fbd.data, POINTER(c_uint8)) - print("CASTED TYPE:" , type(casted)) buf = np.ctypeslib.as_array(cast(fbd.data, POINTER(c_uint8)), shape=(fbd.h, fbd.w, 4)) - print('RAW DATA:') - alen = fbd.h*fbd.w -# for i in range(alen): -# c = fbd.data[i] -# print('{:x}'.format(addressof(c)), c.r, c.g, c.b) - print('BUF', buf.shape, buf.dtype) -# for x, y, z in product(range(fbd.h), range(fbd.w), range(4)): -# print(buf[x][y][z]) - # 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) fbd.data = cast(c_void_p(), POINTER(COLOR)) bdf.free_framebuffer(fb) - print('Rendered {} chars into a buffer of w {} h {} numpy buf {}'.format(len(text), fbd.w, fbd.h, buf.shape)) return buf +def printframe(fb): + h,w,_ = fb.shape + bdf.console_render_buffer(fb.ctypes.data_as(ctypes.POINTER(ctypes.c_uint8)), w, h) + if __name__ == '__main__': fb = render_text('foobarbaz'); - print('buffer shape {} dtype {}'.format(fb.shape, fb.dtype)) -# import colorsys -# h, w, _ = fb.shape -# for x, y in product(range(w), range(h)): -# r,g,b = colorsys.hsv_to_rgb(x*0.03+y*0.05, 1, 1) -# fb[x][y] = (r,g,b,0) -# print(fb) sendframe(fb) - #printframe(fb) +# printframe(fb) |