--- trunk/dwm-status.pl 2007/05/26 23:47:35 31 +++ trunk/dwm-status.pl 2007/05/27 08:39:20 32 @@ -61,23 +61,32 @@ if ( $i % $acpi_every == 0 ) { - $bat->{state} = proc2hash( '/proc/acpi/battery/BAT0/state' ); - $bat->{info} = proc2hash( '/proc/acpi/battery/BAT0/info' ); + my $state = proc2hash( '/proc/acpi/battery/BAT0/state' ); - $bat->{pcnt} = $bat->{state}->{'remaining capacity'} / $bat->{info}->{'design capacity'}; + if ( $state->{'present rate'} != 0 ) { + my $info = proc2hash( '/proc/acpi/battery/BAT0/info' ); - my $time = ( $bat->{info}->{'design capacity'} - $bat->{state}->{'remaining capacity'} ) / $bat->{state}->{'present rate'}; + my $pcnt = $state->{'remaining capacity'} / $info->{'design capacity'}; - warn "time = $time\n" if ($debug); + my $time = $state->{'remaining capacity'} / ( $state->{'present rate'} ); - $bat->{hh} = int( $time ); - $bat->{mm} = int( ( $time - $bat->{hh} ) * 60 ); - $bat->{ss} = ( $time * 3600 ) % 60; + warn "time = $time\n" if ($debug); - $bat->{new} = '!'; + my $hh = int( $time ); + my $mm = int( ( $time - $hh ) * 60 ); + my $ss = ( $time * 3600 ) % 60; + $bat = sprintf("%s %2d%% %02d:%02d:%02d %3.1fW!| ", + substr($state->{'charging state'},0,1), + $pcnt * 100, $hh, $mm, $ss, + $state->{'present rate'} / 1000 + ); + + } else { + $bat = ''; + } } else { - $bat->{new} = ' '; + $bat =~ s/!(\|\s)$/ $1/; } $i++; @@ -107,13 +116,7 @@ my $t = ( $tx - $ltx ) / $dt; ( $lrx, $ltx ) = ( $rx, $tx ); - printf "%s | %s |%6s >> %-6s| %s %2d%% %02d:%02d:%02d %3.1fW%s| %s\n", - $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; + printf "%s | %s |%6s >> %-6s| %s%s\n", $s, $load, unit( $r ), unit( $t ), $bat, $temp; sleep $dt; }