/[scripts]/trunk/dwm-status.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/dwm-status.pl

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 31 by dpavlin, Sat May 26 23:47:35 2007 UTC revision 33 by dpavlin, Sun May 27 08:41:53 2007 UTC
# Line 46  sub unit { Line 46  sub unit {
46    
47          if ( $v >= 1 ) {          if ( $v >= 1 ) {
48                  return sprintf("%d%s/s", $v, $units[$o]);                  return sprintf("%d%s/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/s", $v, $units[$o]);
53          }          }
# Line 61  while ( 1 ) { Line 63  while ( 1 ) {
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    
# Line 107  while ( 1 ) { Line 118  while ( 1 ) {
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 |%6s >> %-6s| %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  }  }

Legend:
Removed from v.31  
changed lines
  Added in v.33

  ViewVC Help
Powered by ViewVC 1.1.26