Thursday, 8 December 2011

Fun With LEDs

I've been replacing mains power gadgets around my house with battery-operated versions for a while now.  An average bedside alarm clock designed to run from the mains will consume up to 6 watts, or 50 kWh of power a year.  A travel clock designed to run from a AAA battery will run for the same period on the equivalent of less than 1 kWh a year.

The latest to be replaced is the bedside lamp.  I bought a mechanic's LED torch on a stand that ran off 3 D cells.  Worked reasonably well, but not as bright as I had hoped.  Unless it is pointing right at the book you are reading, it doesn't illuminate much.  So I decided to build my own LED-based lamp, using one of these:

That's a Cree Super Bright White LED.  100 lumens of white light, driven by 3 volts @ 350 mA, with a beam angle of 90 degrees. For comparison, a traditional 60 watt light bulb puts out 800 lumens. Here's the finished product:

The circuit is built inside a box with a clear lid, pointing straight up.  The original plan was to put a diffuser on top of the box to spray light in all directions.  I tried various diffusers, but the best was a bottle of clear marbles:

Turned out I didn't need the diffuser after all.  100 lumens across the 90 degree beam angle spread means that sitting on the bedside table, pointing straight up at the ceiling, it lights up the whole bedroom.  More than enough to read by.  And then some.

Power consumption is 1 watt, and should get about 30 hours on the two D cell batteries.

Parts list (with Jaycar part numbers):

    ZD-0442 - Cree XR-E Super Bright White LED (or Warm White ZD-0444)
    HH-8580 - Heatsink for LED
    AA-0590 - LED driver module, 3V to 350 mA
    PH-9218 - D cell battery holder x 2
    ST-0554 - Toggle switch
    HP-9556 - Veroboard PCB
    HB-6248 - Polycarbonate box with clear lid
    HP-0815 - Rubber feet
    Optional: 25 degree collimator lens (HP-1297)
    Mounting posts/spacers/nuts for the PCB
    Double-sided mounting tape for the battery holders

Total cost of parts is about AUD$90, batteries not included.  And here is the circuit diagram:

If you use the collimator lens to focus the light upwards, then you'll also need a diffuser like the aforementioned bottle of marbles.  Or stand it on its side to use it as a directional torch!

Wednesday, 7 September 2011

Bug databases and git

I've been using ticgit-ng for my TV Guide project for a few weeks now.  It is a simple ticketing system that runs directly in your git repository on a hidden ticgit branch.  Very nice.  No need to set up a separate bug database - just type ti list or ti new and you're off and racing.  There is a web interface as well, but I didn't bother with that.

The tickets are stored as flat directories and files within the repository.  Updates are normal git commits just like any other, and can be pushed up to your central repository.  A simple git pull followed by ti sync is sufficient to sync the ticket history with that pushed by someone else.  Here's the history and an example ticket for the TV Guide:
And here are my current open tickets, from ti list:

   TicId  Title                    State Date  Assgn    Tags
---------------------------------------------------------------
   daae6d Global search            open  07/09 rhys.we…
   1bc66e Export/import bookmarks  open  07/09 rhys.we…
   33bb19 Programme view widget    open  07/11 rhys.we…
   e37deb Underrun/overrun report… open  07/20 rhys.we…
   af4bbe Partial matching on a p… open  08/14 rhys.we…
   9e8ad6 Inverse bookmarks        open  08/19 rhys.we…
   0a96ec Category matching in bo… open  08/21 rhys.we…
   8a1e8f Android application      open  08/28 rhys.we…
   d04472 Improved 7 day view      open  09/02 rhys.we…
   b4d129 Sorting in bookmark list open  09/03 rhys.we…
   921e49 Partial match is hard t… open  09/05 rhys.we…

Now, ticgit is a little simple compared to "enterprise-quality" bug tracking systems.  There are only 4 ticket states: hold, invalid, open, and resolved.  And the users need write access to the git repo or the web interface.  So ticgit may only be useful for 3-4 person projects.  But that shouldn't stop someone making a larger system using the same concepts (ticgit is written in Ruby).

