Showing posts with label lirc. Show all posts
Showing posts with label lirc. Show all posts

Sunday, June 3, 2012

Configuring LIRC for HVR-1600 in Ubuntu 12.04




As promised, here is the recipe I followed to get LIRC working for my Hauppauge HVR1600 card on Ubuntu 12.04. This includes both the IR Receiver and the IR Blaster. This may work for other Hauppauge cards as well. The hard work was all done by others, for Ubuntu 10.04, this just serves as an updated reference for Ubuntu 12.04. As usual, this info is provided with NO warranty of any kind, so use at your own risk! It's assumed you have basic knowledge of Linux/LIRC/Scripts/etc.

The secret to the HVR1600 is the lirc_zilog kernel module. Once this kernel module is loaded and LIRC is configured, the HVR1600's IR capabilities should work.

Step One: Install LIRC

Step one is easy, just install standard LIRC! You can install it from the Ubuntu Software Center, or, install (or build) it from the command line if you are so inclined. The LIRC version that was installed for me was 0.9.0.

Step Two: Install lirc_zilog

(Note: you might already have lirc_zilog installed, see below).

This part is a bit tricky. The "proper" way to do it would be to install the lirc-modules-source package, apply the lirc_zilog patch, then reconfigure the package to build the kernel modules. The Ubuntu 10.04 recipe for this is here.

However, it does not yet appear that the lirc-modules-source package is available for Ubuntu 12.04. If it were, you would likely have to make some changes to the patch file to get it building under 12.04 (you might find some hints here).

