shithub: olednews

Download patch

ref: afaf736459044632e33771effd9d8fc2d55689f3
parent: f1a004c3925df32274aa9947e6e899ff5ca79c35
author: glenda <glenda@narshaddaa>
date: Mon Apr 24 00:20:12 EDT 2023

working dirty scrolling

--- a/textimg.c
+++ b/textimg.c
@@ -2,6 +2,7 @@
 #include <libc.h>
 #include <draw.h>
 #include <memdraw.h>
+#include <bio.h>
 
 void
 usage(void)
@@ -10,6 +11,33 @@
 }
 
 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)
+			sysfatal("write failed: %r");
+	}
+	free(buf);
+}
+
+
+void
 main(int argc, char **argv)
 {
 	char *s;
@@ -16,18 +44,24 @@
 	Memsubfont *f;
 	Point p;
 	Memimage *img;
-	
-	s = "/lib/font/bit/lucida/latin1B.32.1";
+	char *path;
+	int fd;
+	Biobufhdr *in;
+
+	s = "/lib/font/bit/vga/vga.0000-007F";
 	f = nil;
+	path = "/mnt/reform/kbdoled";
+	in = Bfdopen(0, OREAD);
+
 	ARGBEGIN{
 	case 'f':
 		s = EARGF(usage());
 		break;
+	case 'p':
+		path = EARGF(usage());
+		break;
 	}ARGEND;
-	
-	if (argc < 1)
-		sysfatal("no text argument");
-	
+
 	if (memimageinit())
 		sysfatal("memimageinit failed: %r");
 	
@@ -37,17 +71,56 @@
 		fprint(2, "cannot load subfont. Falling back to default.\n");
 		f = getmemdefont();
 	}
-	
-	p = memsubfontwidth(f, argv[0]);
-	
+
+	// Read text in - one OLED line width at a time
+	//	2 lines on the OLED display
+	// p.x = width of one char in pixels
+	// 126 x 32 oled
+	p = memsubfontwidth(f, "Q");
 	if (p.x == 0)
 		sysfatal("no length");
+
+	int ncharspline, nlines;
+	int h = 32;
+	int w = 126;
+	int y = 0;
+	int ms = 500;
+	long n;
+	ncharspline = w / p.x;
+	nlines = 2;	// i guess?
+	char *buf;
+	fprint(2, "ncharspline: %d\n", ncharspline);
+
+	for(;;){
+		buf = calloc(ncharspline, sizeof (char));
+		n = Bread(in, buf, ncharspline-1);
+		if(n <= 0)
+			break;
+		buf[n] = '\0';
+
+		fprint(2, "buf str: %s\n", buf);
+
+		fd = open(path, OWRITE);
+		if(fd < 0){
+			sysfatal("could not open kbdoled file → %r");
+		}
+		
+		//img = allocmemimage(Rect(0, 0, p.x, f->height), RGB24);
+		img = allocmemimage(Rect(0, 0, p.x*ncharspline, f->height), RGB24);
+		if (!img)
+			sysfatal("cannot allocate memimage: %r");
+		memfillcolor(img, DWhite);
+		
+		memimagestring(img, Pt(0, 0), memblack, ZP, f, buf);
+		writeuncompressed(fd, img);
 	
-	img = allocmemimage(Rect(0, 0, p.x, f->height), RGB24);
-	if (!img)
-		sysfatal("cannot allocate memimage: %r");
-	memfillcolor(img, DWhite);
-	
-	memimagestring(img, Pt(0, 0), memblack, ZP, f, argv[0]);
-	writememimage(1, img);
+		close(fd);
+		free(buf);
+		if(y == 0)
+			y = h/2;
+		else
+			y = 0;
+
+		sleep(ms);
+	}
 }