45 |
} |
} |
46 |
|
|
47 |
if ( $v >= 1 ) { |
if ( $v >= 1 ) { |
48 |
return sprintf("%d%s/s", $v, $units[$o]); |
return sprintf("%d%s", $v, $units[$o]); |
49 |
|
} elsif ( $v == 0 ) { |
50 |
|
return ''; |
51 |
} else { |
} else { |
52 |
return sprintf("%.1f%s/s", $v, $units[$o]); |
return sprintf("%.1f%s", $v, $units[$o]); |
53 |
} |
} |
54 |
} |
} |
55 |
|
|
63 |
|
|
64 |
if ( $i % $acpi_every == 0 ) { |
if ( $i % $acpi_every == 0 ) { |
65 |
|
|
66 |
$bat->{state} = proc2hash( '/proc/acpi/battery/BAT0/state' ); |
my $state = proc2hash( '/proc/acpi/battery/BAT0/state' ); |
|
$bat->{info} = proc2hash( '/proc/acpi/battery/BAT0/info' ); |
|
67 |
|
|
68 |
$bat->{pcnt} = $bat->{state}->{'remaining capacity'} / $bat->{info}->{'design capacity'}; |
if ( $state->{'present rate'} != 0 ) { |
69 |
|
my $info = proc2hash( '/proc/acpi/battery/BAT0/info' ); |
70 |
|
|
71 |
my $time = ( $bat->{info}->{'design capacity'} - $bat->{state}->{'remaining capacity'} ) / $bat->{state}->{'present rate'}; |
my $pcnt = $state->{'remaining capacity'} / $info->{'design capacity'}; |
72 |
|
|
73 |
warn "time = $time\n" if ($debug); |
my $time = $state->{'remaining capacity'} / ( $state->{'present rate'} ); |
74 |
|
|
75 |
$bat->{hh} = int( $time ); |
warn "time = $time\n" if ($debug); |
|
$bat->{mm} = int( ( $time - $bat->{hh} ) * 60 ); |
|
|
$bat->{ss} = ( $time * 3600 ) % 60; |
|
76 |
|
|
77 |
$bat->{new} = '!'; |
my $hh = int( $time ); |
78 |
|
my $mm = int( ( $time - $hh ) * 60 ); |
79 |
|
my $ss = ( $time * 3600 ) % 60; |
80 |
|
|
81 |
|
$bat = sprintf("%s %2d%% %02d:%02d:%02d %3.1fW!| ", |
82 |
|
substr($state->{'charging state'},0,1), |
83 |
|
$pcnt * 100, $hh, $mm, $ss, |
84 |
|
$state->{'present rate'} / 1000 |
85 |
|
); |
86 |
|
|
87 |
|
} else { |
88 |
|
$bat = ''; |
89 |
|
} |
90 |
} else { |
} else { |
91 |
$bat->{new} = ' '; |
$bat =~ s/!(\|\s)$/ $1/; |
92 |
} |
} |
93 |
$i++; |
$i++; |
94 |
|
|
118 |
my $t = ( $tx - $ltx ) / $dt; |
my $t = ( $tx - $ltx ) / $dt; |
119 |
( $lrx, $ltx ) = ( $rx, $tx ); |
( $lrx, $ltx ) = ( $rx, $tx ); |
120 |
|
|
121 |
printf "%s | %s |%6s >> %-6s| %s %2d%% %02d:%02d:%02d %3.1fW%s| %s\n", |
printf "%s | %s |%5s > %-5s| %s%s\n", $s, $load, unit( $r ), unit( $t ), $bat, $temp; |
|
$s, |
|
|
$load, |
|
|
unit( $r ), unit( $t ), |
|
|
substr($bat->{state}->{'charging state'},0,1), $bat->{pcnt} * 100, $bat->{hh}, $bat->{mm}, $bat->{ss}, |
|
|
$bat->{state}->{'present rate'} / 1000, $bat->{new}, |
|
|
$temp; |
|
122 |
|
|
123 |
sleep $dt; |
sleep $dt; |
124 |
} |
} |