ADAM'S WEB PRESENCE

15 November 2008

Update on TwinHan remote for Mythbuntu 8.10

Filed under: General — adam @ 11:08 pm

twinhan remoteI’ve just upgraded my HTPC to the new Mythbuntu 8.10. I must say that setup is a helluva lot easier than previous versions of Myth although I found my ATI card did not work at all and I had to exhume an ancient nVidia card from my parts box. And I had to hack the xorg.conf file to make the TV output work so the setup is not 100% seamless.

Anyway, onto the odd device, my TwinHan remote control. Setting this up is much easier under Mythbuntu 8.10. Here’s the step-by-step:


Step 1 – Configure LIRC

Plug the IR receiver into a USB port. Wait a moment for it to register and then type the following command:

ls /dev/input/by-id

It should produce output like this. This step is just to verify the correct device name for the remote.

usb-Twinhan_Tech_Remote_Control_1111111-event-kbd
usb-Twinhan_Tech_Remote_Control_1111111-event-mouse
usb-Twinhan_Tech_Remote_Control_1111111-mouse

Now edit the file /etc/lirc/hardware.conf and enter values for REMOTE_DRIVER and REMOTE_DEVICE:

REMOTE_DRIVER="devinput"
REMOTE_DEVICE="/dev/input/by-id/usb-Twinhan_Tech_Remote_Control_1111111-event-kbd"

Due to a bug in this version of Ubuntu, you will also need to run the following command:

lshal | grep input.product

It will spit out a few lines of text. Verify that it produces a line like this:

  input.product = 'Twinhan Tech Remote Control'  (string)

Then edit the file /usr/share/hal/fdi/preprobe/20thirdparty/lirc.fdi and make it read like so:

<?xml version="1.0" encoding="UTF-8"?>

<deviceinfo version="0.2">
  <device>
     <match key="info.product" contains_ncase="Twinhan Tech Remote Control">
        <merge key="info.ignore" type="bool">true</merge>
     </match>
  </device>
</deviceinfo>

Finally, download this file:

lircd.conf

and put it in /etc/lirc/

At this stage, I had to reboot so that everything loaded properly. Once you have rebooted, you can test the remote control by typing:

irw

Now every time you press a key, you should see it printed on the screen. Press Ctrl-C when you are done.

STEP 2 – Configure MythTV commands

We are getting closer now. The next step is to set up a file called ~/.lirc/mythtv which contains the mappings between the keys on the remote and the functions in MythTV. Once again, I have already prepared this file which you can download here:

lircrc-mythtv

Rename this file to mythtv and move it to ~/.lirc/ Once that is done, restart MythTV. Here are the key mappings you will end up with:

Key Function
REC Record
TELETEXT OSD
RECALL MENU
PREVIEW INFO
REW/FFWD Forward/backward in MythMusic
CAPTURE Previous playlist item in MythMusic
RECORDLIST Next playlist item in MythMusic

STEP 3 – Configure MPlayer

The final step is to configure the mapping between the remote and the commands in MPlayer. Since MPlayer is a separate program, it needs to be configured separately to MythTV. To configure it, we need another lircrc file but this time is has to be called ~/.lirc/mplayer. Download it from here:

lircrc-mplayer

Rename it to mplayer and put it in ~/.lirc/ and that should be that! Here are the key mappings for MPlayer:

Key Function
MUTE Mute
VOL+/- Adjust volume
CH+/- Skip fwd/back 60 seconds
REW/FFWD Skip fwd/back 10 seconds
PREVIEW Show/hide subtitles
TELETEXT Show/hide OSD
TAB Cycle through audio tracks

If you do not like the key mappings I have chosen, you may edit the files in ~/.lirc. The format should be fairly easy to follow.


22 October 2008

Baud rate converter website is up

Filed under: General — adam @ 9:56 pm

www.serialgadget.comI’ve set up a simple website to hawk my RS232 Rate Converter. The product is now ready to sell. Hooray!

The address is http://serialgadget.com/


Currency Calculation in PHP

Filed under: General — adam @ 9:03 pm

Thanks to some help from Stack Overflow, the new and excellent Q&A site for programmers, I have put together a PHP class which can perform a currency conversion using up to date exchange rates pulled live from Yahoo. Here is the code for y’all to share:

<?php

// fx.php - PHP Code to convert currencies using Yahoo's currency conversion service.
// by Adam Pierce <adam@doctort.org> 22-Oct-2008
// This code is public domain.

class ForeignExchange
{
	private $fxRate;

	public function __construct($currencyBase, $currencyForeign)
	{
		$url = 'http://download.finance.yahoo.com/d/quotes.csv?s='
			.$currencyBase .$currencyForeign .'=X&f=l1';

		$c = curl_init($url);
		curl_setopt($c, CURLOPT_HEADER, 0);
		curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
		$this->fxRate = doubleval(curl_exec($c));
		curl_close($c);
	}

	public function toBase($amount)
	{
		if($this->fxRate == 0)
			return 0;

		return  $amount / $this->fxRate;
	}

	public function toForeign($amount)
	{
		if($this->fxRate == 0)
			return 0;

		return $amount * $this->fxRate;
	}
};

?>

