tweenux
RSS Feed Email Feed

Fully working remote control (HVR-4000) on kernel 2.6.35

Remote control support (input device events) is now handled by the kernel (>=2.6.17). However, not all remote buttons may work out of the box. The driver that handles input device events, xf86-input-evdev, needs to be patched in order to remap higher keycodes than the xserver may handle. x server (Xorg/x11) is built with 255 keycodes in mind, out from the fact that a keyboard rarely has so many keys (but perhaps >128). The problem arise when we use new special keys like on a remote control or extended keyboards or laptops that uses multimedia keys. These keys might have a keycode higher than the regular keycode space may interpret. (>255).

For a long time I thought the kernel only could handle a few buttons from my remote (some remote buttons was not working (menu, back, ch+,ch-)), so I needed to install lirc to get the whole remote to work properly. Though, its been more and more difficult to run lirc on top of the kernel where both interpret to triggered events. Since the ir_common module is impossible to blacklist (kernel >=2.6.33?), something had to be done. Lately, in Ubuntu 10.10, lirc has been left completely useless because a single key press on the remote has resulted in two actions in eg. xbmc for the keys that xserver responds to.
Thanks to Gianni Ceccarelli, who has made a patch making it possible to remap these higher keycodes, the remote can now be mapped to whatever I would like without the use of lirc.

To figure out what keys are not recognised by xserver, simply use/install evtest.

:~$ sudo aptitude install evtest

My irremote is found at this path /dev/input/by-path/pci-0000\:03\:06.1-event-ir (you will find yours by looking for an event-ir device). In order to find the device easier, I will create an udev rule that make a symbol link to /dev/input/irremote.

:~$ sudo vi /etc/udev/rules.d/10-local.rules
KERNEL=="event*",SYSFS{vendor}=="0x14f1",SYMLINK="input/irremote"

To find the vendor id:

:~$ lspci -nn
Conexant Systems, Inc. CX23880/1/2/3 PCI Video and Audio Decoder
[IR Port] [14f1:8804] (rev 05)

Be sure to add 0x infront of the id.

Reload udev or restart computer in order to make the symlink valid. Now we can use this path to test for lost keys in the xserver event mapping:

sudo evtest /dev/input/irremote

The result:

Input driver version is 1.0.1
Input device ID: bus 0x1 vendor 0x70 product 0x6902 version 0x1
Input device name: "cx88 IR (Hauppauge WinTV-HVR400"
Supported events:
  Event type 0 (Sync)
  Event type 1 (Key)
    Event code 2 (1)
    Event code 3 (2)
    Event code 4 (3)
    Event code 5 (4)
    Event code 6 (5)
    Event code 7 (6)
    Event code 8 (7)
    Event code 9 (8)
    Event code 10 (9)
    Event code 11 (0)
    Event code 28 (Enter)
    Event code 103 (Up)
    Event code 105 (Left)
    Event code 106 (Right)
    Event code 108 (Down)
    Event code 113 (Mute)
    Event code 114 (VolumeDown)
    Event code 115 (VolumeUp)
    Event code 116 (Power)
    Event code 119 (Pause)
    Event code 128 (Stop)
    Event code 139 (Menu)
    Event code 142 (Sleep)
    Event code 163 (NextSong)
    Event code 165 (PreviousSong)
    Event code 167 (Record)
    Event code 168 (Rewind)
    Event code 174 (Exit)
    Event code 207 (Play)
    Event code 208 (Fast Forward)
    Event code 353 (Select)
    Event code 363 (Channel)
    Event code 365 (EPG)
    Event code 367 (MHP)
    Event code 370 (Subtitle)
    Event code 372 (Zoom)
    Event code 377 (TV)
    Event code 385 (Radio)
    Event code 388 (Text)
    Event code 392 (Audio)
    Event code 393 (Video)
    Event code 398 (Red)
    Event code 399 (Green)
    Event code 400 (Yellow)
    Event code 401 (Blue)
    Event code 402 (ChannelUp)
    Event code 403 (ChannelDown)
    Event code 412 (Previous)
  Event type 20 (Repeat)
Testing ... (interrupt to exit)

Now we need to download and patch xf86-input-evdev.

