Output the estimated battery lifetime as "hh:mm:ss" along with

everything else.  Add a "-t" option for outputting it in raw form.
Define and document the order in which raw values are printed when
more than one is requested on the command line.
This commit is contained in:
John Polstra 1997-11-12 04:16:23 +00:00
parent 56fac9328e
commit ec8f6ad756
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=31127
2 changed files with 33 additions and 6 deletions

View File

@ -16,7 +16,7 @@
.Nd control the APM BIOS and display its information
.Sh SYNOPSIS
.Nm apm
.Op Fl ablsz
.Op Fl ablstz
.Op Fl d Ar 1|0
.Pp
.Nm zzz
@ -35,6 +35,8 @@ The following options are available for
If no options are specified,
.Nm apm
displays information and current status of APM in verbose mode.
If multiple display options are given, the values are displayed one
per line in the order given here.
.Bl -tag -width indent
.It Fl a
Display the current AC-line status as an integer value. The values
@ -71,6 +73,9 @@ Display the status of the APM support as an integer value. The values
state or
.Dq enabled
state respectively.
.It Fl t
Display the estimated remaining battery lifetime in seconds. If
it is unknown, -1 is displayed.
.It Fl z
Suspend the system. It is equivalent to
.Nm zzz.

View File

@ -15,7 +15,7 @@
#ifndef lint
static const char rcsid[] =
"$Id: apm.c,v 1.10 1997/09/02 06:36:39 charnier Exp $";
"$Id: apm.c,v 1.11 1997/11/06 23:55:38 imp Exp $";
#endif /* not lint */
#include <err.h>
@ -33,7 +33,7 @@ void
usage()
{
fprintf(stderr, "%s\n%s\n",
"usage: apm [-ablsz] [-d 1|0]",
"usage: apm [-ablstz] [-d 1|0]",
" zzz");
exit(1);
}
@ -85,6 +85,21 @@ print_all_info(apm_info_t aip)
else
printf("invalid value (0x%x)", aip->ai_batt_life);
printf("\n");
printf("Remaining battery time: ");
if (aip->ai_batt_time == -1)
printf("unknown");
else {
int t, h, m, s;
t = aip->ai_batt_time;
s = t % 60;
t /= 60;
m = t % 60;
t /= 60;
h = t;
printf("%2d:%02d:%02d", h, m, s);
}
printf("\n");
}
@ -106,6 +121,7 @@ main(int argc, char *argv[])
int c, fd;
int sleep = 0, all_info = 1, apm_status = 0, batt_status = 0;
int display = 0, batt_life = 0, ac_status = 0;
int batt_time = 0;
char *cmdname;
@ -119,7 +135,7 @@ main(int argc, char *argv[])
all_info = 0;
goto finish_option;
}
while ((c = getopt(argc, argv, "ablszd:")) != -1) {
while ((c = getopt(argc, argv, "ablstzd:")) != -1) {
switch (c) {
case 'a':
ac_status = 1;
@ -146,6 +162,10 @@ main(int argc, char *argv[])
apm_status = 1;
all_info = 0;
break;
case 't':
batt_time = 1;
all_info = 0;
break;
case 'z':
sleep = 1;
all_info = 0;
@ -171,14 +191,16 @@ main(int argc, char *argv[])
apm_getinfo(fd, &info);
if (all_info)
print_all_info(&info);
if (ac_status)
printf("%d\n", info.ai_acline);
if (batt_status)
printf("%d\n", info.ai_batt_stat);
if (batt_life)
printf("%d\n", info.ai_batt_life);
if (ac_status)
printf("%d\n", info.ai_acline);
if (apm_status)
printf("%d\n", info.ai_status);
if (batt_time)
printf("%d\n", info.ai_batt_time);
if (display)
apm_display(fd, display - 1);
}