shithub: drawterm-fdroid

Download patch

ref: 35bd7fa731d33914761a4b9461967dbeb4f1aa24
parent: 0448efcbfb7854e210296721025380d287d4c3de
author: Eli Cohen <echoline@gmail.com>
date: Sun Jan 30 20:52:48 EST 2022

android #N device (cameras, accelerometer, etc...)

--- a/gui-android/cpp/devandroid.c
+++ b/gui-android/cpp/devandroid.c
@@ -24,10 +24,19 @@
 	Qcam		= 1,
 	Qaccel		= 2,
 	Qcompass	= 4,
-	Qnotification	= 6,
+	Qnotify		= 6,
 };
-#define QID(p, c, y) 	(((p)<<16) | ((c)<<4) | (y))
 
+Dirtab
+androiddir[] =
+{
+	".",		{Qdir, 0, QTDIR},	0,	DMDIR|0555,
+	"camNNNN.jpg",	{Qcam},			0,	0444,
+	"accel",	{Qaccel},		0,	0444,
+	"compass",	{Qcompass},		0,	0444,
+	"notify",	{Qnotify},		0,	0222,
+};
+
 static void androidinit(void);
 
 static void
@@ -41,14 +50,7 @@
 static Chan*
 androidattach(char *param)
 {
-	Chan *c;
-
-	c = devattach('N', param);
-	c->qid.path = QID(0, 0, Qdir);
-	c->qid.type = QTDIR;
-	c->qid.vers = 0;
-
-	return c;
+	return devattach('N', param);
 }
 
 static int
@@ -57,32 +59,33 @@
 	Qid q;
 
 	if (s == DEVDOTDOT) {
-		mkqid(&q, Qdir, 0, QTDIR);
-		devdir(c, q, "#N", 0, eve, 0555, dp);
+		devdir(c, d->qid, "#N", 0, eve, 0555, dp);
 		return 1;
 	}
 	if (s < Ncameras) {
+		d += 1;
+		q = d->qid;
+		q.path |= (s << 16);
 		sprintf(up->genbuf, "cam%d.jpg", s);
-		mkqid(&q, (s << 16) | Qcam, 0, QTFILE);
 		devdir(c, q, up->genbuf, 0, eve, 0444, dp);
 		return 1;
 	}
 	if (s == Ncameras) {
+		d += 2;
 		sprintf(up->genbuf, "accel");
-		mkqid(&q, Qaccel, 0, QTFILE);
-		devdir(c, q, up->genbuf, 0, eve, 0444, dp);
+		devdir(c, d->qid, up->genbuf, 0, eve, 0444, dp);
 		return 1;
 	}
 	if (s == (Ncameras+1)) {
+		d += 3;
 		sprintf(up->genbuf, "compass");
-		mkqid(&q, Qcompass, 0, QTFILE);
-		devdir(c, q, up->genbuf, 0, eve, 0444, dp);
+		devdir(c, d->qid, up->genbuf, 0, eve, 0444, dp);
 		return 1;
 	}
 	if (s == (Ncameras+2)) {
-		sprintf(up->genbuf, "notification");
-		mkqid(&q, Qnotification, 0, QTFILE);
-		devdir(c, q, up->genbuf, 0, eve, 0222, dp);
+		d += 4;
+		sprintf(up->genbuf, "notify");
+		devdir(c, d->qid, up->genbuf, 0, eve, 0222, dp);
 		return 1;
 	}
 	return -1;
@@ -91,13 +94,13 @@
 static Walkqid*
 androidwalk(Chan *c, Chan *nc, char **name, int nname)
 {
-	return devwalk(c, nc, name, nname, 0, 0, androidgen);
+	return devwalk(c, nc, name, nname, androiddir, nelem(androiddir) + Ncameras - 1, androidgen);
 }
 
 static int
 androidstat(Chan *c, uchar *db, int n)
 {
-	return devstat(c, db, n, 0, 0, androidgen);
+	return devstat(c, db, n, androiddir, nelem(androiddir) + Ncameras - 1, androidgen);
 }
 
 static Chan*
@@ -105,7 +108,7 @@
 {
 	p9_uvlong s;
 
-	c = devopen(c, omode, 0, 0, androidgen);
+	c = devopen(c, omode, androiddir, nelem(androiddir) + Ncameras - 1, androidgen);
 
 	if (c->qid.path & Qcam) {
 		s = c->qid.path >> 16;
@@ -114,7 +117,6 @@
 	c->mode = openmode(omode);
 	c->flag |= COPEN;
 	c->offset = 0;
-	c->iounit = 8192;
 
 	return c;
 }
@@ -201,7 +203,7 @@
 			ASensorManager_destroyEventQueue(sensorManager, queue);
 			return l;
 		case Qdir:
-			return devdirread(c, a, n, 0, 0, androidgen);
+			return devdirread(c, a, n, androiddir, nelem(androiddir) + Ncameras - 1, androidgen);
 	}
 }
 
@@ -212,7 +214,7 @@
 	char *str;
 
 	switch((ulong)c->qid.path) {
-		case Qnotification:
+		case Qnotify:
 			str = malloc(n+1);
 			memcpy(str, a, n);
 			str[n] = '\0';
--- a/kern/devtab.c
+++ b/kern/devtab.c
@@ -19,6 +19,9 @@
 extern Dev kbddevtab;
 extern Dev cmddevtab;
 extern Dev envdevtab;
+#ifdef __ANDROID__
+extern Dev androiddevtab;
+#endif
 
 Dev *devtab[] = {
 	&rootdevtab,
@@ -36,6 +39,9 @@
 	&kbddevtab,
 	&cmddevtab,
 	&envdevtab,
+#ifdef __ANDROID__
+	&androiddevtab,
+#endif
 	0
 };
 
--- a/main.c
+++ b/main.c
@@ -52,7 +52,9 @@
 	if(bind("#I", "/net", MBEFORE) < 0)
 		panic("bind #I: %r");
 	bind("#A", "/dev", MAFTER);
+#ifdef __ANDROID__
 	bind("#N", "/dev", MAFTER);
+#endif
 
 	if(open("/dev/cons", OREAD) != 0)
 		panic("open0: %r");