:~$ sudo aptitude install git-core build-essential libtool autoconf
:~$ sudo aptitude install xserver-xorg-dev xutils-dev
:~$ git clone git://www.thenautilus.net/xf86-input-evdev
:~$ cd xf86-input-evdev
:~/xf86-input-evdev$ git pull git://www.thenautilus.net/xf86-input-evdev code-remap
From git://www.thenautilus.net/xf86-input-evdev
 * branch            code-remap -> FETCH_HEAD
Auto-merging man/Makefile.am
CONFLICT (content): Merge conflict in man/Makefile.am
Auto-merging man/evdev.man
Auto-merging src/evdev.c
Auto-merging src/evdev.h
Automatic merge failed; fix conflicts and then commit the result.

If git complains about a problem regarding merging man/Makefile.am, this is what you need to do.
Open up man/Makefile.am, and edit out these 3 lines

<<<<<<< HEAD
=======
>>>>>>> 35315fc33467b93795baddfc581a1937ae3323ca
:~/xf86-input-evdev$ pico man/Makefile.am
:~/xf86-input-evdev$ git add man/Makefile.am
:~/xf86-input-evdev$ git commit -m "fix merge error"
:~/xf86-input-evdev$ git pull

The last command should now give you : Already up-to-date.

On with the installation:

:~/xf86-input-evdev$./autogen.sh
:~/xf86-input-evdev$ ./configure
:~/xf86-input-evdev$ make
:~/xf86-input-evdev$ sudo make install

The new driver is now located in /usr/local/lib/xorg/modules.
Now we need to add this to the module path for X:

:~$ sudo pico /etc/X11/xorg.conf

Add this section in the file:

Section "Files"
        ModulePath "/usr/local/lib/xorg/modules,/usr/lib/xorg/extra-modules,/usr/lib/xorg/modules"
EndSection

Restart X, and check that the driver is correctly loaded.

:~$ grep evdev_drv /var/log/Xorg.0.log

Hopefully the output will be like this:

(II) Loading /usr/local/lib/xorg/modules/input/evdev_drv.so

The patch adds a configuration option called event_key_remap, and takes in arguments like $evdev_code = $x11_code (as a whitespace separated list). $evdev_code is found from the evtest list printet out at the beginning of this document, while $11_code may be found using xmodmap (shown below).
There are two methods for implementing this re-mapping of keys. By editing xorg.conf or creating a local hal fdi rule under /etc/hal/fdi/policy/.
Below follow my xorg.conf implementation:

Section "ServerLayout"
        Identifier      "Default Layout"
        InputDevice     "RF remote" "SendCoreEvents"
EndSection

Section "InputDevice"
        Identifier  "RF remote"
        Driver      "evdev"
        Option      "Device" "/dev/input/irremote"
        Option      "event_key_remap" "402=112 403=117 365=135 174=22 139=147"
EndSection

For short, I would like button ChannelUp (evtest keycode 402 ) on the remote control to map to the Xserver action Prior(Page Up) (keycode 112).

Since I run xmodmap in a terminal from another computer, i add -display :0 in order to for it to grab data from the xserver.

:~$ xmodmap -pke -display :0
keycode   8 =
keycode   9 = Escape NoSymbol Escape
keycode  10 = 1 exclam 1 exclam exclamdown onesuperior
keycode  11 = 2 quotedbl 2 quotedbl at twosuperior
keycode  12 = 3 numbersign 3 numbersign sterling threesuperior
keycode  13 = 4 currency 4 currency dollar onequarter
keycode  14 = 5 percent 5 percent onehalf U2030
keycode  15 = 6 ampersand 6 ampersand yen fiveeighths
keycode  16 = 7 slash 7 slash braceleft division
keycode  17 = 8 parenleft 8 parenleft bracketleft guillemotleft
keycode  18 = 9 parenright 9 parenright bracketright guillemotright
keycode  19 = 0 equal 0 equal braceright degree
...
keycode 121 = XF86AudioMute NoSymbol XF86AudioMute
keycode 122 = XF86AudioLowerVolume NoSymbol XF86AudioLowerVolume
keycode 123 = XF86AudioRaiseVolume NoSymbol XF86AudioRaiseVolume
keycode 124 = XF86PowerOff NoSymbol XF86PowerOff
keycode 125 = KP_Equal NoSymbol KP_Equal
keycode 126 = plusminus NoSymbol plusminus
keycode 127 = Pause Break Pause Break
keycode 128 = XF86LaunchA NoSymbol XF86LaunchA
keycode 129 = KP_Decimal NoSymbol KP_Decimal
keycode 130 = Hangul NoSymbol Hangul
keycode 131 = Hangul_Hanja NoSymbol Hangul_Hanja
keycode 132 =
keycode 133 = Super_L NoSymbol Super_L
keycode 134 = Super_R NoSymbol Super_R
keycode 135 = Menu NoSymbol Menu
keycode 136 = Cancel NoSymbol Cancel
keycode 137 = Redo NoSymbol Redo
keycode 138 = SunProps NoSymbol SunProps
keycode 139 = Undo NoSymbol Undo
keycode 140 = SunFront NoSymbol SunFront
keycode 141 = XF86Copy NoSymbol XF86Copy
keycode 142 = SunOpen NoSymbol SunOpen
keycode 143 = XF86Paste NoSymbol XF86Paste
...

