June 19, 2009

Driver code: Just about finished.

Today and yesterday were a bit of a grind. Although I was being productive, the type of work I was doing wasn't exactly mentally stimulating. But it had to be done. A lot of the functions of the servos--almost all of them, in fact--are controlled by setting registers. There are a few variations, but in the end the bulk of the class falls into four or five private methods, and the dozens of public methods are only there to provide a user-friendly interface to the servo registers. I tried to find a simpler way, but the data varied too much to make anything very consistent--for example, some of the values are stored in two registers (for values over 0xFF) with the high-byte and low-byte swapped, some are restricted to a smaller range of values, and some are just bit flags. So the class is now chock full of tons of one-line functions, but it should be pretty simple to use--abstract enough for anyone to have an easy time using it, detailed enough for someone familiar with the servos to do anything they want, and secure enough to prevent anyone from breaking anything without explicitly trying to (for the most part).
I wouldn't call this completely finished--there are still one or two functions which I haven't implemented yet, there are a few aesthetic decisions that I might change, and I've still got to write most of the comments. But right now, for the project I'm working on, the code will do everything we need it to do. I feel accomplished.

No comments:

Post a Comment