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