First revision

This is the first revision, untested. I will be backporting some of the
code to my 3d printer library.