Summer Nights

A blog on embedded and real-time systems as well as on general computing issues

Configuring PC-39 Remote Control from ASUS MyCinema P7131 for XBMC

You have to understand the mechanism first:

1. The xbmc recognizes lircd as a generic remote control.
2. lirc further can connect to various remotes based on configuration in /etc/lircd.conf and present them as lirc remote to xbmc.

Now, first of all, you have to know what is the name of your remote device in linux. For this, you need to install input-utils:
apt-get install input-utils

Now when you say:
lsinput
it shows you all the input devices on your system. In my case, among other, I see:
/dev/input/event6
bustype : BUS_PCI
vendor : 0x1043
product : 0x4876
version : 1
name : "saa7134 IR (ASUSTeK P7131 Hybri"
phys : "pci-0000:05:00.0/ir0"
bits ev : EV_SYN EV_KEY EV_REP

This shows that the remote is indeed connected to the system and recognized as /dev/input/event6 device. This device number may change among different boots. We shall fix it by a trick in the lirc configuration.

Now if you want to see whether the events from your remote are being received by the system or not, issue the following:
input-events -g -t5 6
This shows the events received from event6 device with a 6s timeout. Press the buttons on your remote and you should see the codes received on the console.

If you want to see how the remote is mapping keys to keycodes, then isssue the following command:
input-kbd 6 > keyMapIR.txt
where 6 indicates the device id. You might have a different one.

In case, you decide to change this encoding then you can change the keycodes in the keyMapIR.txt file and upload it back to the remote as:
input-kbd -f keyMapIR.txt 6
But normally this will not be required.

Now that you know that your device is connected and working properly, we can proceed to install lirc.
apt-get install lircd
During its installation, please choose the appropriate remote make. In my case, I chose ASUS MyCinema. That sets it. Now lirc waits for a connection on a given address. We do not go in this detail. If you look in the /etc/lirc/lircd.conf, you would see something like:
/usr/share/lirc/extras/more_remotes/asus/mycinema.conf
After tweaking, I have this file as following:
begin remote
name lirc.conf
bits 16
eps 30
aeps 100
one 0 0
zero 0 0
pre_data_bits 16
pre_data 0x8001
gap 135991
toggle_bit_mask 0x80010188
begin codes
Rec 0x00A7
Close 0x0074
Prev 0x019C
Stop 0x0080
Next 0x0197
Rew 0x00A8
PlayPause 0x0077
Fwd 0x00D0
Up 0x0067
Down 0x006C
Enter 0x8001001C
Left 0x0069
Right 0x006A
Vol+ 0x0073
Vol- 0x0072
Ch+ 0x0192
Ch- 0x0193
Back 0x00AE
1 0x0002
2 0x0003
3 0x0004
4 0x0005
5 0x0006
6 0x0007
7 0x0008
8 0x0009
9 0x000A
FullScreen 0x0174
0 0x000B
Recall 0x0070
Tv 0x0179
Video 0x0189
Home 0x0066
Dvd 0x0185
Picture 0x016E
DvdMenu 0x008B
Radio 0x0181
Music 0x0188
Mute 0x0071
end codes
end remote

Please note that the names of the buttons have been changed a bit to match with the xbmc configuration. Now after changing this file and having restarted lircd, you should issue irw command and press buttons on the remote to check the proper encoding of the keys by lirc. If everything is perfect, then we can now proceed to the xbmc configuration.

The file that we want to edit is /usr/share/xbmc/system/Lircmap.xml. Here you should add a section like the following:
<remote device="lirc.conf">
<play>PlayPause</play>
<stop>Stop</stop>
<forward>Fwd</forward>
<reverse>Rew</reverse>
<left>Left</left>
<right>Right</right>
<up>Up</up>
<down>Down</down>
<select>Enter</select>
<pageplus>Ch+</pageplus>
<pageminus>Ch-</pageminus>
<back>Back</back>
<menu>DvdMenu</menu>
<title>Play</title>
<info>More</info>
<skipplus>Next</skipplus>
<skipminus>Prev</skipminus>
<display>Teletext</display>
<start>Home</start>
<record>Rec</record>
<volumeplus>Vol+</volumeplus>
<volumeminus>Vol-</volumeminus>
<mute>Mute</mute>
<power>Close</power>
<myvideo>Video</myvideo>
<mymusic>Music</mymusic>
<mypictures>Picture</mypictures>
<mytv>Tv</mytv>
<one>1</one>
<two>2</two>
<three>3</three>
<four>4</four>
<five>5</five>
<six>6</six>
<seven>7</seven>
<eight>8</eight>
<nine>9</nine>
<zero>0</zero>
</remote>

