I did my testing on a Virtualbox guest running a Minimal Ubuntu Linux 18.04 server and Raspbian Stretch 2018-06-27. Follow that link to see how I did that. The IR sensor is USB so that goes into the host and then when the virtual machine is running use the menu option Devices -> USB -> TopSeed Technology Corp. eHome Infrared Transceiver.
Since this is going to end up controlling Mythtv you will probably use a convenient front end machine. Make sure you back it up before you start. You did make a backup didn’t you? Please do not use comments to say your production mythtv-frontend got screwed up.
The receiver will then be visible in your server.
You can check that out
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub Bus 002 Device 003: ID 1784:0011 TopSeed Technology Corp. eHome Infrared Transceiver Bus 002 Device 002: ID 80ee:0021 VirtualBox USB Tablet Bus 002 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
The name it returns is a bit of a give away 🙂
If you have tried to get lircd working on Ubuntu 18.04 and succeed very well done! I gave up and sorted it out this way.
You do not need lircd or lircd-x installed to get this working, it will not even come in handy later. If you have it installed you can remove it if you like with the following.
sudo apt update
sudo apt purge lircd*
Install the software
sudo apt install ir-keytable
We can do some checks without configuring anything. You can run the next command with or without sudo (as root) without root you get less information, You will not see the bus data and extra capabilities.
Found /sys/class/rc/rc0/ (/dev/input/event7) with: Name: Media Center Ed. eHome Infrared Remote Transceiver (1784:0011) Driver: mceusb, table: rc-rc6-mce lirc device: /dev/lirc0 Supported protocols: lirc rc-5 rc-5-sz jvc sony nec sanyo mce_kbd rc-6 sharp xmp Enabled protocols: lirc rc-6 bus: 3, vendor/product: 1784:0011, version: 0x0100 Repeat delay = 500 ms, repeat period = 125 ms
So we now know that the system can see our device, with lsusb and with ir-keytable. You may need to know the device name assigned to the receiver for some of the ir-keytable commands, see below. My device was listed as lirc device as /dev/lirc0. Strange as I definitely do not have lircd installed not even a little bit. On real hardware it will come out like this /dev/input/event7
You can also see that the output for my remote shows
- Driver: mceusb
- Table: rc-rc6-mce
- Protocol: mce_kbd rc-6
When your device is not automatically found
If there was no output you will need to specify the device name. It is possible to find it with one of the following.
ls -l /dev/input/by-path/*-ir # for real hardware
ls -l /dev/lir* # for virtual machines / Raspberry Pi
If you saw a message about not finding your device with the test use the ‘device’ <lirc device> where the <lirc device> comes from the the output from ir-keytable without any arguments.
Testing you device
Lets see if we can get some input from the remote to our server and then see that on the screen.
sudo ir-keytable --test
Start by pressing a few buttons you should see some output on the screen. Not only that but the output appears to already know what key you are pressing. Far simpler than lircd.
Testing events. Please, press CTRL-C to abort. 1434.457281: event type EV_MSC(0x04): scancode = 0x800f0422 1434.457281: event type EV_KEY(0x01) key_down: KEY_OK(0x0160) 1434.457281: event type EV_SYN(0x00). 1434.591229: event type EV_MSC(0x04): scancode = 0x800f0422 1434.591229: event type EV_SYN(0x00). 1434.848605: event type EV_KEY(0x01) key_up: KEY_OK(0x0160) 1434.848605: event type EV_SYN(0x00). 1435.606259: event type EV_MSC(0x04): scancode = 0x800f0421 1435.606259: event type EV_KEY(0x01) key_down: KEY_RIGHT(0x006a) 1435.606259: event type EV_SYN(0x00). 1435.740992: event type EV_MSC(0x04): scancode = 0x800f0421 1435.740992: event type EV_SYN(0x00). 1436.000427: event type EV_KEY(0x01) key_up: KEY_RIGHT(0x006a) 1436.000427: event type EV_SYN(0x00).
List all scan codes
To get a list of scan code your remote may return try the following. This command lists may show code that your remote does not have keys for. It just lists all the scan codes for the protocol.
sudo ir-keytable --read
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)
The scancode 0x800…. is the code returned by your remote to ir-keytable. The value KEY_DELETE is the data passed on to the kernel. The hexidecimal number in braces is the keyboard scan code associated with the KEY_FOOBAR value. Do not change the scancode, ever. The KEY_FOOBAR part you can change and that will change the value in brackets.
Configuring for MythTV
So far we have only installed the ir-keytable software and not done any configuring at all. The problem we have is that MythTV cannot understand all. Well actually most of the keyboard scan codes coming back to it from our remote.
You did make a backup you can restore, didn't you?
To remap a key we need a keymap file. There are a load installed with ir-keytable, in the directory /lib/udev/rc_keymaps. Now remember when you ran ir-keytable as root it output the table, in my case it was rc-rc6-mce. There is a cfg file that holds a list of tables and files map files it will use. To find it just grep the cfg file or look at it with less or cat.
grep rc-rc6-mce /etc/rc_maps.cfg
My search found this line
* rc-rc6-mce rc6_mce
This shows we will be using the map file /lib/udev/rc_keymaps/rc6_mce. If we move it in to /etc/rc_keymaps it will be loaded automatically at boot time.
sudo cp /lib/udev/rc_keymaps/rc6_mce /etc/rc_keymaps
The beginning of the file looks like this
# table rc6_mce, type: RC6 0x800f0400 KEY_NUMERIC_0 0x800f0401 KEY_NUMERIC_1 0x800f0402 KEY_NUMERIC_2 0x800f0403 KEY_NUMERIC_3 0x800f0404 KEY_NUMERIC_4 0x800f0405 KEY_NUMERIC_5 0x800f0406 KEY_NUMERIC_6 0x800f0407 KEY_NUMERIC_7 0x800f0408 KEY_NUMERIC_8 0x800f0409 KEY_NUMERIC_9 0x800f040a KEY_DELETE 0x800f040b KEY_ENTER 0x800f040c KEY_SLEEP ... Enabled protocols: lirc rc-6
Do not touch the first line or the last line. The rest of the file is similar to the output from ir-tables –read. The first column is the scan code returned by your remote, the second column is the KEY_FOOBAR codes that get passed to the kernel.
We can now edit the new file in /etc/rc_keymaps and it will be reloaded at boot time or when we give the reload command.
There are a number of keys on the remote that do not automatically work with Mythtv. So by way of example, I will remap the Video key on my remote to go to the Mythtv Jump point Video Default. That is where you have saved all your home videos to.
First find a key on the keyboard that is not already mapped. This page shows the keybinding for Mythtv. I chose ‘=’ or KEY_EQUAL. Edit the key map file in /etc/rc_keymaps. Change the line
scancode 0x800f044a = KEY_VIDEO
I like to put a comment next to any changes I make, so I know what the keys were originally key mapping was.
scancode 0x800f044a = KEY_EQUAL # was KEY_VIDEO
Now reload the keymaps file with the following. We clear out all existing map file data rather than append in some extra data.
sudo ir-keytable --clear --write /etc/rc_keymaps/rc6_mce
And you should a see a little bit of output just to let you know what happened.
Read rc6_mce table Old keytable cleared Wrote 64 keycode(s) to driver Protocols changed to rc-6
Now rerun ir-keytable in test mode and you should see that the Video key now output KEY_EQUAL and not KEY_VIDEO.
sudo ir-keytable --test
Testing events. Please, press CTRL-C to abort. 7937.127973: event type EV_MSC(0x04): scancode = 0x800f044a 7937.127973: event type EV_KEY(0x01) key_down: KEY_EQUAL(0x000d) 7937.127973: event type EV_SYN(0x00). 7937.261381: event type EV_MSC(0x04): scancode = 0x800f044a 7937.261381: event type EV_SYN(0x00). 7937.538840: event type EV_KEY(0x01) key_up: KEY_EQUAL(0x000d) 7937.538840: event type EV_SYN(0x00).
To make that work in Mythtv. From the front end where the remote will be connected into, From the first screen Setting -> Edit Keys. In the left-hand column scroll down to JumpPoints then in the right-hand column scroll down to Video defaults and press Return/Enter twice. You will be prompted to Press A Key. Press the key you chose to remap, Then use the cursor keys to highlight OK, press enter again. If you press escape now you will be asked it you want to Save changes?. Or you could also access the save menu with the ‘m’ or menu key.
These changes will not take affect until you restart Myth-frontend and X, the display manager. This is a little quick than a reboot.
To restart X and log you out use the command below.
When you restart X it will close all GUI based programs without saving and log you out. Please make sure you close all programs before running the command below.
sudo systemctl restart display-manager
Now just remap the remaining keys on your remote as you would like and update Mythtv as above.
Remember after making changes:
- Save the keymaps file.
- Reload the keymaps file into ir-keytable
- Change MythTV key maps.
- Save the new keymaps
- Restart myth-frontend
That is it you remote is now talking Mythtv. Time to change the batteries on the remote 🙂
I found that sometime the input from the remote was taken twice. You can slow down the remote a little with something like this. experiment until it works for you.
sudo ir-keytable -D 500 -P 250
Repeat delay = 500 ms, repeat period = 125 ms Changed Repeat delay to 500 ms and repeat period to 250 ms
If you remember at the very top when we first looked at ir-keytable output the missing data when you do not run it as root is this line, you may recognize it now.
Repeat delay = 500 ms, repeat period = 250 ms