| 1 | package Protocol::IR::Proto::NECX2; | ||
| 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 parent 'Protocol::IR::Proto::NEC'; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 8 | |||
| 9 | # NECx2 is the MakeHex NECx2.irp protocol: a 16-bit address with a half | ||
| 10 | # (4500/4500 µs) header, repeating the entire frame. Single-frame timing | ||
| 11 | # is identical to NECx1; only the protocol name differs. | ||
| 12 | 33 | ▶ | sub _protocol_name { 'NECX2' } |
|
Subroutine
_protocol_name: called CC=1 SCAR=0.0
| |||
| 13 | 86 | ▶ | sub _half_header { 1 } |
|
Subroutine
_half_header: called CC=1 SCAR=0.0
| |||
| 14 | 1 | ▶ | sub _inverted_subaddress_default { 0 } |
|
Subroutine
_inverted_subaddress_default: called CC=1 SCAR=0.0
| |||
| 15 | 1 | ▶ | sub _normalize_subaddress { 0 } |
|
Subroutine
_normalize_subaddress: called CC=1 SCAR=0.0
| |||
| 16 | |||
| 17 | 55 | ▶ | use Protocol::IR::Code; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 18 | |||
| 19 | # Convert a NECX2 code to its SAMSUNG equivalent parameters. | ||
| 20 | # NECx2 device/subdevice are the bit-reversal of the Samsung address, | ||
| 21 | # and the NECx2 function is the bit-reversal of the Samsung command. | ||
| 22 | # Returns a hashref suitable for import_code('SAMSUNG', \%params). | ||
| 23 | 4 | ▶ | sub as_samsung_params { |
|
Subroutine
as_samsung_params: called CC=1 SCAR=0.0
Pod
documented
| |||
| 24 | 4 | my ($self, $code) = @_; | |
| 25 | 4 | my $addr = Protocol::IR::Code::reverse_byte($code->address & 0xFF); | |
| 26 | 4 | my $cmd = Protocol::IR::Code::reverse_byte($code->command & 0xFF); | |
| 27 | return { | ||
| 28 | 4 | address => $addr, | |
| 29 | command => $cmd, | ||
| 30 | }; | ||
| 31 | } | ||
| 32 | |||
| 33 | 55 | 1; | |
| 34 | |||
| 35 | =encoding utf8 | ||
| 36 | |||
| 37 | =head1 NAME | ||
| 38 | |||
| 39 | Protocol::IR::Proto::NECX2 - NECx2 protocol handler (extended NEC, whole-frame repeat) | ||
| 40 | |||
| 41 | =head1 VERSION | ||
| 42 | |||
| 43 | version 1.5 | ||
| 44 | |||
| 45 | =head1 SYNOPSIS | ||
| 46 | |||
| 47 | use Protocol::IR::Converter; | ||
| 48 | |||
| 49 | my $converter = Protocol::IR::Converter->new(); | ||
| 50 | |||
| 51 | # NECx2 is the framing used by Samsung TVs: half 4500/4500 µs header | ||
| 52 | # and a real 16-bit address (device + subdevice bytes). | ||
| 53 | my $code = $converter->import_code('NECX2', | ||
| 54 | { device => 7, subdevice => 7, command => 2 }); | ||
| 55 | |||
| 56 | =head1 DESCRIPTION | ||
| 57 | |||
| 58 | The NECx2 protocol (MakeHex F<NECx2.irp>) transmits the same frame as | ||
| 59 | L<Protocol::IR::Proto::NECX1> -- half B<4500/4500 µs> header, 16-bit address | ||
| 60 | (Default S=D) -- but repeats the B<entire> frame instead of a short | ||
| 61 | header+gap ditto. For a single frame the two are timing-identical, so this | ||
| 62 | class only changes the protocol name. Samsung TV IRDB files (for example) | ||
| 63 | label their codes C<NECx2>; a Samsung POWER row of device 7, subdevice 7, | ||
| 64 | function 2 packs to C<0x070702FD>, which matches the output of a reference | ||
| 65 | MakeHex build. | ||
| 66 | |||
| 67 | Like C<NECx1>, a single C<NECx2> frame cannot be told apart from | ||
| 68 | L<Protocol::IR::Proto::SAMSUNG> by timing alone; see L<Protocol::IR::Proto::NECX1> for | ||
| 69 | how L<Protocol::IR::Converter> resolves that. The name is preserved on the | ||
| 70 | by-name (CSV) import path. | ||
| 71 | |||
| 72 | =head1 METHODS | ||
| 73 | |||
| 74 | All methods are inherited from L<Protocol::IR::Proto::NEC>; only the protocol | ||
| 75 | name, header, and subaddress behavior differ, plus the following additional | ||
| 76 | method: | ||
| 77 | |||
| 78 | =head2 as_samsung_params | ||
| 79 | |||
| 80 | my $params = $class->as_samsung_params($code); | ||
| 81 | |||
| 82 | Converts a NECX2 code to its L<Protocol::IR::Proto::SAMSUNG> equivalent | ||
| 83 | parameter hashref. The NECX2 device byte is bit-reversed to produce the | ||
| 84 | Samsung address, and the function byte is bit-reversed to produce the | ||
| 85 | Samsung command. | ||
| 86 | |||
| 87 | The returned hashref is suitable for | ||
| 88 | C<< $converter->import_code('SAMSUNG', $params) >>. | ||
| 89 | |||
| 90 | Example: | ||
| 91 | |||
| 92 | # NECX2 Samsung TV POWER: device=7, function=2 | ||
| 93 | # -> SAMSUNG address=0xE0, command=0x40 | ||
| 94 | my $sam_params = Protocol::IR::Proto::NECX2->as_samsung_params($code); | ||
| 95 | |||
| 96 | This is used by L<Protocol::IR::Converter/cross_protocol> and is also | ||
| 97 | available for direct use when matching captures against IRDB entries. | ||
| 98 | |||
| 99 | =head1 CROSS-PROTOCOL MAPPING | ||
| 100 | |||
| 101 | NECX2 shares identical timing with L<Protocol::IR::Proto::SAMSUNG>: both use | ||
| 102 | a B<4500/4500 µs> half header, B<560/1680 µs> bit timing, 32 bits, per-byte | ||
| 103 | LSB-first. They are distinguished only by the byte structure on the wire: | ||
| 104 | Samsung repeats the address byte and follows the command with its one's | ||
| 105 | complement (C<addr, addr, cmd, ~cmd>), while NECX2 carries a real subaddress | ||
| 106 | byte (C<device, subdevice, function, ~function>). | ||
| 107 | |||
| 108 | When a Samsung TV code is stored in IRDB as NECX2 (the common convention), | ||
| 109 | the Samsung address is the bit-reversal of the NECX2 device byte, and the | ||
| 110 | Samsung command is the bit-reversal of the function byte. For example, | ||
| 111 | Samsung TV POWER is IRDB entry C<NECx2,7,7,2>: device 7 bit-reverses to | ||
| 112 | address 0xE0, function 2 bit-reverses to command 0x40. | ||
| 113 | |||
| 114 | Use L<Protocol::IR::Converter/cross_protocol> to convert between the two | ||
| 115 | automatically, or call C<as_samsung_params> directly. | ||
| 116 | |||
| 117 | =head1 SUPPORT | ||
| 118 | |||
| 119 | Source code: L<https://github.com/bwarden/perl-protocol-ir> | ||
| 120 | |||
| 121 | Bug reports and feature requests: L<https://github.com/bwarden/perl-protocol-ir/issues> | ||
| 122 | |||
| 123 | =head1 AUTHOR | ||
| 124 | |||
| 125 | Brett T. Warden <bwarden@cpan.org> | ||
| 126 | |||
| 127 | =head1 COPYRIGHT AND LICENSE | ||
| 128 | |||
| 129 | Copyright (c) 2026 Brett T. Warden | ||
| 130 | |||
| 131 | This library is free software; you can redistribute it and/or modify it | ||
| 132 | under the terms of the GNU General Public License as published by the | ||
| 133 | Free Software Foundation; either version 2 of the License, or (at your | ||
| 134 | option) any later version. | ||