/[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 74 by dpavlin, Thu Apr 3 18:39:38 2008 UTC revision 80 by dpavlin, Tue Jul 22 01:15:19 2008 UTC
# Line 91  sub unit { Line 91  sub unit {
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    sub read_file {
100            my $path = shift;
101            open(my $fh, '<', $path) || die "can't open $path: $!";
102            my $c = <$fh>;
103            chomp($c);
104            close($fh);
105            return $c;
106    }
107    
108  while ( 1 ) {  while ( 1 ) {
109          my $s = strftime("%Y-%m-%d %H:%M:%S", localtime());          my $s = strftime("%Y-%m-%d %H:%M:%S", localtime());
110    
111          if ( $i % $acpi_every == 0 && $proc_acpi_battery ) {          if ( $i % $acpi_every == 0 ) {
112                    if ( $proc_acpi_battery ) {
113    
114                  my $state = proc2hash( "$proc_acpi_battery/state" );                          my $state = proc2hash( "$proc_acpi_battery/state" );
115    
116                  if ( $state->{'present rate'} != 0 ) {                          if ( $state->{'present rate'} =~ m/^\d+$/ && $state->{'present rate'} != 0 ) {
117                          my $info = proc2hash( "$proc_acpi_battery/info" );                                  my $info = proc2hash( "$proc_acpi_battery/info" );
118    
119                          my $pcnt = $state->{'remaining capacity'} / $info->{'design capacity'};                                  my $pcnt = $state->{'remaining capacity'} / $info->{'design capacity'};
120    
121                          my $time = $state->{'remaining capacity'} / ( $state->{'present rate'} );                                  my $time = $state->{'remaining capacity'} / ( $state->{'present rate'} );
122                          $time = ( $info->{'design capacity'} - $state->{'remaining capacity'} ) / $state->{'present rate'} if ( $state->{'charging state'} eq 'charging' );                                  $time = ( $info->{'design capacity'} - $state->{'remaining capacity'} ) / $state->{'present rate'} if ( $state->{'charging state'} eq 'charging' );
123    
124                          warn "time = $time\n" if ($debug);                                  warn "time = $time\n" if ($debug);
125    
126                          my $hh = int( $time );                                  my $hh = int( $time );
127                          my $mm = int( ( $time - $hh ) * 60 );                                  my $mm = int( ( $time - $hh ) * 60 );
128                          my $ss = ( $time * 3600 ) % 60;                                  my $ss = ( $time * 3600 ) % 60;
129    
130                          $bat = sprintf("%s %2d%% %02d:%02d:%02d %3.1fW!| ",                                  $bat = sprintf("%s %2d%% %02d:%02d:%02d %3.1fW!| ",
131                                  substr($state->{'charging state'},0,1),                                          substr($state->{'charging state'},0,1),
132                                  $pcnt * 100, $hh, $mm, $ss,                                          $pcnt * 100, $hh, $mm, $ss,
133                                  $state->{'present rate'} / 1000                                          $state->{'present rate'} / 1000
134                          );                                  );
   
                         } else {  
                                 $bat = '';  
135                          }                          }
136                    } elsif ( -e $sys_fs ) {
137                            my $full = read_file( "$sys_fs/charge_full" );
138                            my $now = read_file( "$sys_fs/charge_now" );
139                            $bat = sprintf("%2d%% | ", $now * 100 / $full );
140                    }
141          } else {          } else {
142                  $bat =~ s/!(\|\s)$/ $1/;                  $bat =~ s/!(\|\s)$/ $1/;
143          }          }

Legend:
Removed from v.74  
changed lines
  Added in v.80

  ViewVC Help
Powered by ViewVC 1.1.26