Projet

Général

Profil

Révision 54977029

ID54977029d5308451c5b7dbe6e68c11622cc8b319
Parent 3037bb86
Enfant 3b10114d

Ajouté par Gorlow Maxim aka Sheridan il y a presque 14 ans

autoconf, some minor changes

Voir les différences:

plugins/other/batteries
32 32

  
33 33
=head1 MAGIC MARKERS
34 34

  
35
#%# family=power
35
 #%# family=power
36
 #%# capabilities=autoconf
36 37

  
37 38
=head1 VERSION 
38 39

  
......
103 104
  my $sys_batt_count  = get_batteryes_count($sys_path );
104 105
  #print "$proc_batt_count $sys_batt_count\n";
105 106
  $proc_data_exists = $proc_batt_count > 0;
106
  $sys_data_exists = $sys_batt_count > 0;
107
  $sys_data_exists = $sys_batt_count   > 0;
107 108
  if ($proc_data_exists and $sys_data_exists and ($proc_batt_count != $sys_batt_count))
108 109
  {
109 110
    die "Something wrong, batteryes count from $proc_path and $sys_path not equal (proc: $proc_batt_count, sys: $sys_batt_count)!"
110 111
  }
111
  if    ($proc_data_exists) { $batteryes_count = $proc_batt_count; }
112
  elsif ($sys_data_exists) { $batteryes_count = $sys_batt_count; }
112
  if     ($proc_data_exists) { $batteryes_count = $proc_batt_count; }
113
  elsif  ($sys_data_exists)  { $batteryes_count = $sys_batt_count;  }
113 114
  unless ($batteryes_count)
114 115
  {
115 116
    die "Batteryes not found."
......
160 161
    if($sys_data_exists)
161 162
    {
162 163
      $info->{$i}{'manufacturer'}  = read_sys_data($i, 'manufacturer');
163
      $info->{$i}{'battery_type'}  = read_sys_data($i, 'technology');
164
      $info->{$i}{'model_name'}    = read_sys_data($i, 'model_name');
164
      $info->{$i}{'battery_type'}  = read_sys_data($i, 'technology'   );
165
      $info->{$i}{'model_name'}    = read_sys_data($i, 'model_name'   );
165 166
      $info->{$i}{'serial_number'} = read_sys_data($i, 'serial_number');
166 167
    }
167 168
    else
168 169
    {
169 170
      my $proc_info = read_proc_data($i, 'info');
170
      $info->{$i}{'manufacturer'}  = $proc_info->{'OEM info'};
171
      $info->{$i}{'battery_type'}  = $proc_info->{'battery type'};
172
      $info->{$i}{'model_name'}    = $proc_info->{'model number'};
171
      $info->{$i}{'manufacturer'}  = $proc_info->{'OEM info'     };
172
      $info->{$i}{'battery_type'}  = $proc_info->{'battery type' };
173
      $info->{$i}{'model_name'}    = $proc_info->{'model number' };
173 174
      $info->{$i}{'serial_number'} = $proc_info->{'serial number'};
174 175
    }
175 176
  }
