5 releases
| 0.1.4 | Mar 20, 2025 |
|---|---|
| 0.1.3 | Apr 28, 2024 |
| 0.1.2 | Feb 7, 2023 |
| 0.1.1 | Dec 10, 2022 |
| 0.1.0 | May 21, 2022 |
#156 in Unix APIs
368 downloads per month
Used in brickbeam
300KB
7.5K
SLoC
ir-ctl - a new implementation of linux infrared tools
For Linux, there are tools for infrared: ir-ctl and ir-keytable. These
tools can load simple infrared keymaps and load decoders, and transmit simple
IR. The IR decoders and encoders are hardcoded.
There is also the lirc daemon and its tools, which supports many more IR
protocols but certainly not all.
This tool replaces all those tools, but with major new features:
- Pronto hex codes
- IRP support
- lircd.conf remote definition support
- daemon-less (using BPF)
Pronto hex codes are a fairly straightforward way of encoding raw IR, NEC, RC-5 and a few others.
IRP Notation is a DSL language which can express any IR protocol. We can parse IRP and compile a decoder to BPF using LLVM. So, any protocol can be supported directly.
List devices (ir-ctl list)
This gives you a list of infrared and CEC devices on your Linux system. It is
the ir-ctl equivalent of both ir-keytable with no arguments combined with
the lirc features from the old ir-ctl -f.
ir-ctl list
This gives you a list of the all the rc devices on the system.
rc0:
Device Name : Media Center Ed. eHome Infrared Remote Transceiver (1784:0008)
Driver : mceusb
Default Keymap : rc-rc6-mce
Input Device : /dev/input/event12
Input properties : Permission denied (os error 13)
LIRC Device : /dev/lirc0
LIRC Features : Permission denied (os error 13)
Supported Protocols : rc-5 nec rc-6 jvc sony rc-5-sz sanyo sharp mce_kbd xmp imon rc-mm
Enabled Protocols : rc-6
Not all information is available, unless you run it as root.
rc0:
Device Name : Media Center Ed. eHome Infrared Remote Transceiver (1784:0008)
Driver : mceusb
Default Keymap : rc-rc6-mce
Input Device : /dev/input/event10
Bus : USB
Vendor/product : 1784:0008 version 0x0101
Repeat : delay 500 ms, period 125 ms
LIRC Device : /dev/lirc0
LIRC Receiver : raw receiver
LIRC Resolution : 50 microseconds
LIRC Timeout : 125000 microseconds
LIRC Timeout Range : 50 to 1250000 microseconds
LIRC Wideband Receiver : yes
LIRC Measure Carrier : yes
LIRC Transmitter : yes
LIRC Set Tx Carrier : yes
LIRC Set Tx Duty Cycle : no
LIRC Transmitters : 2
BPF protocols :
Supported Protocols : rc-5 nec rc-6 jvc sony rc-5-sz sanyo sharp mce_kbd xmp imon rc-mm
Enabled Protocols :
Transmit/Send (ir-ctl transmit)
If you have a .lircd.conf file or .toml keymap, you can transmit with the following
command:
ir-ctl transmit --keymap RM-Y173.lircd.conf --keycode KEY_CHANNELUP
Alternatively, you can send raw IR directly like so:
ir-ctl transmit --raw '+9000 -4500 +560'
You can also send files or linux kernel scancodes, using the same options like ir-ctl. This supports
mode2 files or raw IR files.
ir-ctl transmit -f input-file -S nec:0xcafe
You can send pronto codes:
ir-ctl transmit --pronto '5000 0073 0000 0001 0001 0001'
Lastly you use IRP notation and set the parameters. This is great for experimenting with IRP; use the --dry-run (-n)
to avoid sending.
ir-ctl transmit -n -a F=2 --irp '{40k,600}<1,-1|2,-1>(4,-1,F:8,^45m)[F:0..255]'
This will give the following output:
info: carrier: 40000Hz
info: rawir: +2400 -600 +600 -600 +1200 -600 +600 -600 +600 -600 +600 -600 +600 -600 +600 -600 +600 -32400
Decoding (ir-ctl decode)
Use this if have a .lircd.conf file or .toml keymap, and want to decode the IR. This does not change
any configation.
ir-ctl decode --keymap foo.lircd.conf
This will infrared from the first lirc device. You can also decode IR on the command line or a file.
ir-ctl decode --keymap foo.lircd.conf -r '+9000 -4500 +560'
or
ir-ctl decode --keymap foo.lircd.conf -f input-file
If you wish to decode using IRP Notation that is possible too:
ir-ctl decode --irp '{40k,600}<1,-1|2,-1>(4,-1,F:8,^45m)[F:0..255]'
Like above the input can be from a lirc device (optionally specify the device with
-d /dev/lirc1 or -s rc), on the command line (-r '+100 -200 +100') or a file (-f filename).
Loading of keymaps
This is the ir-ctl equivalent of ir-keytable -w, however ir-ctl can not just load keymaps, it can
also load .lircd.conf files.
ir-ctl keymap -s rc0 foo.lircd.conf
This will generate a BPF decoder for foo.lircd.conf and load it.
On startup, ir-keytable -a -s rc0 read the correct keymap from /etc/rc_maps.cfg.
ir-ctl keymap -s rc0
Setting the auto-repeat parameters.
ir-ctl keymap -P 125 -D 500
Test configuration (ir-ctl test)
This is the ir-ctl equivalent of ir-keytable -t
ir-ctl test
Status
All the functionality is in place to load keymaps. More tests are needed, and more polish. The aim is to have this done by the end of 2024.
Building
On Linux, ir-ctl depends on llvm for BPF code generation. On Fedora you can install the dependencies (apart from rust) with:
sudo dnf install libstdc++-devel libstdc++-static libffi-devel llvm-devel
For Ubuntu:
sudo apt-get install llvm-dev g++
Once you have all the dependencies installed, you can build ir-ctl like so:
cargo install --git https://gitlab.freedesktop.org/linux-media/tools/cir ir-ctl
Tests
- The IRP encoder and decoder is compared against IrpTransmogrifier with a large set of inputs.
- The parsing, encoding and decoding of lircd.conf files is compared against lirc (see liblircd)
- The encoding of linux protocols is compared against ir-ctl (see libirctl)
- There are many more tests
Dependencies
~4–18MB
~220K SLoC