NAME

Protocol::IR::Proto::SAMSUNG - SAMSUNG protocol handler (32-bit)

VERSION

version 1.0

SYNOPSIS

use Protocol::IR::Converter;

my $converter = Protocol::IR::Converter->new();

# From a raw value (MSB display form) or from parameters
my $code = $converter->import_code('SAMSUNG', '0xE0E09966');
my $code = $converter->import_code('SAMSUNG',
    { address => 0xE0, command => 0x99 });

DESCRIPTION

The SAMSUNG protocol transmits a 32-bit frame at 38 kHz: a customer (address) byte, its one's complement, a command byte, and the command's one's complement. The 32-bit value is transmitted with the most significant byte first and each byte LSB-first within, so the value collected from a capture (and stored in data) matches Tasmota's DataLSB field; the data value exposed for a raw import is the MSB display form (Tasmota's Data field). The customer and command bytes are bit-reversed on the wire relative to their logical values. SAMSUNG has no subaddress; subaddress is set to -1.

Frame timing: 4480 us header mark and 4480 us header space; each bit is a 560 us mark followed by a space of 560 us for 0 or 1680 us for 1; a 560 us stop mark ends the frame.

Timing and bit ordering follow IRremoteESP8266 (David Conran et al., GPLv2, https://github.com/crankyoldgit/IRremoteESP8266): kSamsungHdrMark/ kSamsungHdrSpace = 8 * 560 us, kSamsungBitMark = 560 us, kSamsungOneSpace = 3 * 560 us, kSamsungZeroSpace = 560 us, 32 bits.

METHODS

decode_raw

my $code = $class->decode_raw('0xE0E09966');

Builds an Protocol::IR::Code from the raw 32-bit value.

decode_byte_order

my $code = $class->decode_byte_order($raw, $lsb);

Decodes from either byte order: $lsb true reads the accumulated (DataLSB) form; false reads the display (Data) form, and reverses the bytes to reach it. Samsung is the opposite of NEC's polarity: decode_raw reads the display form directly (its data field carries the accumulated word), so $lsb false needs no reversal and true reverses once.

lsb_is_accumulated

my $flag = $class->lsb_is_accumulated;

True (always, for SAMSUNG) when the accumulated byte order is what decode_raw reads, informing the Tasmota structured importer which of its Data/DataLSB fields to prefer.

decode_params

my $code = $class->decode_params(address => 0xE0, command => 0x99);

Builds an Protocol::IR::Code from discrete parameters. Accepts address or device, and command or function.

decode_timing

my $code = $class->decode_timing(\@burst_pairs_us);

Decodes an arrayref of microsecond [mark_us, space_us] pairs. Returns an Protocol::IR::Code when the header, 32 data bits, and stop bit match the SAMSUNG timing signature, otherwise undef.

to_pronto

my $pronto = $class->to_pronto($ir_code);

Encodes an Protocol::IR::Code object as a Pronto Hex string at 38 kHz.

as_necx2_params

my $params = $class->as_necx2_params($code);

Converts a SAMSUNG code to its Protocol::IR::Proto::NECX2 equivalent parameter hashref. The Samsung address and command are bit-reversed to produce the NECX2 device and function values respectively. The subaddress is set equal to the device (Samsung's address-repeated convention mapped to NECX2's Default S=D).

The returned hashref is suitable for $converter->import_code('NECX2', $params).

Example:

# Samsung TV POWER: address=0xE0, command=0x40
#   -> NECX2 device=7, subdevice=7, function=2
my $necx2_params = Protocol::IR::Proto::SAMSUNG->as_necx2_params($code);

This is used by "cross_protocol" in Protocol::IR::Converter and is also available for direct use when building IRDB lookup tables.

CROSS-PROTOCOL MAPPING

The SAMSUNG protocol shares identical timing with Protocol::IR::Proto::NECX2: both use a 4500/4500 us half header, 560/1680 us bit timing, 32 bits, per-byte LSB-first. The two protocols differ only in field naming:

SAMSUNG sends addr, addr, cmd, ~cmd on the wire.
NECX2 sends device, subdevice, function, ~function.

Because Samsung's address byte is repeated while NECX2 carries a real subaddress byte, the two cannot always be converted. However, when the NECX2 subaddress equals the device byte (the common case for Samsung TV codes in IRDB), the Samsung address is the bit-reversal of the NECX2 device byte, and likewise for the command/function byte.

IRDB labels its Samsung TV entries as NECX2 with the Samsung address and command values in the device and function columns (e.g. Samsung TV POWER is NECx2,7,7,2: device 7 is the bit-reversal of address 0xE0, function 2 is the bit-reversal of command 0x40).

Use "cross_protocol" in Protocol::IR::Converter to convert between the two automatically, or call as_necx2_params directly for IRDB lookups.

SUPPORT

Source code: https://github.com/bwarden/perl-protocol-ir

Bug reports and feature requests: https://github.com/bwarden/perl-protocol-ir/issues

AUTHOR

Brett T. Warden <bwarden@cpan.org>

COPYRIGHT AND LICENSE

Copyright (c) 2026 Brett T. Warden

This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License version 2.1 as published by the Free Software Foundation.