As a shortcut, I found a complied version of lirc_zilog that appears to be 12.04 compatible here. There is a *.deb file for both i386 and 64-bit version (disclaimer: I can't vouch for the security of this site of the files). I find it strange that these files appear in this package but aren't actually in Ubuntu by default - but I'm sure there is an answer to that (if you know, feel free to share).

Download the version applicable to you and open the *.deb file with the Archive Manager (not the Ubuntu Software Center, which it opens with by default).

Find the lirc_zilog.ko file in the archive here: /lib/modules/3.2.0-24-generic/kernel/drivers/staging/media/lirc/

Extract it, and copy it to the following location in your system:
/lib/modules/3.2.0-24-generic/updates/dkms/lirc_zilog.ko

To load the module: sudo modprobe lirc_zilog

If all was successful, you shouldn't get any errors. At this point, you should be able to do lsmod | grep -i lirc_zilog and see:

lirc_dev               19204  1 lirc_zilog

Pro-Tip: To have lirc_zilog automatically inserted into the kernel on boot, add it to /etc/modules

Pro-Tip:  You might already have lirc_zilog installed. As an easy check, in a Terminal, go to /lib/modules and run find . -name "lirc_zilog*. If it finds lirc_zilog, already, you shouldn't have to copy one from another source. However, you'll still have to modprobe lirc_zilog to get it loaded and add it to /etc/modules to have it run boot.


Step Three: Install the HVR1600 IR Firmware files

I believe this can be found here, and a few other locations on the web.

This file needs to be copied here: /lib/firmware


Step Four: Configuration Files

You need to modify the following two files:

/etc/lirc/hardware.conf
/etc/lirc/lircd.conf


First, we modify hardware.conf to get lirc_zilog to be loaded. Add or modify the following lines (if necessary):

REMOTE_MODULES="lirc_dev lirc_zilog"
REMOTE_DEVICE="/dev/lirc0"
START_LIRCD="true"
LOAD_MODULES="true"

As for lircd.conf, again, a working one for my card was found here. I believe you can even put the relevant parts in its own file and use an include directive if you'd like.

Step Five: Take a deep breath

You're almost there! At this point, the following two things should work:

From a terminal, run "irw". Point your HVR1600 at the IR Receiver and press some buttons! If irw is working correctly, you should see some response, like:

$ irw
00000000000017a5 00 OK Hauppauge_350
0000000000001795 00 Down Hauppauge_350
0000000000001794 00 Up Hauppauge_350

This means your IR Receiver is working.

To test the IR Blaster, use the irsend command. At this point, it doesn't matter what code set you use, you just want to get the light to blink. For example:

$ irsend SEND_ONCE blaster 0_130_KEY_0

Note that the name "blaster" was the name chosen in "lircd.conf" from above....if you used another name insert it there.

Step Six: Final configuration

If the IR Blaster and Receiver are responsive, you're pretty much golden. All that remains is a bit of extra configuration.

To get the IR Receiver to do "cool" things (e.g. work MythTV and/or launch applications), you want to configure a ".lircrc" file. This should be in your Home directory.

Each command to be sent to a specific application has an entry that looks like this:

begin
prog = mythtv
button = LEFT
repeat = 3
config = Left
end

Each starts with "begin" and ends with "end".

button = The button on the remote which will cause the command
prog = The program to send the command too.
config = The command to send to the program
repeat = What to do when a key is repeated. 0 ignores repeats. A positive value (n) sends the command to the program every "nth" times.

Obviously, you need a lot of commands to get various buttons working. To get you started, here is a .lircrc file very similar to the one I use.

Pro-Tip: To get a remote button to start a program, instead of just being interpreted by one, set "prog" to irexec and "config" to the command line-method of starting the program. Remember that irexec must be running in the background for this to work, so you can set it up as an Ubuntu start-up application.

For the receiver, you need to figure out what code set the device you are sending commands to uses. One again, a script is already developed for this. This will send the Power command to the device. Once you see it respond, you've found the right code set. For example, in the command I have above, the code set being used was 0_130 code set.

You'll most often be using this to change the channel, but you can do other things as well. You can find some example change_channel scripts here. Don't forget that in order for MythTV change the channel, you need to configure the backend to post to the script.

At this point you should be in good shape, but you might require some additional modifications to get things "quite right" (geeks are never happy, are we?)

My only concern is that some point along the line, a Linux kernel change will cause lirc_zilog to stop working. But I'll cross that bridge when I come to it...either by getting it building from source or finding it compiled elsewhere. I hope you found this guide helpful.

References and special thanks!
http://wilsonet.com/?p=40
http://www.blushingpenguin.com/mark/blog/?p=24
http://www.bsntech.com/bsntech-blog-mainmenu-321/computers-mainmenu-281/1762-getting-your-hauppauge-hvr-1600-remote-control-to-work-in-ubuntu-1004-lucid.html
http://pkgs.org/download/linux-image-3.2.0-24-generic










Tuesday, May 29, 2012

Ubuntu 12.04: The Good. The Bad. The (Not So?) Ugly.

Hello friends!

I recently upgraded by home PC from Ubuntu 10.04 to Ubuntu 12.04. I decided to make a hardware change as well, specifically, upgrading my primary hard drive from a 320GB SATA to a 2TB SATA.

Now, I didn't actually "upgrade" the 10.04 to Ubuntu 12.04 in place, I installed a fresh copy of Ubuntu 12.04 on the 2TB drive and manually migrated my programs, settings and files over to the new system. I personally like to start with fresh installs when possible, and given all the custom modifications I had made to my system, I feared an upgrade would cause more problems then it was worth (if you've had a different experience, let us know).

I didn't take the choice of upgrading to Ubuntu 12.04 lightly. I knew I would have to upgrade 10.04 sooner or later, only having a year 10.04 support left, and didn't want to let it go until the last minute. Having heard a lot of dislike between versions 10.10, 11.04, and 11.10 (the Unity UI for example), I seriously considered switching to another distribution such as Linux Mint.

In the end, I decided to give Ubuntu 12.04 a try. From looking at the screen shots and reading the design philosophy, I decided Unity was worth a try. Even if I didn't like it, I knew I could always install another desktop on top, like classic GNOME, Cinnamon, or GNOME 3, without having to switch distros.

So far, I'm happy with what I see, and think I'll be sticking around with Ubuntu, at least for now. The future is always open though!

