shithub: jacksense

Download patch

ref: 4ec0a1a2712acc48ba2f52dfa760aa25bcb07c85
parent: d462b97a6a22c8de1f8aa9f4c143ae30f2961e9a
author: Sigrid Solveig Haflínudóttir <[email protected]>
date: Wed Mar 3 04:16:47 EST 2021

add debugging, error traces; increase volume switch delay a bit

--- a/jacksense.c
+++ b/jacksense.c
@@ -13,14 +13,18 @@
 main(int argc, char **argv)
 {
 	int hp, sp, cmd, ctl, vol, lastvol, newvol;
-	int hpsafevol, spsafevol;
+	int debug, hpsafevol, spsafevol;
 	u32int x, y[4], has, had, c;
-	Biobuf *b;
 	char *s, *a[16], tmp[32];
+	Biobuf *b;
 
+	debug = 0;
 	hpsafevol = 65;
 	spsafevol = 70;
 	ARGBEGIN{
+	case 'd':
+		debug++;
+		break;
 	case 'h':
 		hpsafevol = atoi(EARGF(usage()));
 		break;
@@ -47,10 +51,14 @@
 			continue;
 		if(strcmp(a[0], "pin") != 0 || strcmp(a[2], "out") != 0)
 			continue;
-		if(strcmp(a[3], "jack") == 0 && strcmp(a[6], "hpout") == 0)
+		if(strcmp(a[3], "jack") == 0 && strcmp(a[6], "hpout") == 0){
 			hp = atoi(a[1]);
-		if(strcmp(a[3], "fix") == 0 && strcmp(a[6], "speaker") == 0)
+			if(debug) fprint(2, "hpout pin %d\n", hp);
+		}
+		if(strcmp(a[3], "fix") == 0 && strcmp(a[6], "speaker") == 0){
 			sp = atoi(a[1]);
+			if(debug) fprint(2, "speaker pin %d\n", sp);
+		}
 	}
 	Bterm(b);
 	if(sp < 0 || hp < 0){
@@ -65,7 +73,7 @@
 		c = 0;
 again:
 		if(write(cmd, &x, 4) != 4 || read(cmd, y, sizeof(y)) < 4)
-			sysfatal("failed");
+			sysfatal("command failed: %r");
 		has = y[0] & (1<<31);
 		if(has != had){
 			if(c++ < 2){
@@ -84,10 +92,13 @@
 			else if(!has && newvol > spsafevol)
 				newvol = spsafevol;
 
-			fprint(ctl, "pin %d\n", has ? hp : sp);
-			fprint(vol, "0\n");
-			sleep(50);
-			fprint(vol, "%d\n", newvol);
+			if(fprint(ctl, "pin %d", has ? hp : sp) < 0)
+				fprint(2, "vol: %r\n");
+			if(fprint(vol, "master 0 0") < 0)
+				fprint(2, "vol: %r\n");
+			sleep(100);
+			if(fprint(vol, "master %d %d", newvol, newvol) < 0)
+				fprint(2, "vol: %r\n");
 		}
 		had = has;
 		sleep(300);