Monday, November 17, 2014

HOWTO: Get MCE USB remote working in Ubuntu without using LIRC for MythTV or Kodi (xbmc)




Some MCE USB remotes don’t work with in-kernel LIRC. Many people have reported problems with USB3 ports + xhci. 

This approach uses ir-keytable and remaps some MCE remote keys to emulate keyboard key-presses and works natively with applications like MythTV and Kodi (xbmc).


Tested on Ubuntu 14.04 (3.13.x kernel) and 14.10 (3.16.x kernel)
Using “ehome” MCE USB remote IR transceiver (Formosa Infrared Receiver)
Works on USB3 ports with no changes to the BIOS to disable xhci.


# Remove LIRC from your system
% sudo apt-get purge lirc


# If the /etc/lirc folder exists on your system, remove that as well
% sudo rm -rf /etc/lirc


# Install ir-keytable
% sudo apt-get install ir-keytable


# Find the device/eventID for your remote
% ir-keytable
You’ll get an output that looks like this:
Found /sys/class/rc/rc1/ (/dev/input/event10) with:
Driver mceusb, table rc-rc6-mce
Supported protocols: NEC RC-5 RC-6 JVC SONY SANYO LIRC other
Enabled protocols: NEC RC-5 RC-6 JVC SONY SANYO LIRC other
Name: Media Center Ed. eHome Infrared
bus: 3, vendor/product: 147a:e03e, version: 0x1001
Repeat delay = 500 ms, repeat period = 125 ms


# Test the remote keypresses using the eventID from the previous step.  This is similar to using “irw” with lirc.  The output shown below is generated for pressing the “OK” key once on the remote.
% sudo ir-keytable --test --device=/dev/input/event10
You should get an output that looks like the one below.  
1416166547.998594: event type EV_MSC(0x04): scancode = 0x800f0422
1416166547.998594: event type EV_KEY(0x01) key_down: KEY_OK(0x0001)
1416166547.998594: event type EV_SYN(0x00).
1416166548.104565: event type EV_MSC(0x04): scancode = 0x800f0422
1416166548.104565: event type EV_SYN(0x00).
1416166548.353099: event type EV_KEY(0x01) key_up: KEY_OK(0x0001)
1416166548.353099: event type EV_SYN(0x00).


# Generate the keymap for your remote and save the file under /etc/rc_keymaps/.  Call it myrc6_mce.  This will give you the scancodes and hexcodes for all the keys supported by your mceusb remote.
% sudo ir-keytable --read --device=/dev/input/event10 > /etc/rc_keymaps/myrc6_mce


A sample output is below:
scancode 0x800f0400 = KEY_NUMERIC_0 (0x200)
scancode 0x800f0401 = KEY_NUMERIC_1 (0x201)
scancode 0x800f0402 = KEY_NUMERIC_2 (0x202)
scancode 0x800f0403 = KEY_NUMERIC_3 (0x203)
scancode 0x800f0404 = KEY_NUMERIC_4 (0x204)
scancode 0x800f0405 = KEY_NUMERIC_5 (0x205)
scancode 0x800f0406 = KEY_NUMERIC_6 (0x206)
scancode 0x800f0407 = KEY_NUMERIC_7 (0x207)
scancode 0x800f0408 = KEY_NUMERIC_8 (0x208)
scancode 0x800f0409 = KEY_NUMERIC_9 (0x209)
scancode 0x800f040a = KEY_DELETE (0x6f)
scancode 0x800f040b = KEY_ENTER (0x1c)
scancode 0x800f040c = KEY_SLEEP (0x8e)
scancode 0x800f040d = KEY_MEDIA (0xe2)
scancode 0x800f040e = KEY_MUTE (0x71)
scancode 0x800f040b = KEY_OK (0x160)
… <truncated>


# X11 can’t recognize keycodes above decimal 255, so you need to re-map some keys.  Here are the remaps I made below based on my Harmony One remote. Remove the (hexcode) after the remap when you edit the /etc/rc_keymaps/myrc6_mce file
KEY_OK ⇒ KEY_ENTER
KEY_EXIT ⇒ KEY_ESC
KEY_DVD ⇒ KEY_M
KEY_INFO ⇒ KEY_I
KEY_RECORD ⇒ KEY_R
KEY_PLAY ⇒ KEY_P
KEY_PAUSE ⇒ KEY_P
KEY_EPG ⇒ KEY_G


