You know what’s been missing from my life?

Yup.  Microcontrollers.

I got this idea several months back to create a few two-in-one effects pedals.  I had an EA Tremolo board and a one-knob reverb ready to go, and I thought they might pair nicely.  While I was doing the layout for the 1590BB enclosure I thought it would be cool if the pedal ran in two modes: Separate Mode, where each switch activated it’s own affect; and Together Mode, where the right switch activated both effects simultaneously.  I spent days thinking about this and mocking up switch diagrams, but all to no avail.  It was too complicated for me to figure out — at least with some room left in the enclosure for the actual effects boards.  For a while I had a brilliant plan to use optoisolators, and while they do simplify things, the switching was still a catastrophe.  That’s when I broke down and started thinking about microcontrollers.

Two weeks later, I have an Arduino Uno and a working prototype on breadboard.

arduino-dual-switch

Arduino Dual-Effect Superswitch

With the added flexibility of the microcontroller, I’ve added a third mode: XOR Mode.  Very exciting!  More details to come….

Three-Mode Dual-Effect Superswitch Prototype_bb

After the filesystem crash back in October I had 11 gigabytes worth of files without meaningful names just sitting in a lost+found directory. I was forced to come up with some creative ways to salvage data.

$ find lost+found/ -type f | wc -l
79370
$ du -sh lost+found/
11G     lost+found/

One of the first things I thought people might want access to would be their digital photographs, so I decided to cook up a little program to sort through the entire lost+found directory, find JPEG’s with a “Camera Model” EXIF tag and then copy them into an appropriate directory based on the value of that tag.

My first attempt used the shell, but that proved unacceptably slow so I fell back to my good friend Python. I installed the Python Image Library (python-imaging in Ubuntu), which I used to identify the JPEG’s (very fast, by the way), and which also has (kludgy, experimental) support for reading EXIF tags.

Here’s the code:

#! /usr/bin/python

import sys
import os
import Image
from ExifTags import TAGS
from shutil import copyfile

INDIR = 'lost+found'
OUTDIR = 'recovered-photos'

def recover_photo(infile, outdir):
    try:
        im = Image.open(infile)

        if im.format == 'JPEG':
            tags = {}
            exif = im._getexif()

            for tag, val in exif.items():
                lookup = TAGS.get(tag, tag)
                tags[lookup] = val

            dirname = tags['Model'].strip()
            dirname = dirname.replace(' ', '_')
            outdirname = os.path.join(outdir, dirname)

            if not os.path.isdir(outdirname):
                os.makedirs(outdirname)

            outfile = os.path.basename(infile)

            if not outfile.endswith(('.jpg', '.JPG')):
                outfile = outfile + '.jpg'

            outfile = os.path.join(outdirname, outfile)

            copyfile(infile, outfile)
            print infile, '->', outfile

    except IOError, v:
        try:
            (errno, errmsg) = v
        except:
            errmsg = v
        print infile, errmsg
    except:
        print infile, 'unknown error'

for root, dirs, files in os.walk(INDIR):
    for name in files:
        infile = os.path.join(root, name)
        recover_photo(infile, OUTDIR)

After running for 28m18s:

$ ls -l recovered-photos/
total 492
drwxr-xr-x 2 matthew matthew  4096 2008-01-26 13:58 C2100UZ
drwxr-xr-x 2 matthew matthew  4096 2008-01-26 14:18 C3100Z,C3020Z
drwxr-xr-x 2 matthew matthew 12288 2008-01-26 14:18 C860L,D360L
drwxr-xr-x 2 matthew matthew 36864 2008-01-26 14:17 C960Z,D460Z
...
$ find recovered-photos/ -type f | wc -l
9293
$ du -sh recovered-photos/
7.3G    recovered-photos/

9293 digital photographs all nicely sorted.

I’ll clean the code up, flesh it out with some handy command-line args and post a link to the updated version here as soon as I have a few spare cycles.

I got bold and decided to push matthewwhitworth.com into production today, and the bugs are already starting to shake out. The big problems seem to be in the theme I chose to use, miniBits. I liked it because of its clean layout and minimal graphics, but its small size also gave me the suspicion that some edge cases might not handle so well.

It turns out it’s more than the edge cases. About 15 minutes after pushing the site into DNS I noticed that the simple “view post” action produces invalid xhtml and displays the sidebar all wonky down at the bottom of the page.

So why didn’t I (or maybe the author) notice this earlier? Well, it’s only broken when you’re not logged in! I’ve been doing most of my development so far while logged in, either as myself or as admin, so the bug just wasn’t occurring. It’s also possible that he sidebar was off the bottom of my browser window and consequently I wasn’t seeing how broken it was when I was viewing the first couple of posts. Who knows? But now it’s gonna be out in the open for a while until I can fix it.

(Interestingly, the bug also doesn’t manifest itself at the demo site. The author freely admits that the theme has only been tested with WordPress 2.1 and hasn’t been maintained for a while. Could version compatability be the culprit?)

I also need to do a bit of Internationalization and Localization. The original author appears to be Italian, and the strings in the program are a mixture of Italian and English. That will actually give me a good “learn how to do something” project (as opposed to the more annoying “bug fix” project) .

So I’m pulling the theme code into bzr right now and getting ready to tweak. Hopefully, I’ll knock out the sidebar display bug tonight and get the site linked over to okcomputer.org so it can really go live.

UPDATE: I found and fixed the bug, and it’s a PHP classic: mixing your layout code inside conditionals. Down in the comments.php file I found two </div> tags were inside an if clause when they shouldn’t have been. A quick cut & paste moved them below the endif, and things are suddenly looking much better.