Raspberry Pi

So, I got myself a new gadget for christmas: A Raspberry Pi model B. For those of you who are not familiar: It’s basically a credit card sized computer with the computing power of a cell phone. Well, a somewhat slow cellphone to tell the truth. Not really the right device to do any fancy computing. One really cool thing though: the integrated BCM2835 chip has a built-in GPU with support for full HD video encoding/decoding and OpenGL 2.0 ES. And all at the power consumption of about 3.5 Watts. Perfect for a little, always on, media center to stream youtube videos and music or watch movies!

First thing, I loaded XBian, a Raspberry Pi optimized Linux distribution with XBMC preinstalled onto a memory card and booted up. Worked like a charm, out of the box you get a full media center solution with support for video playback and audio streaming and plugins that let you browse youtube and dailymotion. Sweet!

IR control

Up to that point I had used my mouse as input and this was getting a bit tedious: A mouse to control the Raspberry, one remote to control the TV and another one to control the sound bar. Way too many devices with a two year old kid running around ;). So I decided to simplify the system. The Raspberry has eight general purpose input/output (GPIO) ports. They can quite easily be programmed and thus used to control all sorts of electronic circuits. At first I hooked up an IR receiver like shown in this Adafruit tutorial. Once I had configured LIRC this allowed me to control XBMC with any remote control. Next I built an IR sender circuit like described here. This allowed me to send IR signals as well. As a final step I configured my programmable remote to mimic some device unknown to TV and sound bar and used lircrc in combination with irsend to control both. Let me illustrate with an example: The volume up button on my remote sends a volume up command which only the Raspberry can understand. Based on the contents of lircrc, the Raspberry then sends the appropriate volume up command for the sound bar. Likewise, a channel up command will be translated to a command for the TV. This allowed me to get rid of two of the three input devices as everything can now be controlled with one remote only.

I should probably add that I struggled for quite a while to get this to work reliably. Sometimes the TV would not react, sometimes multiple button presses were sent etc. Finally it turned out that the issue was related to the low processing power of the CPU: Under heavy load, lircd would be interrupted by the OS quite often in order to run other tasks and thus mistimed the IR impulses. The issue went away once I increased the priority of the lircd daemon.

More fun stuff

This project was so much fun that I started to to look into something else: What about supervising system and network stats? So I wrote a little python script that would grab internet transfer stats from my router, and temperature and free memory from the on-chip sensors in the Raspberry. The script would run every 5 minutes and log the results to a mysql database. I then installed the apache web server and made a little website that shows the data in some neat charts. Some weeks later I also hooked up a temperature and humidity sensor to one of the free GPIOs.

And as the last project (for now 🙂 ) I built a custom tracker for my cellphone: I configured my phone to send a HTTP POST request with the current location to my public IP address (which I set up via dyndns). A php script then extracts the location and stores it to a database. Another small webpage then displays the data via the google maps API.

stats tracking1

And that’s it for now. Definitely a lot of fun and a nice departure from graphics programming. Note that I’ve left out a lot of the gory details, like the components in electronic circuits, or patching the lirc GPIO driver to fix some problems with IR inference from energy saving lamps. Don’t hesitate to contact me in case you’re interested and I can send you some more details.

MacBook Dual Boot

I recently replaced the Superdrive of my MacBook Pro with a regular HDD in order to add some disk space to my chronically full SSD. Installation went fine until I came to the point where I wanted to put Windows 7 on the new HDD: Windows simply refused to boot. I tried all sorts of rescue tools, boot managers, etc but no luck. Until I stumbled upon the following instructions in the Apple discussion forums:

  1. Insert Windows CD and boot to normal OSX.
  2. Run Boot Camp, partition your OSX drive and wait for it to reboot.
  3. When MacBook goes to reboot hold down power button until it shuts off.
  4. Swap out OSX drive in primary HDD location with purposed Windows HDD.
  5. Power on and delete all partitions, format and install Windows to new drive [Hold the option key on startup to boot from CD].
  6. I personally installed all updates and made sure Windows was running fine here. I was able to reboot and MacBook would power on straight into Windows. I could hold down option key and see the Superdrive and the Windows Drive.
  7. Take out Windows drive, replace with OSX and run Boot Camp and remove partition, shutdown.
  8. Take out Superdrive, move Windows into Superdrive with HDD Caddy, replace OSX back into original position.

Prerequisites: Regular OSX drive in drive bay 0, superdrive in drive bay 1 (=standard config), Windows 7 DVD

Weird right? But anyhow, this worked like a charm for me and I finally have a fully working dual boot system again. Oh, and on a side note: if you plan to share data between MacOS and Windows via a HDD partition, your best format option is probably going to be exFAT: Windows can’t read hfs+, MacOS can’t write NTFS and FAT32 has some nasty limitations like 4GB maximum file size.

WordPress Customization

After my work is done on XBox One game Ryse, I can finally invest some time in my blog again. Yay! For starters I have cleaned up the website code, as initially (due to time constraints) I had made all my changes directly to the wordpress source. Not a good idea, as these changes have to be painfully reapplied every time the software is updated.

Child Themes