(See logfile for mor detailed output)

Lirc should now be possible to uninstall, making the use of the media center much, much easier.
xbmc recognices a lot of the xmodmap codes, but an option is to directly map keycodes directly into the lircmap.xml file inside .xbmc/userdata folder in your home directory.

References:
http://www.mythtv.org/wiki/Remapping_remote_control_key_codes_greater_than_255
http://www.thenautilus.net/SW/xf86-input-evdev/en
http://bugs.freedesktop.org/show_bug.cgi?id=11227

6 Comments

rafe  on February 10th, 2011

I would love to use this patch, but I can’t get it to build. I’m getting errors with “autogen” and “make” just doesn’t go.
These are the sorts of errors I’m getting:

configure.ac:25: warning: AC_INIT: not a literal: https://bugs.freedesktop.org/enter_bug.cgi?product=xorg
configure.ac:45: warning: PKG_PROG_PKG_CONFIG is m4_require’d but not m4_defun’d

checking for gcc option to accept ISO C99… -std=gnu99
./configure: line 10631: PKG_PROG_PKG_CONFIG: command not found
./configure: line 10731: –print-errors: command not found
./configure: line 10842: syntax error near unexpected token `XORG,’
./configure: line 10842: `PKG_CHECK_MODULES(XORG, xorg-server xproto inputproto)’

I have tried to install every package I can think of(xserver-xorg-dev, xutils-dev, libtool, and autoconf), but I seem to have everything current already.

Do you have any idea how I can make this make?

pfbach  on February 12th, 2011

Hi,
The AC INIT messages are just warnings.

Seems like you are missing pkg-config.

~$ sudo aptitude install pkg-config

I have created two log files showing what autoconf and configure prints out to terminal when executed. Take a look at them and compare your results if the pkg-config packaged doesn’t do the trick.

http://pfb.no/files/log_autoconf_2011_02_11.txt
http://pfb.no/files/log_configure_2011_02_11.txt

Hope this helps!

dakkar  on February 19th, 2011

Nice to see people using my patch! If you are using a recent xorg server, you may want to compile the code-remap-2.6.0 branch, though.

rafe  on March 4th, 2011

Thanks. I got busy and just now checked back and saw there were replies. It seems like I did need that package. I think it built okay, but I’m not getting any response out of the keys I tried resetting. I checked them with xev and got nothing.

If it is because of the “recent xorg server” I don’t know how to compile using dakkar’s suggestions.

pfbach  on March 5th, 2011

Hm,

Are you sure the module loaded properly:
:~$ grep evdev_drv /var/log/Xorg.0.log
Showing the line:
(II) Loading /usr/local/lib/xorg/modules/input/evdev_drv.so

Be sure to restart xserver / your session, in order for the module to load properly.

Also, perhaps try to stop lirc from running before testing with xev.

I have not gotten around to check out the new patch, but I think it will be much of the same approach.

I believe I will be merging onto the new patch in about a month or so when the new Ubuntu 04.11 (Natty Narwhal) starts to get ready.

rafe  on March 8th, 2011

Yeah, I get the same response with grep. I don’t use lirc (unless the standard mythbuntu install loads it). I just use the remote with the kernel support. It makes quitting external applications like games easier. I will be a little busy with classes for a while, but I will try out the new version when you get it ready. Maybe I’ll have some time to play with it by then.
Thanks fo9r your help.

Leave a Comment

You must be logged in to post a comment.