Permalink
Browse files

Merge pull request #18 from jmatth/extra_bat_support

Adding support for batteries without energy_now and energy_full.
  • Loading branch information...
creaktive committed Oct 29, 2013
2 parents 352346c + 5397d00 commit d63ba92b7ea556af9561ff261ee7e7b6324d831a
Showing with 9 additions and 6 deletions.
  1. +9 −6 rainbarf
View
@@ -384,8 +384,8 @@ sub battery {
my ($uevent, %battery) = ('');
if (grep {
-d $_
and -e qq($_/energy_full)
and -e qq($_/energy_now)
and ( ( -e qq($_/energy_full) and -e qq($_/energy_now) ) or
( -e qq($_/charge_now) and -e qq($_/current_now) ) )
and -e ($uevent = qq($_/uevent))
} sort glob q(/sys/class/power_supply/BAT[0-9])
) {
@@ -401,10 +401,13 @@ sub battery {
close $fh;
$charging = $battery{status} ne q(Discharging);
$time = eval { ($battery{energy_now} * 60 / $battery{power_now}) }
if not $charging
and defined $battery{power_now}
and $battery{power_now} =~ /^\d+$/x;
if (not $charging) {
if (defined $battery{power_now} and $battery{power_now} =~ /^\d+$/x) {
$time = eval { ($battery{energy_now} * 60 / $battery{power_now}) }
} elsif (defined $battery{charge_now} and $battery{charge_now} =~ /^\d+$/x) {
$time = eval { (60 * ($battery{charge_now} / 1000) / ($battery{current_now} / 1000)) }
}
}
$battery = $battery{capacity} / 100;
}
}

0 comments on commit d63ba92

Please sign in to comment.