# As an example, a section of the /etc/rc_keymaps/myrc6_mce file should look like this:
scancode 0x800f040f = KEY_I                     #changed from KEY_INFO
scancode 0x800f0410 = KEY_VOLUMEUP (0x73)
scancode 0x800f0411 = KEY_VOLUMEDOWN (0x72)
scancode 0x800f0412 = KEY_CHANNELUP (0x192)
scancode 0x800f0413 = KEY_CHANNELDOWN (0x193)
scancode 0x800f0414 = KEY_FASTFORWARD (0xd0)
scancode 0x800f0415 = KEY_REWIND (0xa8)
scancode 0x800f0416 = KEY_P                     #changed from KEY_PLAY
scancode 0x800f0417 = KEY_R                     #changed from KEY_RECORD
scancode 0x800f0418 = KEY_P                     #changed from KEY_PAUSE
scancode 0x800f0419 = KEY_STOP (0x80)
scancode 0x800f041a = KEY_NEXT (0x197)
scancode 0x800f041b = KEY_PREVIOUS (0x19c)
scancode 0x800f041c = KEY_NUMERIC_POUND (0x20b)
scancode 0x800f041d = KEY_NUMERIC_STAR (0x20a)
scancode 0x800f041e = KEY_UP (0x67)
scancode 0x800f041f = KEY_DOWN (0x6c)
scancode 0x800f0420 = KEY_LEFT (0x69)
scancode 0x800f0421 = KEY_RIGHT (0x6a)
scancode 0x800f0422 = KEY_ENTER                 #changed from KEY_OK
scancode 0x800f0423 = KEY_ESC                      #changed from KEY_EXIT
scancode 0x800f0424 = KEY_M                          #changed from KEY_DVD
scancode 0x800f0425 = KEY_TUNER (0x182)
scancode 0x800f0426 = KEY_G                          #changed from KEY_EPG


# Test the changes.  This can be done by updating the driver
% sudo ir-keytable --write /etc/rc_keymaps/myrc6_mce -d /dev/input/event10
You should see an output like this:
Wrote 63 keycode(s) to driver


% sudo ir-keytabe --test --device=/dev/input/event10
Press the “OK” key on the remote. You should get an output that looks like the one below.  
1416166547.998594: event type EV_MSC(0x04): scancode = 0x800f0422
1416166547.998594: event type EV_KEY(0x01) key_down: KEY_ENTER(0x0001)
1416166547.998594: event type EV_SYN(0x00).
1416166548.104565: event type EV_MSC(0x04): scancode = 0x800f0422
1416166548.104565: event type EV_SYN(0x00).
1416166548.353099: event type EV_KEY(0x01) key_up: KEY_ENTER(0x0001)
1416166548.353099: event type EV_SYN(0x00).


# Finally, to update on startup, just edit /etc/rc_maps.cfg as root and update the table to point to your new myrc6_mce keymap file:
#driver      table                    file
*                rc-rc6-mce          myrc6_mce


# Reboot and try your settings on mythfrontend.
% sudo reboot

6 comments:

  1. I wasted entire day in searching websites and forums. Finally you saved my day. Thanks a lot mate.

    ReplyDelete
  2. Guide helped. Would you please share the entire myrc6_mce keymaps file? Also, there is a typo in ir-keytable command in one step.
    > % sudo ir-keytabe --test --device=/dev/input/event10

    Should be % sudo ir-keytable --test --device=/dev/input/event10

    ReplyDelete
    Replies
    1. I don't see a typo or notice a change in what you suggest for:
      % sudo ir-keytable --test --device=/dev/input/event10

      Re: sharing the myrc6_mce file, it is setup specific. I'm using a Harmony One remote. FWIW, I added it to dropbox here:
      https://www.dropbox.com/s/lkxh8kyg00p02wq/myrc6_mce.txt?dl=0

      Delete
  3. This comment has been removed by a blog administrator.

    ReplyDelete