Subject: bin/6811: add -m option to apm(8) to display battery estimate in minutes
To: None <gnats-bugs@gnats.netbsd.org>
From: None <dbj@netbsd.org>
List: netbsd-bugs
Date: 01/14/1999 17:54:16
>Number:         6811
>Category:       bin
>Synopsis:       add -m option to apm(8) to display battery estimate in minutes
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    bin-bug-people (Utility Bug People)
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Thu Jan 14 15:35:01 1999
>Last-Modified:
>Originator:     Darrin B. Jewell
>Organization:
	
>Release:        -current, last updated ~1999-01-14 22:48 UTC
>Environment:
	
System: NetBSD pan-fried-peking-ravioli 1.3I NetBSD 1.3I (PAN-FRIED-PEKING-RAVIOLI) #3: Mon Dec 14 17:08:34 EST 1998 root@:/u1/snap/usr/src/sys/arch/i386/compile/PAN-FRIED-PEKING-RAVIOLI i386


>Description:
	The BIOS can provide estimated battery lifetime in minutes,
        but this is not reported by the apm user program.
>How-To-Repeat:
        Enable apm(4) in the kernel, start apmd(8) and use apm(8) to
        retrieve a battery lifetime estimate.  It is provide in %, but
        not minutes.
>Fix:
        This patch adds the -m option to apm, which retrievs the BIOS'
estimate of the battery lifetime in minutes.  It also adds this
information to the verbose output format and documents the new option
in the man page.

Index: src/usr.sbin/apm/apm.8
===================================================================
RCS file: /cvsroot/src/usr.sbin/apm/apm.8,v
retrieving revision 1.8
diff -u -r1.8 apm.8
--- apm.8	1997/11/11 10:07:55	1.8
+++ apm.8	1999/01/14 22:46:59
@@ -74,7 +74,9 @@
 .It Fl S
 Put the system into stand-by (light sleep) mode.
 .It Fl l
-Display the estimated battery lifetime (in percent).
+Display the estimated battery lifetime in percent.
+.It Fl m
+Display the estimated battery lifetime in minutes.
 .It Fl b
 Display the battery status.  0 means high, 1 means low, 2 means
 critical, 3 means charging, 4 means absent, and 255 means unknown.
Index: src/usr.sbin/apm/apm.c
===================================================================
RCS file: /cvsroot/src/usr.sbin/apm/apm.c,v
retrieving revision 1.7
diff -u -r1.7 apm.c
--- apm.c	1998/11/13 22:44:17	1.7
+++ apm.c	1999/01/14 22:46:59
@@ -70,7 +70,7 @@
 void
 usage(void)
 {
-    fprintf(stderr,"usage: %s [-v] [-z | -S] [-slba] [-f socket]\n",
+    fprintf(stderr,"usage: %s [-v] [-z | -S] [-slmba] [-f socket]\n",
 	    __progname);
     exit(1);
 }
@@ -159,6 +159,7 @@
     int dostatus = FALSE;
     int doac = FALSE;
     int dopct = FALSE;
+    int domin = FALSE;
     int dobstate = FALSE;
     int nodaemon = FALSE;
     int fd;
@@ -168,7 +169,7 @@
     struct apm_command command;
     struct apm_reply reply;
 
-    while ((ch = getopt(argc, argv, "lbvadsSzf:d")) != -1)
+    while ((ch = getopt(argc, argv, "lmbvadsSzf:d")) != -1)
 	switch(ch) {
 	case 'v':
 	    verbose = TRUE;
@@ -204,6 +205,12 @@
 	    dopct = TRUE;
 	    action = GETSTATUS;
 	    break;
+	case 'm':
+	    if (action != NONE && action != GETSTATUS)
+		usage();
+	    domin = TRUE;
+	    action = GETSTATUS;
+	    break;
 	case 'a':
 	    if (action != NONE && action != GETSTATUS)
 		usage();
@@ -229,7 +236,7 @@
 
     switch (action) {
     case NONE:
-	verbose = doac = dopct = dobstate = dostatus = TRUE;
+	verbose = doac = dopct = domin = dobstate = dostatus = TRUE;
 	action = GETSTATUS;
 	/* fallthrough */
     case GETSTATUS:
@@ -275,9 +282,18 @@
 		if (dobstate)
 		    printf("Battery charge state: %s\n",
 			   battstate(reply.batterystate.battery_state));
-		if (dopct)
-		    printf("Battery remaining: %d percent\n",
-			   reply.batterystate.battery_life);
+		if (dopct || domin) {
+		    printf("Battery remaining: ");
+		    if (dopct)
+			printf("%d percent",reply.batterystate.battery_life);
+		    if (dopct && domin)
+			printf(" (");
+		    if (domin)
+			printf("%d minutes",reply.batterystate.minutes_left);
+		    if (dopct && domin)
+			printf(")");
+		    printf("\n");
+		}
 		if (doac)
 		    printf("A/C adapter state: %s\n", ac_state(reply.batterystate.ac_state));
 		if (dostatus)
@@ -287,6 +303,8 @@
 		    printf("%d\n", reply.batterystate.battery_state);
 		if (dopct)
 		    printf("%d\n", reply.batterystate.battery_life);
+		if (domin)
+		    printf("%d\n", reply.batterystate.minutes_left);
 		if (doac)
 		    printf("%d\n", reply.batterystate.ac_state);
 		if (dostatus)
>Audit-Trail:
>Unformatted: