2 * acpi-ng: command line acpi battery status tool.
4 * Written by Simon Fowler <simon@dreamcraft.com.au>, 2003-06-20.
5 * Copyright 2003-06-20 Dreamcraft Pty Ltd.
7 * This file is distributed under the GNU General Public License,
8 * version 2. Please see the COPYING file for details.
13 * I'm getting sick of not having a convenient way to query battery
14 * status on the command line, so I'm hacking up this - a quick little
15 * command line tool to display current battery status, using the same
16 * libacpi code as wmacpi-ng.
29 #define ACPI_VER "1.99"
33 void usage(char *name
)
35 printf("%s: query battery status on ACPI enabled systems.\n"
37 "%s [-h] [-a samples]\n"
38 " h - display this help information\n"
39 " a - average remaining time over some number of samples\n"
40 " much more accurate than using a single sample\n"
41 " v - increase verbosity\n",
45 void print_version(void)
47 printf("acpi version %s\n", ACPI_VER
);
48 printf(" Using libacpi version %s\n", LIBACPI_VER
);
51 int main(int argc
, char *argv
[])
59 while((ch
= getopt(argc
, argv
, "hvVa:")) != EOF
) {
72 samples
= atoi(optarg
);
73 if(samples
> 1000 || samples
<= 0) {
74 fprintf(stderr
, "Please specify a reasonable number of samples\n");
78 pinfo("samples: %d\n", samples
);
79 sleep_time
= 1000000/samples
;
87 globals
= (global_t
*) malloc(sizeof(global_t
));
90 /* we want to acquire samples over some period of time, so . . . */
91 for(i
= 0; i
< samples
+ 2; i
++) {
92 for(j
= 0; j
< batt_count
; j
++)
94 acquire_global_info();
98 ap
= &globals
->adapter
;
100 printf("On AC Power");
101 for(i
= 0; i
< batt_count
; i
++) {
102 binfo
= &batteries
[i
];
103 if(binfo
->present
&& (binfo
->charge_state
== CHARGE
)) {
104 printf("; Battery %s charging", binfo
->name
);
105 printf(", currently at %2d%%", binfo
->percentage
);
106 if(binfo
->charge_time
>= 0)
107 printf(", %2d:%02d remaining",
108 binfo
->charge_time
/60,
109 binfo
->charge_time
%60);
113 } else if(ap
->power
== BATT
) {
114 printf("On Battery");
115 for(i
= 0; i
< batt_count
; i
++) {
116 binfo
= &batteries
[i
];
117 if(binfo
->present
&& (binfo
->percentage
>= 0))
118 printf(", Battery %s at %d%%", binfo
->name
,
121 if(globals
->rtime
>= 0)
122 printf("; %d:%02d remaining", globals
->rtime
/60,