| 1 | package Protocol::IR::Proto::Mitsubishi; | ||||||||||||||||||||||||||||
| 2 | 55 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 55 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 55 | our $VERSION = '1.5'; | |||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 55 | ▶ | use Protocol::IR::Code; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 0 | ▶ | sub new { bless {}, shift } | ||||||||||||||||||||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 0 | ▶ | sub decode_raw { | ||||||||||||||||||||||||||
|
Subroutine
decode_raw: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 12 | 0 | my ($class, $raw) = @_; | |||||||||||||||||||||||||||
| 13 | 0 | ▶ | my $val = $raw =~ /^0x/i ? hex($raw) : $raw + 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 14 | 0 | return Protocol::IR::Code->new( | |||||||||||||||||||||||||||
| 15 | protocol => 'Mitsubishi', | ||||||||||||||||||||||||||||
| 16 | bits => 16, | ||||||||||||||||||||||||||||
| 17 | address => ($val >> 8) & 0xff, | ||||||||||||||||||||||||||||
| 18 | subaddress => -1, | ||||||||||||||||||||||||||||
| 19 | command => $val & 0xff, | ||||||||||||||||||||||||||||
| 20 | data => $val & 0xffff, | ||||||||||||||||||||||||||||
| 21 | ); | ||||||||||||||||||||||||||||
| 22 | } | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 2 | ▶ | sub decode_params { | ||||||||||||||||||||||||||
|
Subroutine
decode_params: called CC=7 SCAR=22.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 25 | 2 | my ($class, %args) = @_; | |||||||||||||||||||||||||||
| 26 | 2 | ▶ | my $addr = $args{address} // $args{device} // 0; | ||||||||||||||||||||||||||
|
Condition40%2/5
($args{"address"} // $args{"device"}) // 0
$args{"address"} // $args{"device"}
MC/DC0%0/2
($args{"address"} // $args{"device"}) // 0
$args{"address"}
$args{"device"}
Truth table33%1/3
A // B
A= $args{"address"}B= $args{"device"}
| |||||||||||||||||||||||||||||
| 27 | 2 | ▶ | $addr = hex($addr) if $addr =~ /^0x/i; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 28 | 2 | ▶ | my $cmd = $args{command} // $args{function} // 0; | ||||||||||||||||||||||||||
|
Condition40%2/5
($args{"command"} // $args{"function"}) // 0
$args{"command"} // $args{"function"}
MC/DC0%0/2
($args{"command"} // $args{"function"}) // 0
$args{"command"}
$args{"function"}
Truth table33%1/3
A // B
A= $args{"command"}B= $args{"function"}
| |||||||||||||||||||||||||||||
| 29 | 2 | ▶ | $cmd = hex($cmd) if $cmd =~ /^0x/i; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 30 | 2 | $addr &= 0xff; | |||||||||||||||||||||||||||
| 31 | 2 | $cmd &= 0xff; | |||||||||||||||||||||||||||
| 32 | 2 | my $data = ($addr << 8) | $cmd; | |||||||||||||||||||||||||||
| 33 | 2 | return Protocol::IR::Code->new( | |||||||||||||||||||||||||||
| 34 | protocol => 'Mitsubishi', | ||||||||||||||||||||||||||||
| 35 | bits => 16, | ||||||||||||||||||||||||||||
| 36 | address => $addr, | ||||||||||||||||||||||||||||
| 37 | subaddress => -1, | ||||||||||||||||||||||||||||
| 38 | command => $cmd, | ||||||||||||||||||||||||||||
| 39 | data => $data, | ||||||||||||||||||||||||||||
| 40 | ); | ||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 158 | ▶ | sub decode_timing { | ||||||||||||||||||||||||||
|
Subroutine
decode_timing: called CC=8 SCAR=20.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 44 | 158 | my ($class, $pairs) = @_; | |||||||||||||||||||||||||||
| 45 | 158 | ▶ | return undef unless ref $pairs eq 'ARRAY' && @$pairs >= 16; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
ref $pairs eq "ARRAY" and @$pairs >= 16
MC/DC50%1/2
ref $pairs eq "ARRAY" and @$pairs >= 16
ref $pairs eq "ARRAY"
@$pairs >= 16
Truth table66%2/3
A and B
A= ref $pairs eq "ARRAY"B= @$pairs >= 16
| |||||||||||||||||||||||||||||
| 46 | 85 | my $data = 0; | |||||||||||||||||||||||||||
| 47 | 85 | for my $i (0 .. 15) { | |||||||||||||||||||||||||||
| 48 | 154 | my ($mark, $space) = @{$pairs->[$i]}; | |||||||||||||||||||||||||||
| 49 | 154 | ▶ | return undef unless $mark >= 250 && $mark <= 350; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$mark >= 250 and $mark <= 350
MC/DC50%1/2
$mark >= 250 and $mark <= 350
$mark >= 250
$mark <= 350
Truth table66%2/3
A and B
A= $mark >= 250B= $mark <= 350
| |||||||||||||||||||||||||||||
| 50 | 82 | my $bit; | |||||||||||||||||||||||||||
| 51 | 82 | ▶ | if (abs($space - 2100) < 200) { $bit = 1; } | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 52 | 47 | elsif (abs($space - 900) < 200) { $bit = 0; } | |||||||||||||||||||||||||||
| 53 | 9 | else { return undef; } | |||||||||||||||||||||||||||
| 54 | 73 | $data = ($data << 1) | $bit; | |||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||
| 56 | 4 | return Protocol::IR::Code->new( | |||||||||||||||||||||||||||
| 57 | protocol => 'Mitsubishi', | ||||||||||||||||||||||||||||
| 58 | bits => 16, | ||||||||||||||||||||||||||||
| 59 | address => ($data >> 8) & 0xff, | ||||||||||||||||||||||||||||
| 60 | subaddress => -1, | ||||||||||||||||||||||||||||
| 61 | command => $data & 0xff, | ||||||||||||||||||||||||||||
| 62 | data => $data, | ||||||||||||||||||||||||||||
| 63 | ); | ||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 2 | ▶ | sub to_pronto { | ||||||||||||||||||||||||||
|
Subroutine
to_pronto: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 67 | 2 | my ($class, $code) = @_; | |||||||||||||||||||||||||||
| 68 | 2 | my $data = $code->{data} & 0xffff; | |||||||||||||||||||||||||||
| 69 | 2 | my $carrier_hz = 33000; | |||||||||||||||||||||||||||
| 70 | 2 | my $freq_word = int(1000000.0 / ($carrier_hz * 0.241246) + 0.5); | |||||||||||||||||||||||||||
| 71 | 2 | my $period_us = $freq_word * 0.241246; | |||||||||||||||||||||||||||
| 72 | 2 | ▶ | my $us_to_pulses = sub { int($_[0] / $period_us + 0.5) }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 2 | my @bits; | |||||||||||||||||||||||||||
| 75 | 2 | for my $i (reverse 0 .. 15) { push @bits, ($data >> $i) & 1; } | |||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 2 | my @pairs; | |||||||||||||||||||||||||||
| 78 | 2 | for my $bit (@bits) { | |||||||||||||||||||||||||||
| 79 | 32 | ▶ | push @pairs, [ $us_to_pulses->(300), $us_to_pulses->($bit ? 2100 : 900) ]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | 2 | my $seq1 = scalar(@pairs); | |||||||||||||||||||||||||||
| 83 | 2 | my $header = sprintf('0000 %04X %04X 0000', $freq_word, $seq1); | |||||||||||||||||||||||||||
| 84 | 2 | my $payload = join(' ', map { sprintf('%04X %04X', $_->[0], $_->[1]) } @pairs); | |||||||||||||||||||||||||||
| 85 | 2 | return "$header $payload"; | |||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | 55 | 1; | |||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | =head1 NAME | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | Protocol::IR::Proto::Mitsubishi - IR protocol handler | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | =head1 VERSION | ||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | version 1.5 | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | =cut | ||||||||||||||||||||||||||||