MythTV and the TwinHan remote

TwinHan remote controlToday’s challenge – getting this gizmo to work with MythTV. It turned out to be quite a pain so I am documenting it here in case I need to do it again in the future. Note that I am running Ubuntu 7.04 (Feisty Fawn). The procedure may be slightly different for other platforms.


UPDATE: This article is somewhat out of date now. I have re-written it for the latest version of Mythbuntu, you can read the updated guide here.



STEP 1 – Locate the device node for the remote
This remote has a very nifty USB receiver which presents itself to the PC as a HID keyboard. It is mapped to a device in /dev/input but we need to figure out which one. Type this command:

cat /proc/bus/input/devices

Now look for the TwinHan keyboard device. Beware, it also creates a mouse device which you do not want. The entry will look like this:

I: Bus=0003 Vendor=6253 Product=0100 Version=0110
N: Name="Twinhan Tech Remote Control"
P: Phys=usb-0000:00:11.2-1/input0
S: Sysfs=/class/input/input3
H: Handlers=kbd event3
B: EV=120003
B: KEY=800000 0 e0b0ffdf 1cfffff ffffffff fffffffe
B: LED=1f

Note the Sysfs entry. We will need this for the next step…

STEP 2 – Create a symlink to the device node
Even though we saw the remote was on /class/input/input3, It is not guaranteed to stay there. Next time you reboot it may be a different device so we need to create some method of referring to it which will work every time. We can use UDEV for this. Type this command (replacing inputX with the appropriate event device of course):

 udevinfo -a -p /class/input/inputX

You will get lots of output. We are interested in the first {modalias} line.

  looking at parent device '/class/input/input3':
    KERNELS=="input3"
    SUBSYSTEMS=="input"
    DRIVERS==""
    ATTRS{modalias}=="input:b0003v6253p0100e0110-e0,1,11,14,k74,75,77,7D,7E,7F,B7,raml0,1,2,3,4,sfw"
    ATTRS{uniq}=="1111111"
    ATTRS{phys}=="usb-0000:00:11.2-1/input0"
    ATTRS{name}=="Twinhan Tech Remote Control"

Create a new file /etc/udev/rules.d/10-local.rules and paste that line into it so it looks like this (this is supposed to be all on one line BTW):

KERNEL=="event*",ATTRS{modalias}=="input:b0003v6253p0100e0110-e0,1,11,14,
k74,75,77,7D,7E,7F,B7,raml0,1,2,3,4,sfw",SYMLINK="input/irremote"

Then simply unplug the USB device and plug it back in again. You should now see a new device called /dev/input/irremote. We can test it by typing the following. You should see data arrive whenever you press a button on the remote. Press Ctrl-C when you are done testing.

hexdump -C /dev/input/irremote

STEP 3 – Configure LIRC
You need to set up /etc/lirc/hardware.conf and lircd.conf. Both of these files are located in /etc/lirc. To save you the trouble of working out all the settings, I have posted mine here:

hardware.conf

lircd.conf

Once you have these files in place, restart the lirc daemon with this command:

/etc/init.d/lirc restart

You can test that it is working by typing this:

irw

Now every time you press a key, you should see it printed on the screen. Press Ctrl-C when you are done.

STEP 4 – Configure MythTV commands
We are getting closer now. The next step is to set up a file called /home/mythtv/.mythtv/lircrc which contains the mappings between the keys on the remote and the functions in MythTV. Once again, I have already prepared this file which you can download here:

lircrc-mythtv

Rename this file to lircrc and move it to /home/mythtv/.mythtv/. Once that is done, restart MythTV. Here are the key mappings you will end up with:

Key Function
REC Record
TELETEXT OSD
RECALL MENU
PREVIEW INFO
REW/FFWD Forward/backward in MythMusic
CAPTURE Previous playlist item in MythMusic
RECORDLIST Next playlist item in MythMusic

STEP 5 – Configure MPlayer
The final step is to configure the mapping between the remote and the commands in MPlayer. Since MPlayer is a separate program, it needs to be configured separately to MythTV. To configure it, we need another lircrc file but this time is has to be called /home/mythtv/.lircrc. Download it from here:

lircrc-mplayer

Rename it to .lircrc and put it in /home/mythtv and that should be that! Here are the key mappings for MPlayer:

