shithub: riscv

Download patch

ref: 95206ac7e54cbc7a0c913c0ab73b509896ff27a5
parent: 0986cc7a9275c06ea337d04edf2092d0f3657a0d
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Sat Aug 20 09:39:49 EDT 2022

aux/imx8pm: add relative brightness setting (-+N), useful for key bindings

--- a/sys/man/8/imx8pm
+++ b/sys/man/8/imx8pm
@@ -14,6 +14,11 @@
 .B -s
 .I service
 ]
+.nf
+.sp 0.3v
+.B /mnt/pm/cputemp
+.B /mnt/pm/ctl
+.fi
 .SH DESCRIPTION
 .I Aux/imx8pm
 presents at
@@ -26,13 +31,22 @@
 .BI /srv/ service 
 as well.
 .PP
-The directory contains the following files.
-.TP
 .B cputemp
 Exposes the current temperature reading of the CPU.
-.TP
+.PP
 .B ctl
-Provides a way to control the brightness of the built-in LCD.
+Provides a way to control the brightness of the built-in LCD by
+writing
+.IP
+.I brightness [-+]N
+.PP
+.B N
+is expressed in percentage, either as an absolute value (0-100) or
+relative to the current brightness - by prefixing with a sign.
+.PP
+Reading
+.B ctl
+returns the current brightness.
 .SH SOURCE
 .B /sys/src/cmd/aux/imx8pm.c
 .SH SEE ALSO
--- a/sys/src/cmd/aux/imx8pm.c
+++ b/sys/src/cmd/aux/imx8pm.c
@@ -174,7 +174,7 @@
 fswrite(Req *r)
 {
 	char msg[256], *f[4];
-	int nf;
+	int nf, v;
 
 	if(r->fid->file->aux == (void*)Ctl){
 		snprint(msg, sizeof(msg), "%.*s",
@@ -184,8 +184,12 @@
 			respond(r, "invalid ctl message");
 			return;
 		}
-		if(strcmp(f[0], "brightness") == 0)
-			setbrightness(atoi(f[1]));
+		if(strcmp(f[0], "brightness") == 0){
+			v = atoi(f[1]);
+			if(*f[1] == '+' || *f[1] == '-')
+				v += getbrightness();
+			setbrightness(v);
+		}
 	}
 
 	r->ofcall.count = r->ifcall.count;