HOW-TO:Configure Gyration USB remote for Ubuntu

Introduction
There are several buttons on the Gyration Media Center Remote that work with XBMC out of the box, so to speak.

There are also some that do not.

This method uses the evrouter program to map the unused keys (or any key you wish, for that matter) to keyboard keys that XBMC uses.

This was written using Ubuntu 9.10 i386 with XBMC 9.11 installed from the svn ppa.

We are going to use evrouter to look at the two event devices associated with the Gyration remote, which are: /dev/input/by-id/usb-Gyration_Gyration_RF_Technology_Receiver-event-kbd /dev/input/by-id/usb-Gyration_Gyration_RF_Technology_Receiver-event-mouse

Also, since we're not using lirc, I am starting xbmc with the --nolirc option.

Install evrouter
The Ubuntu repositories do not have evrouter, but there is a .deb package available at the author's website, which this guide will use.

Download the package: Install the package:

Create configuration file for evrouter
You can use evrouter to dump the output of keys for devices. To do this, run this command: While the command is running, press the buttons on the remote, and the configuration will be generated. Here is what it should look like: The last part in the quotes, "fill this in," needs to be replaced with the desired action. According to the man page of evrouter, the action can be either a keyboard press, a mouse button, or a shell script. Please read the man page for more info.

Below is a file where every single button on the remote was pressed. The working buttons have been commented out, but they are there in case you want to change the default behavior. Evrouter can be configured on a per-window basis using the Window parameter in the configuration file. The example below is affecting all windows, so if you're using this in windowed mode in a desktop environment, you might want to put the window class or resource name in the quotes. I think it should be "xbmc.bin"

Copy this and save it wherever you want. I have it saved as ~/evrouter_gyration.txt which will be used later in this guide.

Set Up Sudo
Since root permissions are required for evrouter to do what it does, we will launch it using sudo. However, since this is going to be a part of a script, we need to make sure that the user that is launching XBMC is allowed to run evrouter without having to put in the user's password. To do this, use the command visudo with super user permissions: This will launch your editor to edit the sudoers file. To allow the user xbmc to run evrouter with super user permissions without a password, add this line: xbmc ALL=(root) NOPASSWD: /usr/bin/evrouter

Configure evrouter to start up with the X server
Evrouter needs to be started after the X server is running. To do this, I put it in the user's ~/.xinitrc file.

This was tested using mingetty to auto log in a user that has a file ~/.bash_login as follows: This will run startx as long as the login is not through SSH and X isn't already running, and will restart it if it dies. There may be better ways to do this, but that's not the discussion here.

Here is the user's ~/.xinitrc file:

Customizations
To change or customize the behavior of evrouter with your remote, you will need to figure out what you want a certain key to do. For instance, I want the My Music key on the remote to take me right to my music.

Using evrouter -d, the configuration for that key looks like this:

"Gyration Gyration RF Technology Receiver" "/dev/input/by-id/usb-Gyration_Gyration_RF_Technology_Receiver-event-mouse" none key/391 "Xfill this in!"

We need to populate an action where "fill this in" is written. Since we are replacing the remote button events with keyboard presses, we need to find which key will do that in the default keyboard keymap. The key on the default keyboard keymap for music is this: XBMC.ActivateWindow(MyMusic) Unfortunately we don't have that key launch_media_select, whatever that is. I guess we'll have to find an unused key.

Looking at the default keyboard mapping, the letter G is not used. So, to make the music key on the remote send that, replace "fill this in!" with the action XKey/G -- it should now look like this: "Gyration Gyration RF Technology Receiver" "/dev/input/by-id/usb-Gyration_Gyration_RF_Technology_Receiver-event-mouse" none key/391 "XKey/G"

I will now make a keyboard mapping in ~/.xbmc/userdata/keymaps/keyboard.xml to associate G with the action I want in XBMC. I did the same thing for some other buttons as well:

Closing Thoughts
In doing this, I learned that even though some of the buttons don't do anything, XBMC still sees them. You only need to make an evrouter key assignment if the XBMC debug log does not show a keypress. For me, it doesn't show anything at all with the My Music button without an evrouter mapping. Other buttons show something, but not a button id. For instance, here is what the MyTv button shows in the debug log without evrouter or lircd: 17:44:32 T:3077863296 M:1445896192  DEBUG: SDLKeyboard: scancode: 234, sym: 0, unicode: 0, modifier: 0 17:44:33 T:3077863296 M:1445896192  DEBUG: HAL: Device (/org/freedesktop/Hal/devices/usb_device_c16_2_noserial_if1_logicaldev_input) Condition ButtonPressed | media I don't know what to do with this. What I can do, however, is create an evrouter mapping.

So, to sum up, you only need an evrouter button mapping if the debug log does not show the button id with OnKey. If the button is shown in the debug log with the button ID, you can just map it with an xml file, like I did with back and the green windows key and the back button.