| 1 | package Protocol::IR::Proto::SAMSUNG20; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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 | 55 | ▶ | use Protocol::IR::Code; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 55 | ▶ | use Math::BigInt; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | # Protocol::IR::Proto::SAMSUNG20 is the SAMSUNG20 protocol handler | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | # (20-bit), from the MakeHex Samsung20.irp and DecodeIR definitions: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | # {38.4k,564}<1,-1|1,-3>(8,-8,D:6,S:6,F:8,1,-44) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | # A 20-bit frame carries a 6-bit device, a 6-bit subdevice, and an 8-bit | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | # function, transmitted LSB-first within each field behind a 4512/4512 µs | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | # header (the same header Samsung's 32-bit protocol uses). The whole frame is | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | # sent once, so a capture is header + 20 bits + stop. IRDB uses it for Samsung | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | # air-conditioner handsets. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 55 | ▶ | sub _parse_int { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_parse_int: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 55 | my ($val) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 55 | ▶ | return 0 unless defined $val; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 55 | $val =~ s/^\s+|\s+$//g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 55 | ▶ | return Math::BigInt->from_hex($val) if $val =~ /^0x/i; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 54 | return $val + 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | # True when the accumulated word (Tasmota DataLSB) is the form decode_raw | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | # reads; SAMSUNG20 has no display/accumulated distinction, so decode_byte_order | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | # is inherited from decode_raw. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 0 | ▶ | sub lsb_is_accumulated { 1 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
lsb_is_accumulated: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | # Pack device/subdevice/function into the transmitted 20-bit word. The | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | # default subdevice is 0 per Samsung20.irp (Default S=0), so a caller that | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | # omits it (subaddress -1) sends a zero field. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 36 | ▶ | sub _encode_data { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_encode_data: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 36 | my ($addr, $subaddr, $cmd) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 36 | return (($cmd & 0xFF) << 12) | (($subaddr & 0x3F) << 6) | ($addr & 0x3F); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 1 | ▶ | sub decode_raw { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
decode_raw: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 1 | my ($class, $raw_val) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 1 | my $val = _parse_int($raw_val); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 1 | return Protocol::IR::Code->new( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | protocol => 'SAMSUNG20', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | bits => 20, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | address => $val & 0x3F, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | subaddress => ($val >> 6) & 0x3F, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | command => ($val >> 12) & 0xFF, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | data => $val, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 18 | ▶ | sub decode_params { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
decode_params: called CC=8 SCAR=21.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 18 | my ($class, %args) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 18 | ▶ | my $addr = _parse_int($args{address} // $args{device} // 0) & 0x3F; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition60%3/5
($args{"address"} // $args{"device"}) // 0
$args{"address"} // $args{"device"}
MC/DC0%0/2
($args{"address"} // $args{"device"}) // 0
$args{"address"}
$args{"device"}
Truth table66%2/3
A // B
A= $args{"address"}B= $args{"device"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 18 | ▶ | my $subaddr_arg = _parse_int($args{subaddress} // $args{subdevice} // -1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%5/5
($args{"subaddress"} // $args{"subdevice"}) // -1
$args{"subaddress"} // $args{"subdevice"}
MC/DC100%2/2
($args{"subaddress"} // $args{"subdevice"}) // -1
$args{"subaddress"}
$args{"subdevice"}
Truth table100%3/3
A // B
A= $args{"subaddress"}B= $args{"subdevice"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 18 | ▶ | my $cmd = _parse_int($args{command} // $args{function} // 0) & 0xFF; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
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"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | # Default S=0: a missing subdevice sends a zero field; the stored | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | # subaddress stays -1. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 18 | ▶ | my $subaddr = ($subaddr_arg == -1) ? 0 : $subaddr_arg & 0x3F; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 18 | return Protocol::IR::Code->new( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | protocol => 'SAMSUNG20', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | bits => 20, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | address => $addr, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | subaddress => $subaddr_arg, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | command => $cmd, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | data => _encode_data($addr, $subaddr, $cmd), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | # Decode microsecond timing pairs into Protocol::IR::Code | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 307 | ▶ | sub decode_timing { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
decode_timing: called CC=12 SCAR=25.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 307 | my ($class, $burst_pairs) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 307 | ▶ | return undef unless scalar(@$burst_pairs) >= 22; # Header + 20 bits + Stop | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 158 | my ($hdr_mark, $hdr_space) = @{$burst_pairs->[0]}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | # SAMSUNG20 Header Check: ~4512 µs mark, ~4512 µs space | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 158 | ▶ | return undef unless ($hdr_mark >= 3800 && $hdr_mark <= 5200) && | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%6/9
$hdr_mark >= 3800 and $hdr_mark <= 5200 and ($hdr_space >= 3800 and $hdr_space <= 5200)
$hdr_mark >= 3800 and $hdr_mark <= 5200
$hdr_space >= 3800 and $hdr_space <= 5200
MC/DC50%2/4
$hdr_mark >= 3800 and $hdr_mark <= 5200 and ($hdr_space >= 3800 and $hdr_space <= 5200)
$hdr_mark >= 3800
$hdr_mark <= 5200
$hdr_space >= 3800
$hdr_space <= 5200
Truth table60%3/5
A and B and C and D
A= $hdr_mark >= 3800B= $hdr_mark <= 5200C= $hdr_space >= 3800D= $hdr_space <= 5200
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | ($hdr_space >= 3800 && $hdr_space <= 5200); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 49 | my $value = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 49 | for my $i (0 .. 19) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 980 | my $pair = $burst_pairs->[$i + 1]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 980 | my $space = $pair->[1]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | # Space ~1692 µs = 1, ~564 µs = 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 980 | ▶ | my $bit = ($space > 1100) ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 980 | $value |= ($bit << $i); # LSB-first | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | # Stop bit: a short mark followed by the ~25ms inter-frame space. A | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | # capture may end on a bare trailing mark with no space. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 49 | my ($stop_mark, $stop_space) = @{$burst_pairs->[21]}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 49 | ▶ | return undef unless ($stop_mark >= 400 && $stop_mark <= 900) && | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%6/9
$stop_mark >= 400 and $stop_mark <= 900 and $stop_space == 0 || $stop_space >= 3000
$stop_mark >= 400 and $stop_mark <= 900
$stop_space == 0 or $stop_space >= 3000
MC/DC50%2/4
$stop_mark >= 400 and $stop_mark <= 900 and $stop_space == 0 || $stop_space >= 3000
$stop_mark >= 400
$stop_mark <= 900
$stop_space == 0
$stop_space >= 3000
Truth table60%3/5
A and B and C or D
A= $stop_mark >= 400B= $stop_mark <= 900C= $stop_space == 0D= $stop_space >= 3000
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | ($stop_space == 0 || $stop_space >= 3000); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 48 | return Protocol::IR::Code->new( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | protocol => 'SAMSUNG20', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | bits => 20, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | address => $value & 0x3F, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | subaddress => ($value >> 6) & 0x3F, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | command => ($value >> 12) & 0xFF, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | data => $value, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 18 | ▶ | sub to_pronto { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
to_pronto: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 18 | my ($class, $code) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 18 | my $carrier_hz = 38400; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | # Build the pulse conversion period from the rounded Pronto frequency | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | # word, as MakeHex and Pronto parsers do (see Protocol::IR::Proto::NEC). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 18 | my $freq_word = int(sprintf("%.0f", 1000000.0 / ($carrier_hz * 0.241246))); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 18 | my $period_us = $freq_word * 0.241246; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 18 | ▶ | my $us_to_pulses = sub { int(sprintf("%.0f", $_[0] / $period_us)) }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 18 | my $addr = $code->address & 0x3F; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 18 | ▶ | my $subaddr = ($code->subaddress != -1) ? ($code->subaddress & 0x3F) : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 18 | my $cmd = $code->command & 0xFF; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 18 | my $data = _encode_data($addr, $subaddr, $cmd); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 18 | my @bits; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 18 | for my $i (0 .. 19) { push @bits, ($data >> $i) & 1; } # LSB-first | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 18 | my @burst_pairs = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | [$us_to_pulses->(4512), $us_to_pulses->(4512)] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 18 | for my $bit (@bits) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 360 | ▶ | push @burst_pairs, [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | $us_to_pulses->(564), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | $us_to_pulses->($bit ? 1692 : 564) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | # The trailing mark and ~25ms inter-frame space (1,-44 of 564 µs). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 18 | push @burst_pairs, [$us_to_pulses->(564), $us_to_pulses->(24816)]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 18 | my $seq1_pairs = scalar @burst_pairs; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 18 | my $header = sprintf("0000 %04X %04X 0000", $freq_word, $seq1_pairs); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 18 | my @payload = map { sprintf("%04X %04X", $_->[0], $_->[1]) } @burst_pairs; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 18 | return join(" ", $header, @payload); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 55 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | =encoding utf8 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | Protocol::IR::Proto::SAMSUNG20 - SAMSUNG20 protocol handler (20-bit AC) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | =head1 VERSION | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | version 1.5 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | use Protocol::IR::Converter; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | my $converter = Protocol::IR::Converter->new(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | # From a raw 20-bit value or from parameters | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | my $code = $converter->import_code('SAMSUNG20', '0x27201'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | my $code = $converter->import_code('SAMSUNG20', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | { address => 1, subaddress => 8, command => 39 }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | The C<SAMSUNG20> protocol transmits 20-bit frames at B<38.4 kHz>: a 6-bit | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | B<device>, a 6-bit B<subdevice>, and an 8-bit B<function>, transmitted | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | LSB-first within each field behind a B<4512/4512 µs> header (the same header | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | Samsung's 32-bit protocol uses). The whole frame is sent once, so a capture | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | is header + 20 bits + stop. IRDB uses it for Samsung air-conditioner | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | handsets. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | The C<data> value matches Tasmota's C<DataLSB> field: the B<function> in | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | bits 12-19, B<subdevice> in bits 6-11, and B<device> in bits 0-5. There is no | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | display/accumulated byte-order distinction for a 20-bit word. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | A missing subdevice (C<-1>) sends a zero field per the IRP "Default S=0" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | rule; the stored C<subaddress> stays C<-1>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | =head1 METHODS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | =head2 decode_raw | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | my $code = $class->decode_raw('0x27201'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | Builds an L<Protocol::IR::Code> from the raw 20-bit value. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | =head2 decode_params | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | my $code = $class->decode_params(address => 1, subaddress => 8, command => 39); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | Builds an L<Protocol::IR::Code> from discrete parameters. Accepts C<address> or | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | C<device>, C<subaddress> or C<subdevice>, and C<command> or C<function>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | =head2 decode_timing | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | my $code = $class->decode_timing(\@burst_pairs_us); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | Decodes an arrayref of microsecond C<[mark_us, space_us]> pairs. Returns an | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | L<Protocol::IR::Code> when the header, 20 data bits, and stop bit match the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | SAMSUNG20 timing signature, otherwise C<undef>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | =head2 to_pronto | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | my $pronto = $class->to_pronto($ir_code); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | Encodes an L<Protocol::IR::Code> object as a Pronto Hex string at 38.4 kHz. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | =head1 SUPPORT | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | Source code: L<https://github.com/bwarden/perl-protocol-ir> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | Bug reports and feature requests: L<https://github.com/bwarden/perl-protocol-ir/issues> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | Brett T. Warden <bwarden@cpan.org> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | Copyright (c) 2026 Brett T. Warden | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | This library is free software; you can redistribute it and/or modify it | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | under the terms of the GNU General Public License as published by the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | Free Software Foundation; either version 2 of the License, or (at your | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | option) any later version. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||