A very convenient way to customize a wordpress site is the use of of child themes. The concept is simple: You create a new theme that inherits the settings of an existing theme and overwrite whatever you need to. To do so, simply create a folder for your theme in the wp-content/themes directory and put a file called style.css inside. Here’s the beginning of my style.css:

 Theme Name:     Twenty Eleven Customized
 Author:         Theodor Mader
 Author URI:     http://theomader.com
 Template:       twentyeleven
 Version:        1.0.0

@import url("../twentyeleven/style.css");

/* =Theme customization starts here
------------------------------------------------------------ – */

Note that the Theme Name and the Template entries are required. You can now overwrite the original theme’s styles by simply adding your code after the import statement.

Syntax Highlighter

I had also made quite some changes to the Syntax Highlighter Evolved plugin to better fit my blog’s style and contents. Fortunately the plugin is nicely customizable and with only a bunch of lines of code you can load a custom style sheet and custom syntax definitions.

In order to get a custom style sheet into syntax highlighter, you simply need to add a filter for syntaxhighlighter_themes and add the name of your style sheet the array of style sheets that gets passed in. Don’t forget to register your stylesheet with WordPress as well, for example via wp_register_style. Syntax definitions (or ‘brushes’ as they are called in Syntax Highlighter) can be added in a similar way via the syntaxhighlighter_brushes filter. Since these are java scripts they also need to be registered with WordPress via wp_register_script. For the sake of simplicity, I added the php code to functions.php of my child theme and do the script/style registration via the init action. Here’s the relevant code from my functions.php:

////////////// syntax highlighter customizations /////////////////

add_action( 'init', 'sh_register_customizations' );
add_filter( 'syntaxhighlighter_themes', 'sh_add_custom_style' );
add_filter( 'syntaxhighlighter_brushes', 'sh_add_custom_brushes' );
// Register with wordpress
function sh_register_customizations()
  $sh_customizations_uri = get_stylesheet_directory_uri() . '/syntaxhighlighter/';
  // customized sh style
  wp_register_style('syntaxhighlighter-theme-default_custom', $sh_customizations_uri . 'shCoreDefaultCustom.css', array('syntaxhighlighter-core'), '0.1');

  // custom sh brushes
  wp_register_script( 'syntaxhighlighter-brush-cg', $sh_customizations_uri . 'shBrushCg.js', array('syntaxhighlighter-core'), '0.1' );
  wp_register_script( 'syntaxhighlighter-brush-cppcustom', $sh_customizations_uri . 'shBrushCppCustom.js', array('syntaxhighlighter-core'), '0.1' );
  wp_register_script( 'syntaxhighlighter-brush-csharpcustom', $sh_customizations_uri . 'shBrushCSharpCustom.js', array('syntaxhighlighter-core'), '0.1' );

function sh_add_custom_style($themes)
  $themes['default_custom'] = 'Default Custom';
  return $themes;

function sh_add_custom_brushes( $brushes )
  $brushes['cg'] = 'cg';
  $brushes['cppcustom'] = 'cppcustom';
  $brushes['csharpcustom'] = 'csharpcustom';
  return $brushes;


Oh, and here’s a neat trick I picked up on another website: You can expand the syntaxhighlighter code boxes by adding for example width: 150%; (on hover) and a transition like transition: width 0.2s ease 0s; to the .syntaxhighlighter style.

.syntaxhighlighter {
    transition: width 0.2s ease 0s;

.syntaxhighlighter:hover {
    width: 150% !important;

Note that this scales up the boxes by a fixed 150% instead of the exact required size but unfortunately I haven’t found a way do to the proper scaling without some form of scripting. You can toggle overflow: visible; on hover but so far I couldn’t figure out how to make this a smooth transition via css alone.


New Project

Exciting stuff ahead: I’ve decided to start working on a new project!! To be honest: it’s about time, I haven’t worked on any personal stuff since my BSP tree sample and I’m itching to get my hands on some exciting project. Even better still: My friend Ryan Lewis, an amazing 3D artist and tech guy is on board as well!

So, what will it be? Well, this time I’m going to tackle something new: Skinned animation. A while ago, I’ve come across an interesting paper about using dual quaternions to represent rigid body motion. As we all know, unit Quaternions are an efficient way to represent rotations in space, eliminating a lot of the problems inherent to matrix representations.  Unit dual quaternions extend the space of representable transforms to include translations as well. As it turns out, interpolating between rigid body motions can be approximated by something as simple as computing a weighted average of the corresponding unit dual quaternions and a normalization of the result: which makes the use of dual quaternions for skinning very efficient and suitable for GPU implementation.

Another more recent paper that caught my attention is Crytek’s definition of QTangents. While based on the pretty straight forward idea of representing Tangent Space by a unit Quaternion, Crytek applied their engineering ingenuity and managed to losslessly compress the resulting unit quaternions down to four floating point components without introducing singularities. In their optimized setting this brings the data requirements for tangent spaces from eight 16bit floating point values down to four 16 bit floating point values. Doesn’t sound like much, but consider the hundred thousands of vertices that get pushed through the graphics pipeline every frame. And remember, on consoles every byte of main and video memory counts!