91 |
|
|
92 |
my ( $lrx, $ltx ) = ( 0, 0 ); |
my ( $lrx, $ltx ) = ( 0, 0 ); |
93 |
my ( $ld_r, $ld_w ) = ( 0, 0 ); |
my ( $ld_r, $ld_w ) = ( 0, 0 ); |
94 |
my $bat; |
my $bat = ''; |
95 |
|
|
96 |
my $i = 0; |
my $i = 0; |
97 |
|
my $sys_fs = '/sys/class/power_supply/BAT0'; |
98 |
|
|
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 && $proc_acpi_battery ) { |
if ( $i % $acpi_every == 0 ) { |
103 |
|
if ( -e $sys_fs ) { |
104 |
|
|
105 |
|
my $full = read_file( "$sys_fs/charge_full" ); |
106 |
|
my $now = read_file( "$sys_fs/charge_now" ); |
107 |
|
$bat = sprintf("%2d%% | ", $now * 100 / $full ); |
108 |
|
|
109 |
my $state = proc2hash( "$proc_acpi_battery/state" ); |
} elsif ( $proc_acpi_battery ) { |
110 |
|
|
111 |
if ( $state->{'present rate'} != 0 ) { |
my $state = proc2hash( "$proc_acpi_battery/state" ); |
|
my $info = proc2hash( "$proc_acpi_battery/info" ); |
|
112 |
|
|
113 |
my $pcnt = $state->{'remaining capacity'} / $info->{'design capacity'}; |
if ( $state->{'present rate'} =~ m/^\d+$/ && $state->{'present rate'} != 0 ) { |
114 |
|
my $info = proc2hash( "$proc_acpi_battery/info" ); |
115 |
|
|
116 |
my $time = $state->{'remaining capacity'} / ( $state->{'present rate'} ); |
my $pcnt = $state->{'remaining capacity'} / $info->{'design capacity'}; |
|
$time = ( $info->{'design capacity'} - $state->{'remaining capacity'} ) / $state->{'present rate'} if ( $state->{'charging state'} eq 'charging' ); |
|
117 |
|
|
118 |
warn "time = $time\n" if ($debug); |
my $time = $state->{'remaining capacity'} / ( $state->{'present rate'} ); |
119 |
|
$time = ( $info->{'design capacity'} - $state->{'remaining capacity'} ) / $state->{'present rate'} if ( $state->{'charging state'} eq 'charging' ); |
120 |
|
|
121 |
my $hh = int( $time ); |
warn "time = $time\n" if ($debug); |
|
my $mm = int( ( $time - $hh ) * 60 ); |
|
|
my $ss = ( $time * 3600 ) % 60; |
|
122 |
|
|
123 |
$bat = sprintf("%s %2d%% %02d:%02d:%02d %3.1fW!| ", |
my $hh = int( $time ); |
124 |
substr($state->{'charging state'},0,1), |
my $mm = int( ( $time - $hh ) * 60 ); |
125 |
$pcnt * 100, $hh, $mm, $ss, |
my $ss = ( $time * 3600 ) % 60; |
|
$state->{'present rate'} / 1000 |
|
|
); |
|
126 |
|
|
127 |
} else { |
$bat = sprintf("%s %2d%% %02d:%02d:%02d %3.1fW!| ", |
128 |
$bat = ''; |
substr($state->{'charging state'},0,1), |
129 |
|
$pcnt * 100, $hh, $mm, $ss, |
130 |
|
$state->{'present rate'} / 1000 |
131 |
|
); |
132 |
} |
} |
133 |
|
} |
134 |
} else { |
} else { |
135 |
$bat =~ s/!(\|\s)$/ $1/; |
$bat =~ s/!(\|\s)$/ $1/; |
136 |
} |
} |