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.
31 void usage(char *name
)
33 printf("%s: query battery status on ACPI enabled systems.\n"
35 "%s [-h] [-a samples]\n"
36 " h - display this help information\n"
37 " a - average remaining time over some number of samples\n"
38 " much more accurate than using a single sample\n"
39 " V - increase verbosity\n"
40 " v - print version information\n",
44 void print_version(void)
46 printf("wmacpi-cli version %s\n", WMACPI_VER
);
47 printf(" Using libacpi version %s\n", LIBACPI_VER
);
50 int main(int argc
, char *argv
[])
58 while((ch
= getopt(argc
, argv
, "hvVa:")) != EOF
) {
71 samples
= atoi(optarg
);
72 if(samples
> 1000 || samples
<= 0) {
73 fprintf(stderr
, "Please specify a reasonable number of samples\n");
77 pinfo("samples: %d\n", samples
);
78 sleep_time
= 1000000/samples
;
86 globals
= (global_t
*) malloc(sizeof(global_t
));
89 /* we want to acquire samples over some period of time, so . . . */
90 for(i
= 0; i
< samples
+ 2; i
++) {
91 for(j
= 0; j
< globals
->battery_count
; j
++)
92 acquire_batt_info(globals
, j
);
93 acquire_global_info(globals
);
97 ap
= &globals
->adapter
;
99 printf("On AC Power");
100 for(i
= 0; i
< globals
->battery_count
; i
++) {
101 binfo
= &batteries
[i
];
102 if(binfo
->present
&& (binfo
->charge_state
== CHARGE
)) {
103 printf("; Battery %s charging", binfo
->name
);
104 printf(", currently at %2d%%", binfo
->percentage
);
105 if(binfo
->charge_time
>= 0)
106 printf(", %2d:%02d remaining",
107 binfo
->charge_time
/60,
108 binfo
->charge_time
%60);
112 } else if(ap
->power
== BATT
) {
113 printf("On Battery");
114 for(i
= 0; i
< globals
->battery_count
; i
++) {
115 binfo
= &batteries
[i
];
116 if(binfo
->present
&& (binfo
->percentage
>= 0))
117 printf(", Battery %s at %d%%", binfo
->name
,
120 if(globals
->rtime
>= 0)
121 printf("; %d:%02d remaining", globals
->rtime
/60,