The Good


Off the bat, a lot of 12.04, including the GUI, impressed me. Install and format process was very fast, even on the 2TB drive. I haven't tried setting up a dual boot system (Linux only) but that has been extremely easy since at least 9.10 so assuming it's been kept up to date with newer versions of other OS's, I don't imagine much of an issue.

Nvidia Binary Drivers


Nvidia Binary Drivers were detected and installed out of the box, no configuration needed. This gave me access to 3D acceleration and advanced multi-display configuration - a must have for a HTPC. I did use the Hardware Drivers option to upgrade to the "bleeding edge" drivers, though rather this was necessary or not, I'm not sure.

HDMI Audio Support


Remember this post? Thanks to an updated ALSA, HDMI Audio worked out of the box too. They also fixed the under-enumeration problem present in 10.04. I immediately had a (single) HDMI audio option in the Sound Devices that I could select and move back and forth seemlessly, no fuss. Success!

New MythTV & HVR1600 support


Since one of the main purposes of the my machine is to use as a HTPC and DVR, I installed MythTV straight from the repositories, and no issues setting up my card. Just don't forget to add you cx18.conf file to /etc/modprobe.d :)

Webcam Support

In 10.04 I was never quite able to get my Webcam and my HVR1600 working together. In 12.04, they seem to both work happily, though I haven't tried unplugging the webcam yet (that may still cause some issues to be aware of)

Improved Third Party Software

Firefox and Thunderbird are installed by default. Maybe you don't like them, but I do. Skype works fairly well and is easily installable. The Ubuntu Software Center is really nice, so far I haven't had any need to use another package manager (though I may need to at some point).

The Bad


USB3.0


I never got USB3.0 working reliably on 10.04, and 12.04 doesn't seem to have improved much. Although the Linux kernel officially supports USB3.0, I'm guessing the there is something amiss with the drivers for my specific chipset (the 3.0 ports are build into the motherboard). I am certain the ports, cords and external hard drive are all USB3.0, but I've never gotten any more then a sustained 60 MB/sec (480Mb/sec, USB2.0) transfer speeds when connected to the USB3.0 ports. Worse, I get sporadic "unmounting" of the USB drive when connected over 3.0, and cannot remount without restarting the computer. I realize this is likely the fault of a driver, or missing kernel module (and less Ubuntu), but it's still irritating. Hopefully I can figure out the bottle neck and start getting reliable USB 3.0 support.

Flash

So basically, YouTube videos have a blueish tint. Yep, you heard me right. Apparently, this is a bug in Flash,  but since Adobe has officially discontinued Flash for Linux, with 11.2 being the last version, it is unlikely the bug will be fixed. Now, there are workarounds, the easiest being to disable hardware acceleration,  but come on, something like this shouldn't be necessary as now I have to drive my CPU hotter. 

Another bizarre issue with Flash if you are using dual desktops: Full screen sometimes only appears on your *primary* display, even if the originating window was on the second. Now, I didn't have this problem with YouTube (full screen was on the correct display), but I did have this problem with sites that used their own custom player based on Flash, such as video from the sites of TV Networks. I found a work around for this using gDevilspie (see this thread). But this only addressed the *position* of the window, *not* the size. so unless the two displays were running at the resolution, the full screen was cropped and I could only see the top-left portion. My only work around of this (for now) is to run both displays at the same resolution. 

Hopefully with Flash for Linux discontinued, Canonical (or someone out there) will do the right thing and take over the reigns of support Flash going into the future. Even if you wish Flash would just die, pretending it's already dead is not the solution to a good user experience.

LIRC

LIRC is a great program, unless your card just happens to not be supported. This isn't LIRC's fault, it tries its best, but for legal reasons there are certain remote they just can't support. Getting LIRC to work for my HVR1600 card was a *huge* pain on 10.04, requiring me to build a custom kernel module. I did eventually get it, but if memory serves, it took several months.

