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 "2.3"
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"
42 " v - print version information\n",
46 void print_version(void)
48 printf("wmacpi-cli version %s\n", ACPI_VER
);
49 printf(" Using libacpi version %s\n", LIBACPI_VER
);
52 int main(int argc
, char *argv
[])
60 while((ch
= getopt(argc
, argv
, "hvVa:")) != EOF
) {
73 samples
= atoi(optarg
);
74 if(samples
> 1000 || samples
<= 0) {
75 fprintf(stderr
, "Please specify a reasonable number of samples\n");
79 pinfo("samples: %d\n", samples
);
80 sleep_time
= 1000000/samples
;
88 globals
= (global_t
*) malloc(sizeof(global_t
));
91 /* we want to acquire samples over some period of time, so . . . */
92 for(i
= 0; i
< samples
+ 2; i
++) {
93 for(j
= 0; j
< globals
->battery_count
; j
++)
94 acquire_batt_info(globals
, j
);
95 acquire_global_info(globals
);
99 ap
= &globals
->adapter
;
100 if(ap
->power
== AC
) {
101 printf("On AC Power");
102 for(i
= 0; i
< globals
->battery_count
; i
++) {
103 binfo
= &batteries
[i
];
104 if(binfo
->present
&& (binfo
->charge_state
== CHARGE
)) {
105 printf("; Battery %s charging", binfo
->name
);
106 printf(", currently at %2d%%", binfo
->percentage
);
107 if(binfo
->charge_time
>= 0)
108 printf(", %2d:%02d remaining",
109 binfo
->charge_time
/60,
110 binfo
->charge_time
%60);
114 } else if(ap
->power
== BATT
) {
115 printf("On Battery");
116 for(i
= 0; i
< globals
->battery_count
; i
++) {
117 binfo
= &batteries
[i
];
118 if(binfo
->present
&& (binfo
->percentage
>= 0))
119 printf(", Battery %s at %d%%", binfo
->name
,
122 if(globals
->rtime
>= 0)
123 printf("; %d:%02d remaining", globals
->rtime
/60,