......
183 184
  {
184 185
    if($sys_data_exists)
185 186
    {
186
      $data->{$i}{'design_capacity'}    = read_sys_data($i, 'charge_full_design')/1000000;
187
      $data->{$i}{'last_full_capacity'} = read_sys_data($i, 'charge_full')/1000000;
188
      $data->{$i}{'remaining_capacity'} = read_sys_data($i, 'charge_now')/1000000;
189
      $data->{$i}{'design_voltage'}     = read_sys_data($i, 'voltage_min_design')/1000000;
190
      $data->{$i}{'present_voltage'}    = read_sys_data($i, 'voltage_now')/1000000;
191
      $data->{$i}{'present_rate'}       = read_sys_data($i, 'current_now')/1000000;
187
      my $divider = 1000000; # need for equvivalent sys and proc data
188
      $data->{$i}{'design_capacity'}    = read_sys_data($i, 'charge_full_design')/$divider;
189
      $data->{$i}{'last_full_capacity'} = read_sys_data($i, 'charge_full')       /$divider;
190
      $data->{$i}{'remaining_capacity'} = read_sys_data($i, 'charge_now')        /$divider;
191
      $data->{$i}{'design_voltage'}     = read_sys_data($i, 'voltage_min_design')/$divider;
192
      $data->{$i}{'present_voltage'}    = read_sys_data($i, 'voltage_now')       /$divider;
193
      $data->{$i}{'present_rate'}       = read_sys_data($i, 'current_now')       /$divider;
192 194
    }
193 195
    if($proc_data_exists)
194 196
    {
197
      my $divider = 1000; # need for equvivalent sys and proc data
195 198
      my $proc_info = read_proc_data($i, 'info');
196 199
      unless($sys_data_exists)
197 200
      {
198 201
        my $proc_state = read_proc_data($i, 'state');
199
        $data->{$i}{'design_capacity'}         = $proc_info ->{'design capacity'}/1000;
200
        $data->{$i}{'last_full_capacity'}      = $proc_info ->{'last full capacity'}/1000;
201
        $data->{$i}{'remaining_capacity'}      = $proc_state->{'remaining capacity'}/1000;
202
        $data->{$i}{'design_voltage'}          = $proc_info ->{'design voltage'}/1000;
203
        $data->{$i}{'present_voltage'}         = $proc_state->{'present voltage'}/1000;
204
        $data->{$i}{'present_rate'}            = $proc_state->{'present rate'}/1000;
202
        $data->{$i}{'design_capacity'}    = $proc_info ->{'design capacity'}   /$divider;
203
        $data->{$i}{'last_full_capacity'} = $proc_info ->{'last full capacity'}/$divider;
204
        $data->{$i}{'remaining_capacity'} = $proc_state->{'remaining capacity'}/$divider;
205
        $data->{$i}{'design_voltage'}     = $proc_info ->{'design voltage'}    /$divider;
206
        $data->{$i}{'present_voltage'}    = $proc_state->{'present voltage'}   /$divider;
207
        $data->{$i}{'present_rate'}       = $proc_state->{'present rate'}      /$divider;
205 208
      }
206
      $data->{$i}{'design_capacity_low'}     = $proc_info ->{'design capacity low'}/1000;
207
      $data->{$i}{'design_capacity_warning'} = $proc_info ->{'design capacity warning'}/1000;
208
      $data->{$i}{'capacity_granularity_1'}  = $proc_info ->{'capacity granularity 1'}/1000;
209
      $data->{$i}{'capacity_granularity_2'}  = $proc_info ->{'capacity granularity 2'}/1000;
209
      $data->{$i}{'design_capacity_low'}     = $proc_info ->{'design capacity low'}    /$divider;
210
      $data->{$i}{'design_capacity_warning'} = $proc_info ->{'design capacity warning'}/$divider;
211
      $data->{$i}{'capacity_granularity_1'}  = $proc_info ->{'capacity granularity 1'} /$divider;
212
      $data->{$i}{'capacity_granularity_2'}  = $proc_info ->{'capacity granularity 2'} /$divider;
210 213
    }
211 214
    $data->{$i}{'current_voltage_percent'}  = percent($data->{$i}{'design_voltage'}    , $data->{$i}{'present_voltage'});
212 215
    $data->{$i}{'current_capacity_percent'} = percent($data->{$i}{'last_full_capacity'}, $data->{$i}{'remaining_capacity'});
......
247 250

  
248 251
# ------------------------------------ start here -----------------------------------
249 252

  
253
if (defined($ARGV[0]) and ($ARGV[0] eq 'autoconf')) 
254
{
255
  printf("%s\n", (-e $proc_path or -e $sys_path) ? "yes" : "no ($proc_path and $sys_path not exists)");
256
  exit (0);
257
}
258

  
250 259
init();
251 260

  
252 261
if ($ARGV[0] and $ARGV[0] eq "config")
......
256 265
  foreach my $graph (keys %{$graphs})
257 266
  {
258 267
    my @order;
259
    $config{$graph}{'graph'}{'title'}  = sprintf($graphs->{$graph}{'title'}, 'Mean batteryes');
260
    $config{$graph}{'graph'}{'args'}   = $graphs->{$graph}{'args'};
261
    $config{$graph}{'graph'}{'vlabel'} = $graphs->{$graph}{'vlabel'};
268
    $config{$graph}{'graph'}{'title'}    = sprintf($graphs->{$graph}{'title'}, 'Mean batteryes');
269
    $config{$graph}{'graph'}{'args'}     = $graphs->{$graph}{'args'};
270
    $config{$graph}{'graph'}{'vlabel'}   = $graphs->{$graph}{'vlabel'};
262 271
    $config{$graph}{'graph'}{'category'} = 'power';
263 272
    foreach my $field (@{$graphs->{$graph}{'fields'}})
264 273
    {
......
277 286
      my @b_order;
278 287
      my $battery_name = sprintf("BAT%s", $i);
279 288
      my $graph_name   = sprintf("%s.%s", $graph, $battery_name);
280
      $config{$graph_name}{'graph'}{'title'}  = sprintf($graphs->{$graph}{'title'}, $battery_name);
281
      $config{$graph_name}{'graph'}{'info'}   = sprintf("%s battery %s %s (sn: %s)", $info->{$i}{'battery_type'}, $info->{$i}{'manufacturer'}, $info->{$i}{'model_name'}, $info->{$i}{'serial_number'});
282
      $config{$graph_name}{'graph'}{'args'}   = '--base 1000';
283
      $config{$graph_name}{'graph'}{'vlabel'} = $graphs->{$graph}{'vlabel'};
289
      $config{$graph_name}{'graph'}{'title'}    = sprintf($graphs->{$graph}{'title'}, $battery_name);
290
      $config{$graph_name}{'graph'}{'info'}     = sprintf("%s battery %s %s (sn: %s)", $info->{$i}{'battery_type'}, $info->{$i}{'manufacturer'}, $info->{$i}{'model_name'}, $info->{$i}{'serial_number'});
291
      $config{$graph_name}{'graph'}{'args'}     = '--base 1000';
292
      $config{$graph_name}{'graph'}{'vlabel'}   = $graphs->{$graph}{'vlabel'};
284 293
      $config{$graph_name}{'graph'}{'category'} = 'power';
285 294
      foreach my $field (@{$graphs->{$graph}{'fields'}})
286 295
      {
......
348 357
    print "\n";
349 358
  }
350 359
}
351

  
352

  
353

  

Formats disponibles : Unified diff