Unfortunately, my card *still* isn't supported in the newest version of LIRC with 12.04. Likely, it never will. On 10.04, I was able to build the kernel module thanks to the lirc-modules-source package and a very nice Fedora user, but it wasn't fun. Unfortunately, it appears lirc-modules-source is not available for 12.04! So until it is, I can't update the patch for 12.04, nor build my kernel module or use my IR Blaster/Receiver.

UPDATE!  I *have* gotten LIRC for my HVR1600 card working on 12.04! Without too much difficulty. I happened across a pre-complied version of the necessary module, lirc_zilog, here inside of a DEB file (32 and 64-bit versions available). I'll post a more comprehensive tutorial as soon as I have a spare moment :).

The (Not So?) Ugly

Unity

Hey, I like it. Been using it for a few weeks now and I find it pretty fluid and easy to use. The HUD feature is very cool. Now, now, I know what you are thinking...that damn Unity bar is glued to the left side!!! While I agree that, in principle, this was a poor choice on the part of the Unity developers, you have to remember that Unity is just one desktop environment. You aren't forced to use it, and there are even forks out there (or could fire one up yourself) to get it on the bottom if it's really important to you. Or use an alternative like Cairo dock, or another desktop environment. So it's not really a reason to abandon the distribution altogether, at least IMHO. And if you give it try, you might just like it too. While I do hope they add an supported option to move it in the future, for now I can deal.

X-Session Weirdness

In Ubuntu 10.04, I ran GNOME on two separate X-sessions, one of the PC display, and one of the TV display. I liked this better then running a single display on both, since applications seemed to handle it better (e.g. full screen Flash), even though it meant you couldn't move windows between displays (no biggie to me).

When I enabled dual X-sessions (with the Nvidia-config tool) in 12.04, I was very confused. On one display was the normal Ubuntu desktop, but on the other was just a pure white background with a "X" for a cursor. Obviously 12.04/Unity wasn't designed to handle dual X-sessions this way.

So, I flipped over to Twinview, to see if I could configure that the way I wanted. To my vast surprise, I found two separate desktops (complete with Launcher and top menu bar) just as if I was using dual X-sessions! But now, I had the ability to move windows between desktops. Pretty cool, considering I had been expecting something similar to way Windows handles extended displays, just making a blank window space on the other monitor, but no separate task bar.

So it seems like they tried to take the best of dual X-sessions and the best of Twinview (extended desktop) and munge them together (as a new form of Twinview). And honestly, it works pretty well, except for two problems I've found so far:

1) The "Flash" full screen issue I mentioned above
2) Applications don't quite "understand" it.

What I mean by #2 is that I'm used to being able to launch an X program on either GUI from the command line simply by setting the "DISPLAY" environment variable. Well, in 12.04 no such luck, the DISPLAY environment variable has the same value (0) regardless of what display you are on. So now, launching applications based on the X-session is a little trickier than it used to be - not a good thing. For the most part, applications do work correctly if you launch them on the correct display, but I haven't yet figured out how to launch an application on a specific display from the command line. Unfortunately, MythTV was one of the applications that didn't quite behave, it was showing up on the primary display regardless of what display I launched it from. No good - I need Myth on my secondary (TV) display. Thankfully I found an option in the MythTV appearance settings which allowed me to choose between display "0" and "1". Setting to 1 put it on the TV display....just as if I had set the environment variable. So there is some support similar to the old methods, but it appears to be application specific.

But sometimes (like when I'm running mythbackend), I *do* want it on the primary display. I used to have separate scripts that I could run for which display I wanted to appear on...but even trying to use the "--display" option on the mythfrontend command line, it goes to whatever display I set it to in the options. So, I have a workaround for now (setting the display option in the settings), but this is irritating...having a way to move it on the command line would be much preferred.

It's only been a few weeks, but so far I like what I see in 12.04 and find it a worthy successor to 10.04 (I usually skip non-LTS versions...due to the work involved with upgrading). So I'll be sticking with Ubuntu for now, and hope others out there enjoy it as well.

Have a great day!