Key Function
MUTE Mute
VOL+/- Adjust volume
CH+/- Skip fwd/back 60 seconds
REW/FFWD Skip fwd/back 10 seconds
PREVIEW Show/hide subtitles
TELETEXT Show/hide OSD
TAB Cycle through audio tracks

If you do not like the key mappings I have chosen, you may edit the lircrc files. The format should be fairly easy to follow.

43 thoughts on “MythTV and the TwinHan remote

  1. Learned new things, again. Just small difference: udevinfo returned “ATTR” in the beginning of line, but I have put “ATTRS” to file 10-local.rules . Just this small change, otherwise everything worked like a charm. GREAT howto, thanx.

  2. I could have sworn they were working the other day but now all the permissions are buggered. Sorry about that, it’s fixed now.

  3. Thanks for the easy to read howto…I hit a snag along the way. I’m using the Mythdora distro…Step 3 where we start irw, doing so immediately kills off lircd (always, as root, as mythtv, as sudo, etc.). The odd thing is that the remote (same as the photo above) still does “some” things with everything lirc-related killed. For example, pause works in Mythtv with the “capture” key (one key below the one it should be), Play works, CH+ and CH- seem to be mapped to PAGE UP/DOWN instead of just up/down, and Cancel seems to work. Even if I could get these few keys to work, I’d be in business. As far as I can tell, something other than lirc is doing all the work. I suspect it has something to do with the hidp module I see in lsmod but the docs on that are for someone other than me with just 10 years of Linux use. The gauntlet is thrown, however, so I will return if I find a solution (and if anyone out there has any suggestions, I’d love to hear them).

  4. The reason the thing will work without lircd is because it shows up in the system as a keyboard. So pressing the cursor-keys on the remote has the same effect as pressing the cursor keys on the keyboard. Some of the default mappings will indeed work with MythTV but as you noticed, it was only a few of them.

    I’m not sure why irw would crash lircd. Perhaps you could just skip that step, it is not essential.

  5. Thanks for this guide! I am using it for one of my mythtv frontends and it is working well.

    I really appreciate the work you did and Thank You for sharing it with the rest of us. Saved me from abandoning this control.

    Do you think this guide will work with Gutsy and Hardy?

  6. Thanks for commenting phar, I’m glad to see my article has been helpful.

    It would probably work just fine on Gutsy and later but I’m not intending to update this machine anytime soon now that I’ve got it running perfect.

    If you try this on any other OS, let me know how it goes!

  7. *sorry if it double posts, page wouldn’t load on posting comment, comment hasn’t shown up on page refresh*

    Hey I’ve been using your instructions to get my remote working, however it’s a different model to yours and has more buttons as it’s used for Digital TV and recording and other stuff. I’m having trouble adding more buttons to the lircd.conf file and I was wondering if you could help me, I made a post on the ubuntu forums http://ubuntuforums.org/showthread.php?p=4139750 . If you could help me it would be much appreciated :)

    Keep up the good work!!!

  8. Waistless, It looks like your remote is putting out a multiple key sequence. I’m really not sure how to configure lircd to cope with that. I had a quick look through the LIRC documentation and I couldn’t find any mention this situation.

    Sorry I can’t be much more help that this. Why not go over to http://www.lirc.org/ and post a question on their mailing list.

  9. Hmmm thanks, I think I will. If and when I eventually get all buttons working, I’ll upload the lircd.conf in the same forum thread. ;)

  10. The perfect answer with all the good info, thanks so much for posting this when you figured it out.
    I happened to find that persistant devices names are avail under “/dev/input/by-id/” path as well but i prefer this. Just for the record I amusing Ubuntu Gutsy 7.10.

  11. did not have to use lirc to get my remote working. You’ll find that some of the remote keys generates combo keys, e.g. Play is Ctrl+N. You can use xev to confirm which key does what. I used MythControls to map these keys to Myth functions. The trick is not to use the actual remote key for combo keys when you get to the “waiting for keypress” screen when binding keys. Use the keyboard for these. If you use the remote, it generates something like Ctrl+Square for all combo keys, so they turn up the same for all combo keys.

    Hope this helps.

    Cheers!
    RoboRat

  12. I have the same remote control as you show on the picture. I followed the guide step by step.My USB remote control work perfectly in my Ubuntu 7.10 Terminal screen with the IRW commande but is not working in MythTV…Can you help me

  13. Double-check your lircrc-mythtv file. You might need to move it to a different folder depending on what user account you run MythTV under.

    Also check that the signal names listed in lircrc-mythtv match the ones being output by irw.

  14. Hi,
    I transfered my lircrc file from /home/mythtv/.mythtv to /home/gonzo/.mythtv. Still have the same problem. It work perfectly on Ubuntu but not very well in mythtv. When I open mythtv it work the first time I entered a channel…but after that it’s slow and i’m not able to do anything. Could it be the lirc that I did’nt choose the correct remote. I have one exactly like the photos that you have…If so how can I reconfig Lirc.

    Thanks

  15. Hi! I made the modification that you sugest and I have the same probleme. I put the lircrc file in the directory that is setup MythTV /home/username directory/.MythTv/lircrc. It still work under Ubuntu but not in MythTV…It work when I start MythTv the first time I’m able to change the channel pressing the button only one time. After it fall very slow and I’m not able to use my remote.

    Any other Idea….

    Thanks

  16. If the output from IRW is correct, chances are that LIRC is working. I’m not quite sure what you mean by “Works in Ubuntu but not Myth”. Are you dual-booting or something ?

    What LIRC is doing is simply pretending to be a keyboard and sending keystrokes to MythTV. You might like to test Myth with your keyboard and see if it works properly then.

  17. I wanted to use the remotes up and down buttons control to replace the keyboard’s up and down buttons in the main MythTV display area. I.E. from “watch TV” to “media Library” or manage recordings”. Is that possible? I noticed that you did not map any of the directional keys. Can that be done? If so, How?
    Thanks for establshing this page, I can’t imagine how much time it must have taken.

  18. The directional keys on my remote control are labelled VOL- (left), VOL+ (right), CH+ (up) and CH- (down). These are the key names I have used when mapping it to MythTV.

    The file lircrc-mythtv controls the mappings when in the MythTV menus, if you look at that file you will see I have mapped the up and down to CH+ and CH-.

    The file lircrc-mplayer controls the key mappings while playing video. I have mapped the CH+ and CH- keys to jump forward and backward in large steps as a kind of really-fast-forward function which I find useful.

    If your remote has different names for the directional keys, you will need to edit the lircrc-mythtv and lircrc-mplayer files to change the names to whatever they are called on your remote.

  19. No joy with Hardy Beta, didn’t seem to want to create the /dev/input/irremote.

    More success with the xev and MythControls method. The play button in my case is “Enter” so I didn’t remap it but the keys that got me were the “Vol-” & “Vol+” which are “Left Shift” + “Down” & “Left Shift” + “Up” respectively. This method does not require the use of Lirc.

    Thanks for your suggestion RoboRat.

  20. Hey there Adam, and thanks for this handy HowTo of yours. Question: Do you know if there is a way to get ANOTHER remote working with that particular Twinhan sensor device? I had no luck so far: irrecord would work fine learning the keys of every different remote control I tried, but the output of irw would always be rubbish… the lircd.conf I found on the lirc website didn’t help either. I don’t like the Twinhan remote that much and I don’t see the problem the sensors has with other remotes… maybe some1 has an idea? Thanks in advance.

  21. I really doubt any other remote control will work with this receiver.

    The receiver presents itself as a HID class device which means the decoding of the IR code must be done inside the receiver. Programs like irrecord will not be able to access the raw IR data.

    The only way I can think of to get another controller to work is to either find a remote control which puts out exactly the same code as the original controller or possibly use a universal remote control to send those same codes.

  22. every thing works fine in my ubuntu 7.10 but when i pressed Power button a black terminal screen comes ubuntu 7.10 usr-desktop tty6 … what must i do.. thanks for this How to

  23. I could never get the power button to work properly either. It gives off a three-key sequence which seems to confuse the software. I just don’t use it.

  24. hi doctor hi guys and thank you man (doctor) for this . it works fine for me with ubuntu gutsy 7.10 but not with ubuntu hardy 8.04 . any idea ??

  25. I haven’t tried Ubuntu 8 yet. Do you have any idea at which stage it is failing (eg. does irw work ? does the UDEV rule work ?)

  26. No joy with Hardy 8.04 also. The driver /dev/input does not seem to work with it. I used your guide and had it working perfectly in 7.10.

    The new lirc has a new file format but even with the new format it does not like /dev/input as a driver.

    root@firefly02:~# vi /etc/lirc/hardware.conf
    root@firefly02:~# /usr/sbin/lircd -n
    lircd-0.8.3pre1[7014]: config file contains no valid remote control definition
    lircd-0.8.3pre1[7014]: lircd(userspace) ready
    lircd-0.8.3pre1[7014]: accepted new client on /dev/lircd
    lircd-0.8.3pre1[7014]: could not get file information for /dev/lirc
    lircd-0.8.3pre1[7014]: default_init(): No such file or directory
    lircd-0.8.3pre1[7014]: caught signal
    Terminated
    root@firefly02:~# vi /etc/lirc/hardware.conf
    root@firefly02:~# /etc/init.d/lirc restart
    * Stopping remote control daemon(s): LIRC [fail]
    * Loading LIRC modules [ OK ]
    * Starting remote control daemon(s) : LIRC Driver `/dev/input’ not supported.

    Dies when I run irw in a new terminal.

  27. This is a follow up on comment 28 – I think I have it. Not sure if there is something wrong with the lirc init.d script or whatever but if I run:

    /usr/sbin/lircd -H dev/input –device=/dev/input/event2 -n

    Then I can get irw to work. So now I just need to setup my own rc.d to run this on boot and I then do the key map to elisa.

  28. Adding line
    ATTRS{modalias}==”input:b0003v6253p0100e0110-e0*”, SYMLINK+=”input/irremote”
    to /etc/udev/rules.d/60-persistent-input.rules helped me.

  29. ETisaRE you mean works for you now on hardy 8.04 ?? by adding this ATTRS{modalias}==”input:b0003v6253p0100e0110-e0*”, SYMLINK+=”input/irremote”
    to /etc/udev/rules.d/60-persistent-input.rules

  30. Hi, did anybody got it running under (x)ubuntu 8.04 ? Sofar I had no success. :-(

  31. I used the original guide on Ubuntu 7.05 (thanks Adam)

    For 8.04 things seem different and easier. I set up my hardware.conf with
    REMOTE_DRIVER=”devinput”
    REMOTE_DEVICE=”/dev/input/by-id/usb-Twinhan_Tech_Remote_Control_1111111-event-kbd”

    … and that seems to be all that needs doing. Bear in mind the hardware.conf format has changed between Ubuntu 7 and 8 (I originally just copied my old file in, and got annoyed when it wouldn’t work.)

    Thanks again for the original guide.

    - Angus

  32. Forwarded from Doug via email:

    Hi Adam,

    You mentioned in your article that you had not been able
    to get the remote’s POWER button working. If that is still the
    case, you might like to try adding the line:
    POWER 0x1001d
    to the lircd.conf file. This enabled me to define actions for POWER
    that seemed to work OK when I pressed the POWER button on my remote.

    Hope this helps someone!

    Doug.

  33. Hi there,

    maybe a lil off-topic, but i found this thread googling…..

    Does anybody of you know what IR-transistor hardware piece is inside this IR receiver from twinhan, i mean brand and model.

    regards,

    Sven

  34. Thanks Adam for your useful site – used it to build my original MythTV box. Recently this box overheated due to dust build up causing the HDD to lose data.

    Rebuilt the box using Mythbuntu 8.10 Intrepid Ibex but spent a lot of time trying to get my Twinhan VP7045 remote working.
    hexdump -C /dev/input/irremote did not work. irw did not work.

    Switched to tty using Ctrl-Alt-F1, logged in as root. hexdump and irw worked. ‘lsmod | grep evdev’ in the tty and from within the X terminal shows that the evdev module being referenced differently when hexdump and irw worked / did not work.

    Found the comment by Mario Limonciello at https://bugs.launchpad.net/ubuntu/+source/lirc/+bug/164627 last night and this fixed my problem. Use lshal to find out the input.product string – ‘IR-receiver inside an USB DVB receiver’ in my case.

    xyz@iota:~$ lshal | grep input.product
    input.product = ‘Macintosh mouse button emulation’ (string)
    input.product = ‘Power Button (CM)’ (string)
    input.product = ‘Power Button (FF)’ (string)
    input.product = ‘PC Speaker’ (string)
    input.product = ‘IR-receiver inside an USB DVB receiver’ (string)
    input.product = ‘IR-receiver inside an USB DVB receiver’ (string)
    input.product = ‘Logitech USB Receiver’ (string)
    input.product = ‘Logitech USB Receiver’ (string)

    Change the file /usr/share/hal/fdi/preprobe/20thirdparty/lirc.fdi from

    true

    to match your input.product string. Mine was changed to:

    true

    And the remote works now.

  35. Reposting as XML bit got lost in translation.

    Thanks Adam for your useful site – used it to build my original MythTV box. Recently this box overheated due to dust build up causing the HDD to lose data.

    Rebuilt the box using Mythbuntu 8.10 Intrepid Ibex but spent a lot of time trying to get my Twinhan VP7045 remote working.
    hexdump -C /dev/input/irremote did not work. irw did not work.

    Switched to tty using Ctrl-Alt-F1, logged in as root. hexdump and irw worked. ‘lsmod | grep evdev’ in the tty and from within the X terminal shows that the evdev module being referenced differently when hexdump and irw worked / did not work.

    Found the comment by Mario Limonciello at https://bugs.launchpad.net/ubuntu/+source/lirc/+bug/164627 last night and this fixed my problem. Use lshal to find out the input.product string – ‘IR-receiver inside an USB DVB receiver’ in my case.

    xyz@iota:~$ lshal | grep input.product
    input.product = ‘Macintosh mouse button emulation’ (string)
    input.product = ‘Power Button (CM)’ (string)
    input.product = ‘Power Button (FF)’ (string)
    input.product = ‘PC Speaker’ (string)
    input.product = ‘IR-receiver inside an USB DVB receiver’ (string)
    input.product = ‘IR-receiver inside an USB DVB receiver’ (string)
    input.product = ‘Logitech USB Receiver’ (string)
    input.product = ‘Logitech USB Receiver’ (string)

    Change the file /usr/share/hal/fdi/preprobe/20thirdparty/lirc.fdi from

    true

    to match your input.product string. Mine was changed to:

    true

    And the remote works now.

  36. Last 2 comments did not work due to HTML tag filter, so here is an extract.

    Change /usr/share/hal/fdi/preprobe/20thirdparty/lirc.fdi with the line
    match key=”info.product” contains_ncase=”saa7134 ir”
    to
    match key=”info.product” contains_ncase=”IR-receiver inside an USB DVB receiver”

  37. Thankx for your howto
    I passed all procedure .I think every thing is good but my /etc/init.d/lirc restart output is
    * Stopping remote control daemon(s): LIRC [fail]
    * Loading LIRC modules [ OK ]
    * Starting remote control daemon(s) : LIRC [fail]
    and when i type irw in terminal nothing happens .

  38. bug fix for Twinhan DTV StarBox USB2.0 DVB-S
    enabled remote control
    Tested-by: Tomasz G. B.

    on Mandriva 2009.0, Kernel 2.6.32.8, Kaffeine 0.8.7 TwinhanDTV StarBox USB2.0 DVB-S model no:7021

    — linux-2.6.32.8/drivers/media/dvb/dvb-usb/vp702x.c.orig 2010-02-09 13:57:19.000000000 +0100
    +++ linux-2.6.32.8/drivers/media/dvb/dvb-usb/vp702x.c 2010-02-19 01:14:10.000000000 +0100
    @@ -173,40 +173,86 @@ static int vp702x_streaming_ctrl(struct
    return 0;
    }

    -/* keys for the enclosed remote control */
    +/* keys for the enclosed remote control (define your events) (code, event) */
    static struct dvb_usb_rc_key vp702x_rc_keys[] = {
    - { 0×0001, KEY_1 },
    - { 0×0002, KEY_2 },
    + { 0x004d, KEY_SCREEN }, /* Full screen */
    + { 0×0016, KEY_POWER }, /* Power */
    + { 0×0003, KEY_1 }, /* 1 */
    + { 0×0001, KEY_2 }, /* 2 */
    + { 0×0006, KEY_3 }, /* 3 */
    + { 0×0009, KEY_4 }, /* 4 */
    + { 0x001d, KEY_5 }, /* 5 */
    + { 0x001f, KEY_6 }, /* 6 */
    + { 0x000d, KEY_7 }, /* 6 */
    + { 0×0019, KEY_8 }, /* 7 */
    + { 0x001b, KEY_9 }, /* 8 */
    + { 0×0011, KEY_RECORD }, /* REC */
    + { 0×0015, KEY_0 }, /* 9 */
    + { 0×0017, KEY_FAVORITES }, /* Heart symbol – Favorite */
    + { 0×0040, KEY_REWIND }, /* Rewind */
    + { 0×0005, KEY_CHANNELUP }, /* CH+ */
    + { 0×0012, KEY_FASTFORWARD }, /* Forward */
    + { 0x000a, KEY_VOLUMEDOWN }, /* VOL- */
    + { 0×0014, KEY_PLAY }, /* Play */
    + { 0x001e, KEY_VOLUMEUP }, /* VOL+ */
    + { 0x000e, KEY_PREVIOUS }, /* Recall */
    + { 0×0002, KEY_CHANNELDOWN }, /* CH- */
    + { 0x001a, KEY_STOP }, /* Stop */
    + { 0x004c, KEY_PAUSE }, /* Time Shift – Pause */
    + { 0×0010, KEY_MUTE }, /* Mute */
    + { 0x000c, KEY_CANCEL }, /* Cancel */
    + { 0×0054, KEY_PRINT }, /* Capture */
    + { 0×0048, KEY_INFO }, /* Preview */
    + { 0x001c, KEY_EPG }, /* EPG */
    + { 0×0004, KEY_LIST }, /* RecordList */
    + { 0×0000, KEY_TAB }, /* Tab */
    + { 0x000f, KEY_TEXT }, /* Teletext */
    + { 0×0041, KEY_PREVIOUSSONG },
    + { 0×0042, KEY_NEXTSONG },
    + { 0x004b, KEY_UP },
    + { 0×0051, KEY_DOWN },
    + { 0x004e, KEY_LEFT },
    + { 0×0052, KEY_RIGHT },
    + { 0x004f, KEY_ENTER },
    + { 0×0054, KEY_AUDIO },
    + { 0×0013, KEY_CANCEL },
    + { 0x004a, KEY_CLEAR },
    + { 0×0043, KEY_SUBTITLE },
    + { 0×0008, KEY_VIDEO },
    + { 0×0007, KEY_SLEEP },
    + { 0×0045, KEY_ZOOM },
    + { 0×0018, KEY_RED},
    + { 0×0053, KEY_GREEN},
    + { 0x005e, KEY_YELLOW},
    + { 0x005f, KEY_BLUE}
    };

    -/* remote control stuff (does not work with my box) */
    +/* remote control stuff */
    static int vp702x_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
    {
    u8 key[10];
    int i;

    -/* remove the following return to enabled remote querying */
    - return 0;
    -
    vp702x_usb_in_op(d,READ_REMOTE_REQ,0,0,key,10);

    - deb_rc(“remote query key: %x %d\n”,key[1],key[1]);
    + deb_rc(“remote query key: %x %d\n”, key[3], key[3]);

    if (key[1] == 0×44) {
    *state = REMOTE_NO_KEY_PRESSED;
    return 0;
    }

    - for (i = 0; i < ARRAY_SIZE(vp702x_rc_keys); i++)
    - if (rc5_custom(&vp702x_rc_keys[i]) == key[1]) {
    - *state = REMOTE_KEY_PRESSED;
    - *event = vp702x_rc_keys[i].event;
    - break;
    + if (key[2] == key[3] + key[4]) {
    + for (i = 0; i < ARRAY_SIZE(vp702x_rc_keys); i++)
    + if (rc5_data(&vp702x_rc_keys[i]) == key[3]) {
    + *state = REMOTE_KEY_PRESSED;
    + *event = vp702x_rc_keys[i].event;
    + break;
    + }
    }
    return 0;
    }

    -
    static int vp702x_read_mac_addr(struct dvb_usb_device *d,u8 mac[6])
    {
    u8 i;

    ————————-
    this is patch for linux-2.6.32.8 kernel and higher
    apply this patch and compile kernel
    it's work for me

Comments are closed.