monome/libmonome — pull request #19 by TheAlphaNerd (2011-12-06 04:00:25+00:00)
Title: Added Tilt Support for 40h

Modeled after the code you used for series.c and series.h

This pull request updates src/proto/40h.c and src/proto/40h.h with the necessary code to enable tilt on 40h devices. I decided to not use the AUX enable command, as done in the past, and opted to use a tilt.enable / tilt.disable message similar to what was done in series.c. This allows the 40h tilt to be backwards compatible with any code written for a series or mext device.

The only concern with this code is that the resolution on the tilt leaves much to be desired. The 40h had a 10 bit value for tilt... and I was able to measure a range of close to 128 discrete points from the raw serial data. I ended up dividing the 10 bit value by 4 to make a 8 bit value. This method allowed for the tilt values to center, the downside is that it becomes limited to less than 40 discrete points. Perhaps there is a better way to scale the numbers.