IR-KEYTABLE without LIRC / LIRCD

  • Hi all,

    Since Kodibuntu is no longer supported by the Kodi developers, I have made the move to LibreELEC and I am very happy with it so far... Quick to install, fast boot, available options that should have been in Kodibuntu (network configuration tool!) and overall a very impressive experience.

    However, I am scratching my head when it comes to getting my remote control working. Previously in Kodibuntu, I would remove LIRC and rely on IR-KEYTABLE to deal with a bank of RC-5 commands from my Philips Pronto remote control. I had no issues with creating a keytable and configuring a "keyboard.xml" to map buttons to specific functions. Everything worked perfectly and whenever reinstalling, I could just drop my "pronto.cfg" (keytable) and "keyboard.xml" files in the relevant places, and it would just work.

    I assumed the same was possible with LibreELEC since it has IR-KEYTABLE built in, but I am unable to get it to work fully. I am well versed in IR-KEYTABLE; I can assign protocols, write keytables, test commands, load on boot, etc, but I have two problems:

    LIRCD interferes with IR-KEYTABLE

    My IR receiver is working perfectly but before IR-KEYTABLE will accept IR codes, I have to stop the LIRCD service with "systemctl stop eventlircd.service". No problem, just write an "autostart.sh" script to run this script on boot... Except it doesn't work!

    I have no use for LIRC / LIRCD since I am using the RC-5 IR codes to emulate a keyboard and as I understand it, only IR-KEYTABLE can emulate key presses. I have no interest in using LIRC / LIRCD so if it cannot be removed, can it be disabled on boot up?

    Specific Keys are not recognised by Kodi

    I have the "Guide" button on my Pronto mapped to an RC-5 IR code that prompts "KEY_C" in the keytable. After stopping LIRCD, "KEY_C" works when running "ir-keytable -t" and I can see the key is recognised by IR-KEYTABLE. However, Kodi does not react to this keypress! It should display the Context Menu, but nothing happens. I thought this could be an issue with my custom "keyboard.xml" so I deleted it, which reverts back to Kodi's defaults, and although pressing the "C" key on a USB keyboard works, "KEY_C" is not recognised!

    I have tested with a few other keys as well, most notably "KEY_P" and this doesn't work to play a video either, even though "P" on a USB-connected keyboard works fine. Interestingly, I mapped the same RC-5 IR code to "KEY_PLAY" instead of "KEY_P", and it now works in Kodi.

    This tells me that LIRC / LIRCD is interfering in the translation from IR-KEYTABLE to Kodi, and any keys it doesn't recognise, it just drops. What is the best way to completely disable LIRC / LIRCD so that I can just use IR-KEYTABLE? And also, where is the translation from IR-KEYTABLE names to Kodi commands done? There must be a file somewhere that takes the IR-KEYTABLE commands, translates to Kodi-recognised commands, and spits them out to Kodi.

    If you need any further information please let me know and I'll try to supply it. Thanks for any help you can give!

    EDIT: Here is an excerpt from my kodi.log. It looks like I was right; LIRC is intercepting IR signals and dropping those it doesn't understand!

    11:49:01.937 T:140430158071040 DEBUG: LIRC: Update - NEW at 71096:6c 0 KEY_DOWN devinput (KEY_DOWN)
    11:49:01.937 T:140430158071040 DEBUG: OnKey: 167 (0xa7, obc88) pressed, action is Down
    11:49:02.186 T:140430158071040 DEBUG: LIRC: Update - NEW at 71345:6c 0 KEY_DOWN_UP devinput (KEY_DOWN_UP)
    11:49:02.518 T:140430158071040 DEBUG: LIRC: Update - NEW at 71677:2e 0 KEY_C devinput (KEY_C)
    11:49:02.767 T:140430158071040 DEBUG: LIRC: Update - NEW at 71926:2e 0 KEY_C_UP devinput (KEY_C_UP)
    11:49:04.128 T:140430158071040 DEBUG: LIRC: Update - NEW at 73287:2e 0 KEY_C devinput (KEY_C)
    11:49:04.394 T:140430158071040 DEBUG: LIRC: Update - NEW at 73553:2e 0 KEY_C_UP devinput (KEY_C_UP)
    11:49:04.958 T:140430158071040 DEBUG: LIRC: Update - NEW at 74117:2e 0 KEY_C devinput (KEY_C)
    11:49:05.224 T:140430158071040 DEBUG: LIRC: Update - NEW at 74383:2e 0 KEY_C_UP devinput (KEY_C_UP)
    11:49:06.286 T:140430158071040 DEBUG: LIRC: Update - NEW at 75445:11 0 KEY_W devinput (KEY_W)
    11:49:06.552 T:140430158071040 DEBUG: LIRC: Update - NEW at 75711:11 0 KEY_W_UP devinput (KEY_W_UP)
    11:49:07.332 T:140430158071040 DEBUG: LIRC: Update - NEW at 76491:e 0 KEY_BACKSPACE devinput (KEY_BACKSPACE)

    Edited once, last by NinjaMonkeyUK (January 25, 2017 at 5:32 PM).

  • If you are using a GPIO IR receiver. You should only need to edit the /flash/config.txt so that dtoverlay=lirc-rpi is not commented out. Then un install lirc if you installed it. Then put your RC-5 lircd.conf in the /storage/.config directory.

    Forget about all of that old fashioned stuff.


  • If you are using a GPIO IR receiver. You should only need to edit the /flash/config.txt so that dtoverlay=lirc-rpi is not commented out. Then un install lirc if you installed it. Then put your RC-5 lircd.conf in the /storage/.config directory.

    Forget about all of that old fashioned stuff.

    I'm actually using a USB IR receiver on a vanilla install of the generic Intel / nVidia / AMD build of LibreELEC, on a Zotac ZBox, not a Raspberry Pi. Saying that, I have tested this on my Raspberry Pi and seen similar results.

    I have not installed LIRC. In fact that's the first thing I used to purge from my Kodibuntu installations to get IR-KEYTABLE set up and working. Your comment on uninstalling LIRC, then using lircd.conf seems contradictory; are LIRC and LIRCD completely separate entities?

    How do I uninstall / disable LIRC and LIRCD in LibreELEC? I cannot find any documentation that gives any hints how to do this.

    I'm not sure what you mean about "old fashioned stuff", as I was under the impression that the move from LIRC to in-kernal IR-KEYTABLE was a good thing and a move in the right direction, not a regression.

    I need to use IR-KEYTABLE independently so that I have access to the full array of 120+ keys that are available on a keyboard, rather than the limited set available in LIRC. This then enables me to create an on-screen keyboard on my remote which I can use to type in Kodi. This works and has done for years under Kodibuntu... It's just LibreELEC doesn't seem to want me to shut off LIRC / LIRCD!

    Interestingly, when I switch IR protocols in IR-KEYTABLE using "ir-keytable -p rc-5", IR-KEYTABLE reports that the enabled protocols are RC-5 and LIRC. On Kodibuntu, if I switch to RC-5 (or any other protocol), then that is the only one that becomes enabled. How come IR-KEYTABLE on LibreELEC essentially forces the LIRC protocol?


  • Try "systemctl stop eventlircd" rather than "systemctl stop eventlircd.service".

    Hi Troggy, thanks for the suggestion but unfortunately your command appears to be no different to the one I was using. It still behaves in the same way. :rolleyes:

    I'm convinced LIRC is the culprit, due to what I found in the kodi.log file (in my post above). However, if I try to stop LIRC with "systemctl stop lirc", I just get this error message:

    "Failed to stop lirc.service: Unit lirc.service not loaded."

    If LIRC isn't loaded, how can it be intercepting the keystrokes?

    It's interesting that I don't seem to be able to stop IR-KEYTABLE from using the LIRC protocol. In Kodibuntu, if I specify just the RC-5 protocol, that is the only one that becomes available. In LibreELEC, it doesn't work the same; no matter which protocol I specify, LIRC is always enabled as well! I believe this is the sticking point.

    Does anyone know how to get IR-KEYTABLE to force OFF the LIRC protocol in LibreELEC? :s

  • Just checked on my pc - either command ( systemctl stop eventlircd.service or systemctl stop eventlircd) seem to stop lirc as expected. That's on 17.0-BETA7, I should really try the latest.
    Log snippet:

  • I am using the very latest LibreELEC which is Kodi 17.0-RC3 Git 4d93228, compiled Jan 16 2017. I have literally just done a clean installation in the last 10 minutes. So far I have run this command (ignore the LibreLaptop name; I'm just using a laptop to test while at work):

    Code
    LibreLaptop:~ # ir-keytable
    Found /sys/class/rc/rc0/ (/dev/input/event11) with:
            Driver mceusb, table rc-rc6-mce
            Supported protocols: unknown other lirc rc-5 jvc sony nec sanyo mce-kbd rc-6 sharp xmp
            Enabled protocols: lirc nec rc-6
            Name: Media Center Ed. eHome Infrared
            bus: 3, vendor/product: 147a:e03e, version: 0x1001
            Repeat delay = 1000 ms, repeat period = 125 ms

    LIRC, NEC and RC-6 are clearly the only enabled protocols. Since I just need RC-5, I can run this command:

    Code
    ir-keytable -p rc-5
    Protocols changed to rc-5

    Now on Kodibuntu this command literally enables RC-5 and NOTHING else. But on LibreELEC, if I query IR-KEYTABLE now I get:

    Code
    LibreLaptop:~ # ir-keytable
    Found /sys/class/rc/rc0/ (/dev/input/event11) with:
            Driver mceusb, table rc-rc6-mce
            Supported protocols: unknown other lirc rc-5 jvc sony nec sanyo mce-kbd rc-6 sharp xmp
            Enabled protocols: lirc rc-5
            Name: Media Center Ed. eHome Infrared
            bus: 3, vendor/product: 147a:e03e, version: 0x1001
            Repeat delay = 1000 ms, repeat period = 125 ms
    LibreLaptop:~ #

    Clearly, LIRC is still being used and I think this is the reason why my IR keyboard commands are being dropped. If I check the Kodi log file, I can see key presses from the laptop's keyboard.

    At this point, since I haven't yet run "systemctl stop eventlircd.service", if I try to test for key presses in IR-KEYTABLE, it doesn't see anything. If I then run the command to stop the LIRCD service, I see this in the Kodi log:

    Code
    LibreLaptop:~ # ir-keytable
    Found /sys/class/rc/rc0/ (/dev/input/event11) with:
            Driver mceusb, table rc-rc6-mce
            Supported protocols: unknown other lirc rc-5 jvc sony nec sanyo mce-kbd rc-6 sharp xmp
            Enabled protocols: lirc rc-5
            Name: Media Center Ed. eHome Infrared
            bus: 3, vendor/product: 147a:e03e, version: 0x1001
            Repeat delay = 1000 ms, repeat period = 125 ms

    This is what makes me think LIRC and LIRCD are completely separate, and stopping the LIRC service (even though it says LIRC disconnected in Kodi's log) does not actually shut down LIRC. After this, IR-KEYTABLE starts responding to IR commands:

    Code
    LibreLaptop:~ # ir-keytable -t
    Testing events. Please, press CTRL-C to abort.
    1485446427.304544: event type EV_MSC(0x04): scancode = 0x1b46
    1485446427.304544: event type EV_SYN(0x00).
    1485446428.055559: event type EV_MSC(0x04): scancode = 0x1b46
    1485446428.055559: event type EV_SYN(0x00).
    1485446428.823524: event type EV_MSC(0x04): scancode = 0x1b47
    1485446428.823524: event type EV_SYN(0x00).
    1485446429.304563: event type EV_MSC(0x04): scancode = 0x1b47
    1485446429.304563: event type EV_SYN(0x00).

    Since I haven't created / loaded a keytable in this fresh install of LibreELEC, clearly the scancodes are not mapped to any key presses. I can quickly write a keytable for the most common commands (/storage/.kodi/userdata/keymaps/prontotest.cfg):

    Code
    #table pronto, type: rc-5
    
    
    0x1b46 KEY_UP
    0x1b47 KEY_DOWN
    0x1b48 KEY_LEFT
    0x1b49 KEY_RIGHT
    0x1b3a KEY_ENTER
    0x1b1a KEY_C
    0x1b5c KEY_BACKSPACE

    Now if I load this keytable into IR-KEYTABLE:

    Code
    LibreLaptop:~ # ir-keytable -c -w /storage/.kodi/userdata/keymaps/prontotest.cfg
    Read pronto table
    Old keytable cleared
    Wrote 7 keycode(s) to driver
    Protocols changed to rc-5

    The keys are successfully written to the table, and a test proves they work under IR-KEYTABLE:

    Here is where I am stuck. The above keys clearly work in IR-KEYTABLE and all except KEY_C are passed to Kodi without issue. I can navigate up, down, left and right through menus, select options, and return (KEY_BACKSPACE) to the previous menu. I just can't launch the Context Menu on KEY_C. Kodi logs the keys like this:

    As you can see, the KEY_C scancode is ignored by Kodi. I am convinced LIRC is the cause of this.

    I think LIRC is translating the navigation keys as they are a common standard, but since LIRC is not designed for use with keyboards, it doesn't know what KEY_C (or KEY_A, KEY_W, etc) is so it can't map it to a command that it understands, to then pass to Kodi... Therefor it just drops the command so Kodi doesn't see anything.

    There must be a way of completely disabling LIRC either at LibreELEC boot time or by issuing a command to IR-KEYTABLE to tell it not to listen to LIRC!

    Edited once, last by NinjaMonkeyUK (January 26, 2017 at 5:19 PM).

  • I do know for sure that lirc is included in the newer linux/Ubuntu kernel. I was slapped down a while ago when I tried to correct somebody about using sytemctl to stop and start lirc in libreelec, I know that is how in linux/Ubuntu, don't know about libreelec.

    Comparing LibreELEC with KodiUbuntu is pretty much a waste of time, you have to forget most of what you trial and errored and start anew.

    Ir-keytable is used to configure the seemingly invisible lirc.

    Lirc.org is a good place to find out how to make lirc work the way you want it to. However it is huge and filled with outdated and new information. I do remember seeing something about conflicts with the kernel when programming that I could not understand because it is way too "linux" for me.

    In windows some key strokes, like the green button, are defined by registry values, Makes me wonder about those odd ones in LibreELEC.

  • Yes I think LIRC is still part of the kernel but IR-KEYTABLE is being prepared to phase LIRC out...

    I realise comparing LibreELEC with Kodibuntu is a little like comparing oranges and apples, but there are similarities between them. Trouble is, I need IR-KEYTABLE rather than LIRC as it gives much more flexibility than LIRC. Essentially it allows me to use my remote as a keyboard, rather than just a remote.

    Still scratching my head!

    It seems other people are running into a similar issue whereby they don't have working return, Context Menu, etc, buttons, but the guides and hints to fix those all point to using LIRC. Surely somebody out there must be wanting to use IR-KEYTABLE like me!


  • lirc on LibreELEC works out of the box on 99% of devices with no extra configuration needed. Flirc you have to map all the key presses and is actually more work in the end.

    A couple of nice things about Flirc though.
    First is that you can use virtually any remote under the sun. I like using old DirecTV remotes. Got a bag of 5 of them for $2 at a local thrift store.

    Second, since your device sees it as a USB keyboard it works with anything running Kodi with zero config. Plug and play.

    Third, you only have to map a remote to it once. After that you can copy that config to other Flircs as needed.

    I get that $20 is a hit to the pocketbook, but for me it has been worth it. I've been using the same config for several years and never had to touch a LIRC config or remote.conf.


  • EDIT: Here is an excerpt from my kodi.log. It looks like I was right; LIRC is intercepting IR signals and dropping those it doesn't understand!

    11:49:02.518 T:140430158071040 DEBUG: LIRC: Update - NEW at 71677:2e 0 KEY_C devinput (KEY_C)
    11:49:02.767 T:140430158071040 DEBUG: LIRC: Update - NEW at 71926:2e 0 KEY_C_UP devinput (KEY_C_UP)



    You can map unknown lirc keys to kodi remote keys using Lircmap.xml.

    Code
    cp /usr/share/kodi/system/Lircmap.xml /storage/.kodi/userdata/

    Edit the devinput section (in your case), i.e.:

    Code
    ...
    <remote device="devinput">
    <menu>KEY_C</menu>
    ...

    See LIRC - Official Kodi Wiki


  • In the newest beta you can disable lirc from the LibreELEC settings add-on. You can't disable eventlircd though. You would have to override the udev rule for that.

    I don't know how I missed this!

    Anyway, I tried disabling it but it didn't seem to actually do anything...
    [hr]


    Once you get angry enough with all the lirc nonsense you'll get a Flirc and be done with it.

    That's the thing though... Flirc costs about £20 in the UK and I shouldn't even need it as this should be possible in-kernel... If Flirc can translate my IR codes into usable Kodi commands, then there is no reason why it cannot be done in-kernel.
    [hr]


    You can map unknown lirc keys to kodi remote keys using Lircmap.xml.

    Code
    cp /usr/share/kodi/system/Lircmap.xml /storage/.kodi/userdata/

    Edit the devinput section (in your case), i.e.:

    Code
    ...
    <remote device="devinput">
    <menu>KEY_C</menu>
    ...

    See LIRC - Official Kodi Wiki

    Thanks, but I think you're missing the point of my post. IR-KEYTABLE can process key presses from an IR keyboard. As far as I am aware, LIRC is not capable of this and is ONLY for IR remote control commands.

    I don't want to map "KEY_C" to <menu> because I want to map it to "C" so that it emulates pressing the "C" key on an actual keyboard. This way, I can have an on-screen keyboard on my Pronto's screen that I can use to type directly into Kodi. I know this is possible because I use it this way with Kodibuntu!

    My point is, LIRC / LIRCD is handling these "KEY_C", "KEY_A", etc events and since it doesn't recognise them, it drops them, so Kodi doesn't ever receive them. I want to fully disable LIRC / LIRCD so that only IR-KEYTABLE processes the IR transmissions. This will allow it to translate the IR codes to actual keyboard keys. LIRC is only working to map remote control keys and ignores the rest.

    I shouldn't need to edit lircmap.xml because I have no use for it. There must be a way to permanently disable LIRC / LIRCD so that only IR-KEYTABLE processes IR commands in-kernel.

    Edited once, last by NinjaMonkeyUK (January 28, 2017 at 12:32 PM).

  • Do not know if it helps but you can disable the udev lirc rules with

    Code
    : >/storage/.config/udev.rules.d/98-lircd.rules

    and/or mask the lirc systemd units with

    Code
    : > /storage/.config/system.d/[email protected]
    : > /storage/.config/system.d/[email protected]

    and reboot

    I'm not too sure what any of that means but I did find the following code from the OpenELEC forums:

    Code
    ln -sf /dev/null /storage/.config/system.d/eventlircd.service
    sync && reboot

    This fixes my issue after the reboot! All keys on the IR keyboard (remote) start working again. However, once I reboot for a second time, it stops working again. It looks to me like the above code creates a symbolic link from /dev/null to the LIRCD service which basically stops LIRCD from working completely. This is fine as it allows IR-KEYTABLE to work but I cannot figure out how this code should be implemented to work on every boot! :(

    At least I'm getting somewhere now and I know this is possible in LibreELEC.

    Edited once, last by NinjaMonkeyUK (January 29, 2017 at 6:27 PM).


  • If you are using a GPIO IR receiver. You should only need to edit the /flash/config.txt so that dtoverlay=lirc-rpi is not commented out. Then un install lirc if you installed it. Then put your RC-5 lircd.conf in the /storage/.config directory.

    Forget about all of that old fashioned stuff.

    I'm using GPIO IR receiver for recording IR remote buttons but I am facing inconsistency to record and execute remote key using LIRC. My question is if we can use remote key operation in my code via IR keytable approach, if yes kindly help and provide steps to perform same.

    Referring approach mentioned here