The main thing I like about using git for bug tracking is that it could solve an annoying problem with continuous integration (CI) systems.  At my previous job, our features and bug fixes were done in "staging repos", which the CI system would automatically integrate, build, and test.  Any compile or unit test failure would toss the staging repo contents back so that the mainline was not polluted.

All well and fine - except for bug reports.  When a developer marked a bug as fixed, there was a good chance QA would re-open it soon thereafter because the fix wasn't in their mainline-based build yet.  So developers routinely would add copious "Fixed in SHA-1 in staging repo blah, branch foo" comments to ward off bugs being reopened too soon.

With a git-based system, the update to the ticket could be made in the staging repo as well.  The mainline repo's copy of the ticket will still show "not fixed", but once the staging repo passes CI, the ticket changes will be merged as well.  At all times, the tickets reflect an accurate picture of what is in each staging repo and mainline.

The ticgit system isn't perfect though.  I'd actually prefer the tickets to be stored in the master branch, so that the commit that fixes the bug in the source code also updates the ticket state.  It is common to update the source code, documentation, and unit tests in a single SHA1 - there's no reason why the ticket state change couldn't be made part of the commit as well.

Sunday, 28 August 2011

Gamification, what is it good for?

I've been seeing ads on Sci-Fi Australia for a couple of weeks now for the Clustr application for iPhone and Android.  Apparently a social networking tool to talk to other sci-fi fans, rate shows, etc.  OK, whatever.  Such sites are a dime a dozen on the Internet.

But the thing that really pushed my "Why do I need this?" button was "Unlock exclusive Doctor Who badges".

Er?  What?  As best I can tell, they are pictures from the Doctor Who series that turn up as little pictures in the application once you've won a prize or something.  Ever heard of Google Images guys?  If I wanted a nice picture of my favourite Doctor Who character, then I'm hardly going to sign up to a service that wants the following privileges on my phone:
  • Full Internet access.
  • Fine GPS location.
  • Read contact data.
  • Modify/delete SD card contents.
  • Prevent phone from sleeping.
The whole application seems to be an example of Gamification, designed to harvest personal information in exchange for postage stamp sized icons that I could Google for myself.  No thanks.

Thursday, 11 August 2011

The PC is going away! Tablets rule!

So one of the original designers of the IBM PC said that the PC is going away.  Yeah right.

The PC is not going away.  The important thing about a personal computer is the personal, not the computer.  Whether it is the size of a wristwatch or a fridge, the most important thing about a PC is this:
Some control freak in the machine room cannot tell you what you can do with the computer and when you can do it.
That was the fundamental change that came with the Altair 8080 and the first IBM PC.  Not the form factor.  The PC gave everyone local processing and storage capacity that wasn't charged by the CPU second or the kilobyte.  Capacity that didn't need forms in triplicate to access.

A tablet is merely a desktop PC with the keyboard removed and distributed in a more mobile form factor.  It can run some types of applications very well, but others very poorly.  Reading other people's web pages is nice on a tablet.  Try creating a new web page for yourself and you'll want that keyboard back.

