Showing posts with label Ubuntu. Show all posts
Showing posts with label Ubuntu. Show all posts

Thursday, May 19, 2011

Teaching Dogs Tricks

Or, more hard work involving Ubuntu, LIRC, XBMC and my Revo 3700. The dog in question specifically being  my cheap tat probably fake USB IR receiver - the "Fintek  F71610A or F71612A" aka "HP P/N 5187-4593" aka "Model OVU400102/71". This came supplied with a matching MCE remote, but seen as I've already wasted far too long making that one work, I thought why not waste additional precious life and make it work with via my existing TV remote as well?

Step 1a: Go look for an existing remote configuration file.

A full set can be found at the LIRC website and a reduced set in  /user/share/lirc.

Of course my TV is a no-name ("Technika")  item I got from Tesco so impossible to tell if the remote is already supported, because I have no idea what it is because it has no label. This will clearly take longer than it should.

Step 1b: Capture some output from the remote
Open this existing XBMC configuration file in file in an editor:
user/share/xbmc/system/lircmap.xml
Find in that file a section that starts a bit like this:
    <remote device="linux-input-layer">
    <altname>cx23885_remote</altname>
    <altname>devinput</altname>
        <left>KEY_LEFT</left>
        <right>KEY_RIGHT</right>
What you are interested in are two things:
  1. Tthe semi-meaningful names for remote buttons, (e.g. "KEY_LEFT", KEY_RIGHT") that are understood by XBMC  etc.
  2. The names of the remotes that XBMC understands (e.g. "devinput")

In a terminal execute:
sudo irrecord -d /dev/lirc0 lircd.conf.tmp 
 And follow the instructions. There's three phases:
  1. Mash buttons on your remote. Dots (80 of them) get printed as long as a button is pressed
  2. Mash more buttons on your remote. Dots (80 of them) get printed once per press
  3. Type in a name of a button (e.g. "KEY_LEFT" - see handy list you made previously) -  then press that button on your remote and it will be captured.
At the end of this, you'll end up with a file called lircd.conf.tmp which will contain the captured remote data.

Edit this file  to give your remote a name that XBMC will understand, i.e. find the line:

 name lircd.conf.tmp
and change it to
  name devinput

The captured data was in "raw" mode, we will analyse the data into something moire meaningful and at the same time copy the data to somewhere more appropriate. Change "technika" to something more appropriate for what you have.

$ sudo mkdir /usr/share/lirc/remotes/technika
$ sudo -s 'irrecord -a lircd.conf.tmp > /usr/share/lirc/remotes/technika/lircd.conf.technika'



Step 2:Check if the remote is indeed supported
I'm not sure how effectively I did this. What I did was:
  1. Download the supported remote list archive from LIRC
  2. Mounted the archive in Nautilus
  3. grep'ed the archive with one of the codes I'd captured in the previous step.
The result was - It took forever and did not find a match. So, I'll call my remote currently  unsupported by LIRC.

Step 3: Let LIRC know about the new remote

Edit the configuration file at /etc/lirc. It should already have a line to include the "mceusb" remote, you need to add a second line to include the new one also

#Configuration for the Windows Media Center Transceivers/Remotes (all) remote:
include "/usr/share/lirc/remotes/mceusb/lircd.conf.mceusb"

#  tesco technika TV
include "/usr/share/lirc/remotes/technika/lircd.conf.technika"

And then re-start LIRC so it picks up the new configuration:

$ sudo /etc/init.d/lirc restart

You can test it works in a terminal using:

$ irw 

And pressing some buttons on the remote, you shoukd see their assigned names appear in the terminal. CTRL-C on the keyboard stops irw.
Step 4: There is no Step 4.
You should be now able to start up XBMC and your operate it with the new remote. 
Note that there is a number of possible ways to do this, using different naming conventions - you could for example give your remote a more meaningful name than "devinput" but I've chosen this method because it's the simplest way to add a single remote that involves the least number of files you need to maintain. This helps when trying to move or update XBMC. 
Another several hours of my life spent reading incomprehensible manuals and editing text files. Lucky it's so much fun.

Friday, May 6, 2011

Tightwad + Ubuntu = Agony.

So I recently bought this to control my Ubuntu based XBMC for  a whole 18 US dollars off of that e-bay:
It says "HP" on it. Obviously Genuine

I plugged my tightwad remote into my tightwad computer which runs Ubuntu 10.10 and predictably it didn't work. Both because it's cheap junk and Ubuntu is designed to test the most patient amongst us. I blame myself for all of this, you know.

So, the not so obvious first step is to install LIRC, the Linux remote control software because it just is.
sudo apt-get install lirc
You will get a funky little text based installer asking you to choose what type of device you have. Instead of guessing, you want to choose "Windows Media Center Transceivers/Remotes (all)" for the  remote and "None" for the transmitter.

Did that work? Of course not.

Next thing is to do is find out what it really is in the box.
user@Revo:~$ lsusb
Bus 003 Device 004: ID 1934:5168 Feature Integration Technology Inc. (Fintek) F71610A or F71612A Consumer Infrared Receiver/Transceiver
Oh yes, the well known HP "Fintek" thingy. A bit of googling tells me that this is a generic part which is a single chip USB / IR solution. You need to add a tiny memory chip to it to get it to report another name (you know, like "HP" or "Microsoft"); something LIRC may recognise. Amusingly, the difference between the F71610A and the  F71612A is that one is a transceiver and the other a receiver only; except they are the same part and you enable the additional functionality by adding a resistor.

The problem then is not all Linux - these knock-off devices are being put on the market without the proper identification because it saves a few pennies. So, I may now know what it is but lamentably Ubuntu 10.10 does not have a scooby doo. How to fix this. Who can tell. Well, me after a bit (lot) of hunting around on the Internet.

The first problem is; this may be fixed in future versions of the Linux kernel, but it's not fixed in the kernel I have, and it's unlikely to be fixed as there's been a change in the way LIRC handles things. It used to be a "kernel extension" and now it's "in kernel". And of course it's much harder to change the new "in kernel" module. So we'll go back to doing it the old way.

First thing to do is blacklist the new kernel module so it won't load any more:
sudo sh -c 'echo "blacklist mceusb" > /etc/modprobe.d/blacklist-mce.conf'
That'll show it.
Next we need to add the Fentek device (ID 1934:5168) to the old kernel extension and that means <sigh> we need to re-compile it. Get the source code first:
sudo apt-get install lirc lirc-modules-source
Then you need to edit the file /usr/src/lirc-0.8.7~pre3/drivers/lirc_mceusb/lirc_mceusb.c adding the following lines into the big structure of similar entries:
/* Crappy Fintek based Chinese Remote */ {USB_DEVICE(VENDOR_FINTEK, 0x5168) },
Then do the actual build and install of the old style kernel module:
sudo dkms remove -m lirc -v 0.8.7~pre3 --all
sudo dkms add -m lirc -v 0.8.7~pre3
sudo dkms -m lirc -v 0.8.7~pre3 build
sudo dkms -m lirc -v 0.8.7~pre3 install
Hang on, we are getting there... And finally tell LIRC to load the old fashioned kernel extension instead of the new one; in file /etc/lirc/hardware.conf change the line:
REMOTE_MODULES="lirc_dev mceusb" 
to:
REMOTE_MODULES="lirc_dev lirc_mceusb"

You then need to restart and if you made no mistakes (hah!) it will work.

The final thing you need to do with this remote is to change the key mappings a bit, it has a single "Play/Pause" button where it looks like others have separate buttons. This means that within XBMC neither is detected.

I fixed this by modifying the file /usr/share/xbmc/system/lircmap.xml There is probably a better way of doing this by changing something in your user folder but I don't know what that is.
Two lines should be changed in the  <remote device="mceusb"> section. Before:

<play>Play</play>
<pause>Pause</pause>
and after:

<play>PlayPause</play>
<pause>PlayPause</pause>
Several wasted hours later it should work as you hoped!