The LIRC device interface is a bi-directional interface for transporting raw IR data between userspace and kernelspace. Fundamentally, it is just a chardev (/dev/lircX, for X = 0, 1, 2, ...), with a number of standard struct file_operations defined on it. With respect to transporting raw IR data to and fro, the essential fops are read, write and ioctl.
Example dmesg output upon a driver registering w/LIRC:
$ dmesg |grep lirc_dev lirc_dev: IR Remote Control driver registered, major 248 rc rc0: lirc_dev: driver ir-lirc-codec (mceusb) registered at minor = 0
What you should see for a chardev:
$ ls -l /dev/lirc* crw-rw---- 1 root root 248, 0 Jul 2 22:20 /dev/lirc0
5.2. LIRC modes¶
LIRC supports some modes of receiving and sending IR codes, as shown on the following table.
The driver returns a sequence of pulse and space codes to userspace, as a series of u32 values.
This mode is used only for IR receive.
The upper 8 bits determine the packet type, and the lower 24 bits the payload. Use
LIRC_VALUE()macro to get the payload, and the macro
LIRC_MODE2()will give you the type, which is one of:
LIRC_MODE2_PULSESignifies the presence of IR in microseconds.
LIRC_MODE2_SPACESignifies absence of IR in microseconds.
LIRC_MODE2_FREQUENCYIf measurement of the carrier frequency was enabled with ioctl LIRC_SET_MEASURE_CARRIER_MODE then this packet gives you the carrier frequency in Hertz.
This mode can be used for IR receive and send.
The IR signal is decoded internally by the receiver, or encoded by the transmitter. The LIRC interface represents the scancode as byte string, which might not be a u32, it can be any length. The value is entirely driver dependent. This mode is used by some older lirc drivers.
The length of each code depends on the driver, which can be retrieved with ioctl LIRC_GET_LENGTH. This length is used both for transmitting and receiving IR.
In pulse mode, a sequence of pulse/space integer values are written to the lirc device using LIRC write().
The values are alternating pulse and space lengths, in microseconds. The first and last entry must be a pulse, so there must be an odd number of entries.
This mode is used only for IR send.