The biggest threat to the PC is not tablets or smartphones (which are just PC's).  It is cloud computing.  Because that puts the control freaks in charge of your data again, and reduces the device in your hand to little more than a dumb terminal.  Resist that to your dying breath.

The control freaks never went away - they have MBA's these days and think that computing is only useful if they can charge you by the CPU hour or the gigabyte, or charge someone else to insert ads into your data whenever you access it.  They are reshaping the entire computing world to serve their business models rather than your personal needs.

When someone talks about the death of the PC, they are trying to send you back to the world of mainframes, dumb terminals, and central control by crippling the devices you use.  Ignore them.

Sunday, 24 July 2011

What's on the tube?

For most of my life I've bought the Sunday paper for the TV guide.  Even recently, when the rest of the world switched to EPG's.  The main reason for the procrastination is that EPG's suck.

Typical EPG's display a tiny snapshot of the guide - a small number of channels and the next couple of hours of programs - all in a 40 point font designed to be visible to blind granny on the other side of the room.  Navigation with the up/down/left/right/OK buttons on a remote control is also a pain.  My kingdom for a QWERTY keyboard and a mouse!

Here are some use cases that EPG's fail at miserably:
  • Draw a circle around your favourite show.  Not to record it - just to remind you that you may want to watch it.
  • Tell you if a program has moved to a different timeslot.
  • "Oh cool!  Doctor Who is back on again!"
  • Noticing a new show out of the corner of your eye - the narrow two hour view of an EPG makes this impossible.

My attempt to improve upon EPG's is a Qt 4.7 based application for the desktop.  No DVR integration or HDMI control protocols.  Just you, your laptop, and the TV guide.



Plain boring desktop Qt application (patches to add a QML front-end welcome, although the whole point of this is taking advantage of the big screen).  The guide data for all TV free to air and Pay TV channels in Australia comes from OzTivo in XMLTV format, and is quite comprehensive.


Most of the use cases are handled with the "bookmark" feature, which displays your selected shows in a chosen color - altered slightly if the timeslot or day doesn't match.  The "7 Day Outlook" feature will display the bookmark matches for the next 7 days on a particular channel (or "All Channels" if you select it), which acts as your "viewing guide".

Code here: https://github.com/rweather/tvguide
Documentation: Press F1 for help.

Wednesday, 25 May 2011

Plang documentation and status report

A snapshot of the Plang documentation has been uploaded here.

Plang is coming along nicely.  The core language and builtin predicate set are fairly close to complete.  Performance is being worked on - I added an interpreter for the Warren Abstract Machine to speed up predicate execution (still more to do on that front).

A sample of the cool features that have been implemented to date:

I'm starting to shift my focus to writing applications in Plang to see how well it tackles the traditional logic programming problems of theorem proving and AI.  There's no point building a new language if it doesn't do the job better than the old one, after all.

Thursday, 14 April 2011

Balancing Deletions

Those who have known me for a long time are familiar with Rhys' First Law of Balanced Trees:

There is no such thing as a balanced tree delete algorithm.

Since it was first codified in 1989 the law has seen wide application: AVL trees, B-trees, red-black trees, you name it.  Open up any textbook on algorithms and you'll usually find something like this (Knuth, volume 3, section 6.2.4):

Exercises
...
7. [23] Design a deletion algorithm for B-trees.
"Algorithms in C++", Sedgewick, 1992 doesn't even mention deletion in the section on red-black trees.

Try it with your textbook.  Deletion is always left as an exercise for the reader.  I began to suspect that none of the authors had ever managed to implement deletion themselves.  But rather than admit ignorance they instead preferred to torture their students with mythical algorithms that were "too big to fit in the margin".

Over the years, I just gave up and added a boolean flag, "deleted", to every node and ignored the heap space cost.  Whenever someone has said "You're wrong, libfoobar implements it", I've looked and found only unreadable heuristic gobbledegook.  Nothing like a textbook treatment.  "Trust me!  It works!".  Sure it does Sonny.

Well, after 20-odd years, the law has finally been disproved.  Wikipedia's page on red-black trees actually includes code and a decent description of how deletion works.  After wading through the implementation and writing tons of unit tests, I can confirm that it does indeed work as advertised.

For the first time in my life I've actually implemented a balanced tree delete that actually works!  Woohoo!

I can now use red-black trees to do clause indexing for quickly locating a relevant clause amongst thousands (or even gabillions!) of Plang database facts.

Code here https://github.com/rweather/plang/blob/master/src/libplang/rbtree.c

References: Wikipedia, Literate Programs.

Saturday, 9 April 2011

Back on the air

It's been a while since I was last hacking on pure Free Software for myself.  My last big community project was DotGNU Portable.NET.  After some years working on Qt for Trolltech and then Nokia, I am now returning to my roots in the community.

These days I am playing around with logic programming languages.  In particular, a little thing I am calling Plang (pronounced "P lang", although I might sometimes humourously refer to it as "R-Prolog").  At the moment, it is basically an experiment - can we make a more productive logic programming language that uses the same semantic core as Prolog, but a completely new C-style syntax on top?  Dunno, but should be fun to find out.

More information coming in the future as the experiment takes shape.  For now, you can access the sources from the git repository at github.