line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# |
2
|
|
|
|
|
|
|
# $Id$ |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
# harware::battery Brik |
5
|
|
|
|
|
|
|
# |
6
|
|
|
|
|
|
|
package Metabrik::Hardware::Battery; |
7
|
1
|
|
|
1
|
|
525
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
29
|
|
8
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
29
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
5
|
use base qw(Metabrik::File::Text); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
396
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub brik_properties { |
13
|
|
|
|
|
|
|
return { |
14
|
0
|
|
|
0
|
1
|
|
revision => '$Revision$', |
15
|
|
|
|
|
|
|
tags => [ qw(unstable) ], |
16
|
|
|
|
|
|
|
author => 'GomoR ', |
17
|
|
|
|
|
|
|
license => 'http://opensource.org/licenses/BSD-3-Clause', |
18
|
|
|
|
|
|
|
commands => { |
19
|
|
|
|
|
|
|
capacity => [ ], |
20
|
|
|
|
|
|
|
}, |
21
|
|
|
|
|
|
|
}; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub capacity { |
25
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
26
|
|
|
|
|
|
|
|
27
|
0
|
|
|
|
|
|
my $base_file = '/sys/class/power_supply/BAT'; |
28
|
0
|
0
|
|
|
|
|
$self->brik_help_run_file_not_found('capacity', $base_file) or return; |
29
|
|
|
|
|
|
|
|
30
|
0
|
|
|
|
|
|
my $battery_hash = {}; |
31
|
0
|
|
|
|
|
|
my $count = 0; |
32
|
0
|
|
|
|
|
|
while (-f "$base_file$count/capacity") { |
33
|
0
|
0
|
|
|
|
|
my $data = $self->read("$base_file$count/capacity") or next; |
34
|
0
|
|
|
|
|
|
chomp($data); |
35
|
|
|
|
|
|
|
|
36
|
0
|
|
|
|
|
|
my $this = sprintf("battery_%02d", $count); |
37
|
0
|
|
|
|
|
|
$battery_hash->{$this} = { |
38
|
|
|
|
|
|
|
battery => $count, |
39
|
|
|
|
|
|
|
capacity => $data, |
40
|
|
|
|
|
|
|
}; |
41
|
|
|
|
|
|
|
|
42
|
0
|
|
|
|
|
|
$count++; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
0
|
|
|
|
|
|
return $battery_hash; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
1; |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
__END__ |