shithub: oledsaver

Download patch

ref: d4fa0493e43ad94c1f419d162e0d1ab224a33cf5
author: glenda <glenda@narshaddaa>
date: Wed Apr 26 10:15:57 EDT 2023

base from oledimations

--- /dev/null
+++ b/main.c
@@ -1,0 +1,115 @@
+#include <u.h>
+#include <libc.h>
+#include <draw.h>
+#include "memdraw.h"
+
+#define NPIXELS 4032
+
+void
+usage(void)
+{
+	sysfatal("usage: %s [ -f subfont ] text", argv0);
+}
+
+void
+writeuncompressed(int fd, Memimage *m)
+{
+	char chanstr[32];
+	int bpl, y, j;
+	uchar *buf;
+
+	if(chantostr(chanstr, m->chan) == nil)
+		sysfatal("can't convert channel descriptor: %r");
+	fprint(fd, "%11s %11d %11d %11d %11d ",
+		chanstr, m->r.min.x, m->r.min.y, m->r.max.x, m->r.max.y);
+
+	bpl = bytesperline(m->r, m->depth);
+	buf = malloc(bpl);
+	if(buf == nil)
+		sysfatal("malloc failed: %r");
+	for(y=m->r.min.y; y<m->r.max.y; y++){
+		j = unloadmemimage(m, Rect(m->r.min.x, y, m->r.max.x, y+1), buf, bpl);
+		if(j != bpl)
+			sysfatal("image unload failed → %r");
+		//if(write(fd, buf, bpl) != bpl)
+		if(write(fd, buf, bpl) != bpl)
+			sysfatal("wu write failed → %r");
+	}
+	free(buf);
+}
+
+
+void
+main(int argc, char **argv)
+{
+	Memimage *img;
+	# 126 x 32 oled ⇒ 4032 pixels
+	int h,w,i;
+	h = 32;
+	w = 126;
+	long ms;
+	ms = 1000;
+	Point topleft;
+	double angle;
+	//angle = 0.0;
+	Rectangle pixel;
+	pixel.min.x = -1;
+	pixel.min.y = 1;
+	pixel.max.y = 2;
+	pixel.max.x = 2;
+	char *path;
+	path = "/mnt/reform/kbdoled";
+
+	Rectangle r;
+	int fd;
+
+	ARGBEGIN{
+	default:
+		usage();
+	}ARGEND;
+	
+	if (memimageinit())
+		sysfatal("memimageinit failed: %r");
+
+	for(;;){
+		r.min.x = 0;
+		r.min.y = 0;
+		r.max.x = 1;
+		r.max.y = 1;
+		angle = truerand();
+
+		fd = open(path, OWRITE);
+		if(fd < 0){
+			sysfatal("could not open kbdoled file → %r");
+		}
+
+		img = allocmemimage(Rect(0, 0, w, h), GREY1);
+		if (!img)
+			sysfatal("cannot allocate memimage: %r");
+		memfillcolor(img, DBlack);
+		topleft.y = 0;
+		topleft.x = 0;
+		for(i=0;i<w;i+=3){
+
+			r.min.x = abs(i%w);
+			r.min.y = abs(((int)(50.0*sin(angle*PI/180)))%h);
+			r.max.x = r.min.x+1;
+			r.max.y = r.min.y+1;
+			//fprint(2, "(x=%d,y=%d) to (x=%d,y=%d)\n", r.min.x, r.min.y, r.max.x, r.max.y);
+
+			memimagedraw(img, r, memwhite, ZP, nil, ZP, SoverD);
+			
+		
+			angle+=5;
+		}
+
+		writeuncompressed(fd, img);
+		freememimage(img);
+		fd = close(fd);
+		if(fd < 0)
+			sysfatal("close failed → %r");
+		
+		sleep(ms);
+	}
+	
+}
\ No newline at end of file
--- /dev/null
+++ b/mkfile
@@ -1,0 +1,6 @@
+</$objtype/mkfile
+
+TARG=oledimations
+OFILES=main.$O
+
+</sys/src/cmd/mkone