The device name “lirc.conf” is the same that you see when you run irw command. You can see that the keys correspond to the keys in lircd config file.

Finally, we want lircd to always connect to the right device even if its device number changes after reboot. To this end, we need to change the /etc/init.d/lirc as follows:

build_remote_args ()
{
REMOTE_ARGS="$*"

#For remote only detection support, we need
#both REMOTE_DEVICE and TRANSMITTER_DEVICE undefined
if [ -z "$REMOTE_DEVICE" ] && [ -z "$TRANSMITTER_DEVICE" ] && [ -c $dev ]; then
REMOTE_DEVICE="$dev"
fi

#If we have a REMOTE_DEVICE or REMOTE_DRIVER defined (either because no devices
#were defined, OR if we explicitly did), then populate REMOTE_ARGS
if [ ! -z "$REMOTE_DEVICE" ] || [ ! -z "$REMOTE_DRIVER" ]; then
if [ -n "$REMOTE_DEVICE" ] && [ "$REMOTE_DEVICE" != "none" ]; then
REMOTE_ARGS="--device=name=$REMOTE_DEVICE $REMOTE_ARGS"
fi
if [ -n "$REMOTE_DRIVER" ] && [ "$REMOTE_DRIVER" != "none" ]; then
REMOTE_ARGS="--driver=$REMOTE_DRIVER $REMOTE_ARGS"
fi

#Now, if we ALSO have a transmitter defined, add some args
#To make the first lircd listen up
if [ ! -z "$TRANSMITTER_DEVICE" ] || [ ! -z "$TRANSMITTER_DRIVER" ]; then
REMOTE_ARGS="$REMOTE_ARGS --listen"
fi
REMOTE_ARGS="--output=$REMOTE_SOCKET $REMOTE_ARGS"
fi
echo $REMOTE_ARGS
}

whereas $REMOTE_DEVICE is defined as REMOTE_DEVICE=’saa7134*’ in /etc/lirc/hardware.conf. This step makes sure that after a reboot, the lircd always connects to the IR device regardless of its device number assigned by linux kernel.

Just in case it is of help to someone, here is my /etc/lirc/hardware.conf file:

# /etc/lirc/hardware.conf
#
#Chosen Remote Control
REMOTE=”Asus MyCinema P7131″
REMOTE_MODULES=””
REMOTE_DRIVER=”devinput”
REMOTE_DEVICE=’saa7134*’
REMOTE_SOCKET=””
REMOTE_LIRCD_CONF=”asus/mycinema.conf”
REMOTE_LIRCD_ARGS=””

#Chosen IR Transmitter
TRANSMITTER=”None”
TRANSMITTER_MODULES=””
TRANSMITTER_DRIVER=””
TRANSMITTER_DEVICE=””
TRANSMITTER_SOCKET=””
TRANSMITTER_LIRCD_CONF=””
TRANSMITTER_LIRCD_ARGS=””

#Enable lircd
START_LIRCD=”true”

#Don’t start lircmd even if there seems to be a good config file
#START_LIRCMD=”false”

#Try to load appropriate kernel modules
LOAD_MODULES=”true”

# Default configuration files for your hardware if any
LIRCMD_CONF=””

#Forcing noninteractive reconfiguration
#If lirc is to be reconfigured by an external application
#that doesn’t have a debconf frontend available, the noninteractive
#frontend can be invoked and set to parse REMOTE and TRANSMITTER
#It will then populate all other variables without any user input
#If you would like to configure lirc via standard methods, be sure
#to leave this set to “false”
FORCE_NONINTERACTIVE_RECONFIGURATION=”false”
START_LIRCMD=””

13 Responses to “Configuring PC-39 Remote Control from ASUS MyCinema P7131 for XBMC”

Leave a Reply to Habo Cancel reply

Your email address will not be published. Required fields are marked *