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, and the repeat code), Sony SIRC (12 / 15 / 20-bit), Samsung, Philips RC5 / RC5X (14-bit Manchester), and Kaseikyo (the 48-bit pulse-distance frame shared by Panasonic / Denon / JVC / Sharp / Mitsubishi) 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; 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 ¶
This section is empty.
Functions ¶
func EncodePronto ¶ added in v0.615.0
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: 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), and Kaseikyo (Panasonic/Denon/JVC/Sharp/Mitsubishi — 48-bit, vendor via opt.Vendor, both the vendor parity and the frame parity computed).
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.