blib/lib/DDCCI.pm

filter: Statementstmt 62.3% 43 / 69 Branchbran 35.0% 7 / 20 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 62.5% 10 / 16 Podpod 100% 10 / 10 totaltotal 62.5% 75 / 120 CC 14 SCAR 17.8
CC
14
Cov
58%
scan_devices
14.1
new
12.0
DESTROY
6.0
CRAP 6.0
↑ Summary DDCCI.xs »
1 package DDCCI;
2  
3 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use XSLoader;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use Exporter 5.57 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 3 our $VERSION = '0.002';
10 #our @ISA = qw Exporter );
11 3 our %EXPORT_TAGS = ( 'all' => [ qw() ] );
12 3 our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
13 3 our @EXPORT = qw(
14 &list_vcp_names
15 &get_vcp_name
16 &get_vcp_addr
17 &decode_edid
18 &scan_devices
19 );
20  
21 3 XSLoader::load('DDCCI', $VERSION);
22  
23 sub list_vcp_names {
24  
25 1 ▶ my $ret = [];
Subroutine list_vcp_names: called CC=3 SCAR=11.0
Pod documented
26  
27 1 for my $i (0x00 .. 0xff) {
28 256 my $n = _get_vcp_name($i);
29 256 ▶ push @{$ret}, $n if ($n ne '???');
Branch: 1 branch
BranchTrueFalseTotal
if $n ne "???" 76 180 256
30 }
31  
32 1 return $ret;
33 }
34  
35 sub get_vcp_name {
36  
37 258 ▶ my ($vcp) = @_;
Subroutine get_vcp_name: called CC=1 SCAR=0.0
Pod documented
38  
39 258 return _get_vcp_name($vcp);
40 }
41  
42 sub get_vcp_addr {
43  
44 5 ▶ my ($name) = @_;
Subroutine get_vcp_addr: called CC=1 SCAR=0.0
Pod documented
45  
46 5 return _get_vcp_addr($name);
47 }
48  
49 sub decode_edid {
50  
51 3 ▶ my ($edid) = @_;
Subroutine decode_edid: called CC=4 SCAR=13.9
Pod documented
52 3 ▶ return undef if (!defined $edid || (length($edid) != 128));
Branch: 1 branch
BranchTrueFalseTotal
if not defined $edid or length $edid != 128 2 1 3
Condition100%3/3
not defined $edid or length $edid != 128
l!l&&r!l&&!r
111
MC/DC100%2/2
not defined $edid or length $edid != 128
not defined $edid length $edid != 128
Truth table100%3/3
not(A) or B
A= not defined $edidB= length $edid != 128
ABresult
1X1
011
000
53  
54 1 my @b = (
55 unpack('@8C', $edid),
56 unpack('@9C', $edid),
57 unpack('@10S<', $edid),
58 unpack('@12L', $edid),
59 unpack('@20C', $edid)
60 );
61 return {
62 1 ▶ id => sprintf(
Branch: 1 branch
BranchTrueFalseTotal
$b[4] & 128 ? : 0 1 1
63 '%c%c%c%04X',
64 (($b[0] >> 2) & 0x1f) - 1 + ord('A'),
65 (($b[0] & 0x03) << 3) + ($b[1] >> 5) - 1 + ord('A'),
66 ($b[1] & 0x1f) - 1 + ord('A'),
67 $b[2]
68 ),
69 sn => sprintf('%lu', $b[3]),
70 type => ($b[4] & 0x80) ? 'digital' : 'analog',
71 };
72 }
73  
74 sub scan_devices {
75  
76 1 ▶ my $ret = [];
Subroutine scan_devices: called CC=6 SCAR=26.5
Pod documented
77  
78 1 ▶ opendir(my $dh, '/dev') || croak "cannot open /dev";
Branch: 1 branch
BranchTrueFalseTotal
opendir my $dh, "/dev" or croak("cannot open /dev") 0 1 1
79 1 ▶ my @devs = reverse grep { /^i2c-\d+$/ && (-c '/dev/' . $_) } readdir $dh;
Branch: 1 branch
BranchTrueFalseTotal
/^i2c-\d+$/ and -c '/dev/' . $_ 0 17 17
80 1 closedir $dh;
81  
82 1 for my $i (0 .. scalar @devs - 1) {
83 0 my $fn = '/dev/' . $devs[$i];
84 0 ▶ (my $fd = _open_dev($fn)) || next;
Branch: 1 branch
BranchTrueFalseTotal
my $fd = _open_dev($fn) or next 0 0 0
85 0 my $edid = _read_edid($fd);
86 0 my $de = decode_edid($edid);
87 0 ▶ if (defined $de) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $de) 0 0 0
88 0 push @{$ret}, {
89 dev => $fn,
90 id => $de->{'id'},
91 sn => $de->{'sn'},
92 0 type => $de->{'type'}
93 };
94 }
95 0 _close_dev($fd);
96 }
97  
98 1 return $ret;
99 }
100  
101 sub new {
102 0 ▶ my ($class, $dev) = @_;
Subroutine new: not called CC=3 SCAR=24.8
Pod documented
103 0 ▶ defined($dev) || croak "usage: $class\->new(\$dev)";
Branch: 1 branch
BranchTrueFalseTotal
defined $dev or croak("usage: $class->new(\$dev)") 0 0 0
104  
105 0 my $self = { fd => _open_dev($dev) };
106  
107 0 ▶ if ($self->{'fd'} < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"fd"} < 0) 0 0 0
108 0 croak "unable to open device $dev";
109 0 return undef;
110 }
111  
112 0 bless $self, $class;
113 0 return $self;
114 }
115  
116 sub DESTROY {
117 0 ▶ my ($self) = @_;
Subroutine DESTROY: not called CC=2 SCAR=17.9
118  
119 0 ▶ _close_dev($self->{'fd'}) unless ($self->{'fd'} < 0);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"fd"} < 0 0 0 0
120 }
121  
122 sub read_edid {
123 0 ▶ my ($self) = @_;
Subroutine read_edid: not called CC=1 SCAR=6.9
Pod documented
124  
125 0 return _read_edid($self->{'fd'});
126 }
127  
128 sub read_caps {
129 0 ▶ my ($self) = @_;
Subroutine read_caps: not called CC=1 SCAR=6.9
Pod documented
130  
131 0 return _read_caps($self->{'fd'});
132 }
133  
134 sub read_vcp {
135 0 ▶ my ($self, $addr) = @_;
Subroutine read_vcp: not called CC=1 SCAR=6.9
Pod documented
136  
137 0 return _read_vcp($self->{'fd'}, $addr);
138 }
139  
140 sub write_vcp {
141 0 ▶ my ($self, $addr, $value) = @_;
Subroutine write_vcp: not called CC=1 SCAR=6.9
Pod documented
142  
143 0 return _write_vcp($self->{'fd'}, $addr, $value);
144 }
145  
146 3 1;
147  
148 __END__
↑ Summary DDCCI.xs »