NAME
Protocol::IR::Format::Mode2 - LIRC mode2 pulse/space capture import and export
VERSION
version 1.0
SYNOPSIS
use Protocol::IR::Converter;
my $converter = Protocol::IR::Converter->new();
# Import a mode2 capture (pulse/space lines, one timing per line)
my $capture = "pulse 4514\nspace 4514\npulse 549\nspace 1708\n...";
my $codes = $converter->import_format('Mode2', $capture);
# Re-export a code as mode2 lines
my $text = $converter->export_code($codes->[0], 'Mode2');
DESCRIPTION
Protocol::IR::Format::Mode2 imports and exports the pulse/space capture format of the LIRC mode2 tool (and the MQTT IR test rig's receiver topic): one timing per line, pulse N or space N, in microseconds, strictly alternating.
decode reads a whole capture, splits it into messages on spaces of 10000 us or more (lirc's default inter-message gap, keeping the separator in the message that precedes it), decodes each message through every registered protocol decoder, and returns one Protocol::IR::Code per message. Every code keeps its raw timings so a re-export is lossless. Messages with no mark at all (dead air between two separators) are dropped; signals no protocol recognizes are kept with protocol UNKNOWN rather than discarded, because a capture is a record of what was on the air. Codes that decode to a known protocol get their alias set to the signal's Data hex value.
export writes one message per code as alternating pulse/space lines, ensuring each message ends on a space wide enough (100000 us, or its existing trailing space when already >= 10000 us) that re-importing the output splits messages back at the same boundaries. When a code carries no raw timings (e.g. one built with import_code), they are derived by round-tripping the code through the protocol encoder's Pronto output, so the emitted timings match the other timing formats exactly.
METHODS
decode
my $codes = $class->decode($input, $registry);
Parses a mode2 capture (a string, or an arrayref of lines) into a list of Protocol::IR::Code objects, one per message. Dies on empty input with no timings.
export
my $text = $class->export($ir_code, $registry);
Serializes one Protocol::IR::Code, or an arrayref of them, into mode2 pulse/space lines.
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.