Because it creates an object, that object will remember the exchange rate so it doesn’t need to look up the rate again and again if you want to do multiple currency conversions on the same web page.

Usage Example:

<?php

// Create an object to convert Australian Dollars to Euros.
    require 'fx.php';
    $fx = new ForeignExchange('AUD', 'EUR');

// This function formats a value with 2 decimal places.
    function fmtMoney($amount)
    {
        return sprintf('.%.2f', $amount);
    }

    $auPrice = 25.50;

    echo '<p>Your price is AU$'. fmtMoney($auPrice)
        .' which is approximately &euro;'. fmtMoney($fx->toForeign($auPrice)) .'</p>';
?>

…enjoy.


17 October 2008

Elastic Tabstops by Nick Gravgaard

Filed under: General — adam @ 5:55 pm

I’ve just been playing with the Elastic Tabstops plugin by Nick Gravgaard. I really like it. I like my code to look neat so when I write a block of code like this:

   $custFirstName = $_REQUEST['cust_first_name'];
   $custLastName = $_REQUEST['cust_last_name'];
   $custEmail = $_REQUEST['cust_email'];
   $custAddr1 = $_REQUEST['cust_addr_1'];
   $custAddr2 = $_REQUEST['cust_addr_2'];

I always try to neaten it up by adding spaces like so:

   $custFirstName = $_REQUEST['cust_first_name'];
   $custLastName  = $_REQUEST['cust_last_name'];
   $custEmail     = $_REQUEST['cust_email'];
   $custAddr1     = $_REQUEST['cust_addr_1'];
   $custAddr2     = $_REQUEST['cust_addr_2'];

Which is a little fiddly but I always do it because like I said, I like my code to look neat.

But now I have a tool which does it automatically. I’m very happy.

It will even handle proportional fonts so I’ve been experimenting with the decadent pleasure of coding in more beautiful type faces and still having everything line up.

Unfortunately it is only for gedit at this time (which is a fine text editor but just a text editor nevertheless). If this were available in Eclipse or MS Dev Studio, I’d be in heaven!


12 October 2008

Windows vs Linux when Changing Motherboards

Filed under: General — adam @ 8:30 pm

My new motherboardWell, here’s an interesting little tidbit. My home box is dual boot with Windows XP SP2 and Linux Ubuntu 8.04. My motherboard has been playing up recently so I got myself a new one, a Gigabyte GA-G31M-S2L. This is a budget board with a pretty plain-vanilla collection of peripherals.

After installing the board I chose to boot up Ubuntu first. I thought I’d probably need to install some drivers for the onboard audio, video and Gigabit Ethernet but no, it just worked! I was amazed. It would seem the days are gone when getting new hardware to work under Linux was a massive chore. I was so stunned I had to write a blog post about it. Even 3D acceleration worked immediately, no mess, no fuss.

Then I tried booting into Windows. Ha ha haha ha. Did it work straight up. Did it hell! I had to spend an hour mucking about with loading drivers and rebooting a million times.

Nowdays we have many cross-platform applications such as Open Office, GIMP, Firefox and so on. Add to this the increasing stability and simplicity of the Gnome desktop, Ubuntu is very much a serious competitor for Windows, not just some time in the future but right now.


3 October 2008

Centering and Scaling an Image on a Web Page

Filed under: General — adam @ 10:34 am

I want a web page which displays a single image. The image is to be scaled so it is as large as possible within the browser but without losing it’s aspect ratio.

I also want it to be centred (or centered if you are American).

After spending literally hours trying to do this with CSS and scads of nested div tags, I have decided it is not possible to do it this way. The alternative was to use Javascript to compute the size and position of the image.

Here is the final code which works on IE and Firefox:

<html>
<head>
<script>
function scaleAndCenter(id)
{
 img = document.getElementById(id);
 img.style.position = "absolute";

 if(img.width / document.body.clientWidth > img.height / document.body.clientHeight)
 {
  img.style.width = "100%";
  img.style.top   = (document.body.clientHeight - img.height) / 2;
 }
 else
 {
  img.style.height = "100%";
  img.style.left   = (document.body.clientWidth - img.width) / 2;
 }
}
</script>
</head>
<body style="margin: 0; background: black;">
<img id="image" src="myimage.jpeg" onload="scaleAndCenter(this.id)" />
</body>
</html>

20 September 2008

Bed Hair

Filed under: General — adam @ 11:09 am

Adam with bed hairI’m not my best first thing in the morning. Some evil person has been taking pictures…


14 July 2008

Gravatar support

Filed under: General — adam @ 10:54 am

Just a quick note that this site now supports Gravatars. So if you make a comment here and are registered over at www.gravatar.com, your picture will appear next to your comment like magic!


30 April 2008

No more advertising

Filed under: General — adam @ 8:36 pm

As you can see, I have removed all the Google ads from this blog.

This blog gets around 1000 page views per day and I’ve been running the ads for about a year and a half now. In all that time Google have not paid me anything. Not a cent! So they are gone.


17 January 2008

Multicomp on Linux

Filed under: General — adam @ 8:59 pm

Hey, Multicomp runs pretty good under Ubuntu using WINE!

multicomp-on-linux.png


« Previous PageNext Page »

Powered by WordPress