ir

package
v0.714.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 19, 2026 License: AGPL-3.0 Imports: 4 Imported by: 0

Documentation

Overview

Package ir decodes raw infrared remote-control timing captures into the protocol + address/command — the IR analogue of the Sub-GHz protocol decoders, and the complement to the file-level ir_decode_file (which only reads a .ir file's already-parsed entries).

Wrap-vs-native judgement

Native. Consumer-IR protocols are public, fully-deterministic pulse-distance encodings documented for decades (NEC by NEC/Renesas, reproduced in LIRC, the Flipper IR stack, and Arduino-IRremote). Decoding is a leader-match plus a per-bit mark/space classifier over the captured microsecond timings the operator already has (ir_receive raw, a Flipper RAW .ir entry, or a logic-analyser capture) — no IR hardware at decode time.

Verifiable / no confidently-wrong output

NEC carries a built-in checksum: the 8-bit address is followed by its bitwise inverse and the 8-bit command by its inverse. A standard NEC frame is reported only when BOTH inversions hold; when only the command inversion holds it is reported as NEC-extended (16-bit address, no address inversion); when neither holds the raw 4 bytes are surfaced with a note rather than a guessed address/command. The leader and every bit are tolerance-matched, so a non-NEC pulse train is rejected, not mis-decoded.

Covered / deferred

The NEC family (standard, extended, NEC42 / NEC42ext, and the repeat code), Sony SIRC (12 / 15 / 20-bit), Samsung, Philips RC5 / RC5X (14-bit Manchester), Kaseikyo (the 48-bit pulse-distance frame shared by Panasonic / Denon / JVC / Sharp / Mitsubishi), and RCA (24-bit pulse-distance, 4-bit address + 8-bit command, distinct 4000µs leader) are covered — the most common consumer-IR protocols across the three encoding families (pulse-distance, pulse-width, and bi-phase). NEC is gated by its address/command inverse-byte checksum, RCA by its 4-bit/8-bit inverse-field checksums; Kaseikyo by BOTH its 4-bit vendor parity and its 8-bit frame parity; the checksum-less protocols are gated structurally instead — SIRC by its 2400µs leader + exact 12/15/20-bit count, and RC5 by an exact 28-half-bit Manchester reconstruction with a valid S1 start bit (a polarity-inverted or non-RC5 train fails the bit-pair or S1 gate and is rejected, not mis-decoded). RC6 (a more complex Manchester variant with a double-width toggle) and the Pronto/`ir_build` parsed formats are deliberately not decoded here yet.

Index

Constants

This section is empty.

Variables

View Source
var EncodeProtocols = []string{
	"NEC", "NEC-extended", "NEC-repeat", "Samsung32",
	"SIRC", "RC5", "Kaseikyo", "RCA", "NEC42",
}

EncodeProtocols lists every protocol EncodeRaw accepts, by canonical name, in one place so the error message and tool docs cannot drift from the switch below as protocols are added (TestEncodeRawSupportedList guards that every listed name is actually dispatched).

Functions

func EncodePronto added in v0.615.0

func EncodePronto(timings string, carrierHz int) (string, error)

EncodePronto is the inverse of DecodePronto: it converts a raw IR timing sequence (space/comma-separated microsecond mark/space durations) and a carrier frequency into a raw-oscillated (format 0x0000) Pronto HEX code with no repeat sequence. It round-trips with DecodePronto (decode of the emitted code reproduces the input timings within carrier-period rounding).

func EncodeRaw added in v0.621.0

func EncodeRaw(protocol string, address, command int, opt EncodeOptions) (string, error)

EncodeRaw generates the raw IR timing sequence (space-separated microsecond mark/space durations) for a consumer-IR frame — the inverse of DecodeRaw. The emitted timings round-trip through DecodeRaw to the same protocol + address + command. It is the offline complement to the device-side ir_build, and the timings can be fed to EncodePronto to produce a shareable Pronto code.

Supported (EncodeProtocols): NEC (8-bit address + command, both inverse-byte checksums emitted), NEC-extended (16-bit address, command inversion only), the NEC-repeat code, Samsung32 (address·address·command·~command), Sony SIRC (12/15/20-bit), Philips RC5 / RC5X (14-bit Manchester; a command > 63 emits an RC5X frame), Kaseikyo (Panasonic/Denon/JVC/Sharp/Mitsubishi — 48-bit, vendor via opt.Vendor, both the vendor parity and the frame parity computed), RCA (24-bit; 4-bit address + 8-bit command, both inverse fields emitted), and NEC42 (42-bit; 13-bit address + 8-bit command, both inverse fields emitted).

Types

type EncodeOptions added in v0.621.0

type EncodeOptions struct {
	SIRCBits int // 12 (default), 15 or 20 — Sony SIRC frame width
	Toggle   int // 0/1 — RC5 toggle bit
	Ext      int // SIRC 20-bit extension byte
	Vendor   int // Kaseikyo 16-bit vendor ID (default 0x2002 Panasonic)
}

EncodeOptions carries the per-protocol extras EncodeRaw needs beyond the address/command: the Sony SIRC frame width, the RC5 toggle bit, and the SIRC 20-bit extension.

type ProntoResult added in v0.614.0

type ProntoResult struct {
	Format        string   `json:"format"`
	FormatWord    string   `json:"format_word"`
	CarrierHz     int      `json:"carrier_hz,omitempty"`
	IntroPairs    int      `json:"intro_pairs"`
	RepeatPairs   int      `json:"repeat_pairs"`
	IntroTimings  []int    `json:"intro_timings_us"`
	RepeatTimings []int    `json:"repeat_timings_us,omitempty"`
	Protocol      *Result  `json:"protocol,omitempty"`
	Notes         []string `json:"notes,omitempty"`
}

ProntoResult is the decoded view of a Pronto HEX IR code.

func DecodePronto added in v0.614.0

func DecodePronto(input string) (*ProntoResult, error)

DecodePronto parses a Pronto HEX code (space-separated 4-hex-digit words; a '0x' prefix and ':'/'-' separators tolerated) into carrier + timings.

type Result

type Result struct {
	Protocol      string   `json:"protocol"`
	Address       int      `json:"address"`
	AddressHex    string   `json:"address_hex"`
	Command       int      `json:"command"`
	CommandHex    string   `json:"command_hex"`
	Bits          int      `json:"bits"`
	ChecksumValid bool     `json:"checksum_valid"`
	Vendor        int      `json:"vendor,omitempty"`
	VendorHex     string   `json:"vendor_hex,omitempty"`
	VendorName    string   `json:"vendor_name,omitempty"`
	RawBytesHex   string   `json:"raw_bytes_hex,omitempty"`
	Notes         []string `json:"notes,omitempty"`
}

Result is the decoded view of a raw IR capture.

func DecodeRaw

func DecodeRaw(timings string) (*Result, error)

DecodeRaw parses a space-separated list of microsecond timings (the alternating mark/space durations from a raw IR capture) and decodes the NEC-family frame it carries.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL