9 use Term::ANSIColor qw(:constants);
11 die "No information on battery 0\n" if not -r '/proc/pmu/battery_0';
13 my $bat_inf_fh = new IO::File '/proc/pmu/battery_0';
18 my $battery_info = {};
20 while (<$bat_inf_fh>) {
21 if (/(.+?)\s*:\s*(-?\d+)/) {
22 $battery_info->{$1} = int $2;
29 #print Dumper($battery_info);
32 if (exists $battery_info->{'time rem.'}) {
33 my $hours = int $battery_info->{'time rem.'}/3600;
34 my $minutes = (int $battery_info->{'time rem.'}/60)%60;
35 my $seconds = $battery_info->{'time rem.'}%60;
36 my $is_charging = hex $battery_info->{flags} & 2;
37 my $charge_state = $is_charging?'Charging':'Discharging';
38 # TODO Split charging and discharging current
40 if ($battery_info->{current} > 0) {
41 $current = floor($battery_info->{current}/$max_in*1000)/10;
44 $current = floor($battery_info->{current}/$max_out*1000)/10;
47 my $percentage = floor($battery_info->{'charge'}/$battery_info->{'max_charge'}*1000)/10;
54 print "$charge_state at $current\%: $hours hours, $minutes minutes, and $seconds seconds remaining. [$percentage\%]\n";