96 |
my $i = 0; |
my $i = 0; |
97 |
my $sys_fs = '/sys/class/power_supply/BAT0'; |
my $sys_fs = '/sys/class/power_supply/BAT0'; |
98 |
|
|
|
sub read_file { |
|
|
my $path = shift; |
|
|
open(my $fh, '<', $path) || die "can't open $path: $!"; |
|
|
my $c = <$fh>; |
|
|
chomp($c); |
|
|
close($fh); |
|
|
return $c; |
|
|
} |
|
|
|
|
99 |
while ( 1 ) { |
while ( 1 ) { |
100 |
my $s = strftime("%Y-%m-%d %H:%M:%S", localtime()); |
my $s = strftime("%Y-%m-%d %H:%M:%S", localtime()); |
101 |
|
|
102 |
if ( $i % $acpi_every == 0 ) { |
if ( $i % $acpi_every == 0 ) { |
103 |
if ( $proc_acpi_battery ) { |
if ( -e $sys_fs ) { |
104 |
|
|
105 |
|
my $path = glob "$sys_fs/*_full"; |
106 |
|
my $full = read_file( $path ); |
107 |
|
$path =~ s/_full/_now/; |
108 |
|
my $now = read_file( $path ); |
109 |
|
$bat = sprintf("%2d%% | ", $now * 100 / $full ); |
110 |
|
|
111 |
|
} elsif ( $proc_acpi_battery ) { |
112 |
|
|
113 |
my $state = proc2hash( "$proc_acpi_battery/state" ); |
my $state = proc2hash( "$proc_acpi_battery/state" ); |
114 |
|
|
132 |
$state->{'present rate'} / 1000 |
$state->{'present rate'} / 1000 |
133 |
); |
); |
134 |
} |
} |
|
} elsif ( -e $sys_fs ) { |
|
|
my $full = read_file( "$sys_fs/charge_full" ); |
|
|
my $now = read_file( "$sys_fs/charge_now" ); |
|
|
$bat = sprintf("%2d%% | ", $now * 100 / $full ); |
|
135 |
} |
} |
136 |
} else { |
} else { |
137 |
$bat =~ s/!(\|\s)$/ $1/; |
$bat =~ s/!(\|\s)$/ $1/; |