Thinkpad Accelerometer: I did it!

Quick update: I did it! I dug in a little further and solved the problem - turns out wrapping sensor.dll was the right approach after all.

However, it was quite a learning experience. It turns out that JNative comes with a bunch of pre-wrapped windows libraries including all of kernel32.dll's exports. It also turns out that JNative has a utility method that enumerates a DLL's exports (although it remains silent on expected arguments, alas). It also turns out that working with kernel32.CreateFile was a dead end (which I discovered only after trying to run the Perl and first version of the C# code on my machine.) Perhaps that strange file hand \\.\ShockMgr was for older thinkpads, I dunno.

Now I need to program a game to use the data. But first I need to write a calibration routine. It's funny how similar 2D accel data is to a joystick (it's analogue data which measures force)...

...and so I have discovered another example of a wildly over-designed Java API, called JInput. Check it out: (javadocs) (project home) (getting started)

JInput comes with it's own sizable JNI baggage, apart from a silly API, so I think I'll skip it for now. I may look at it later for examples on how to do high resolution polling with JNI if I need that.

Future directions: I think it would be great to get this working on Linux. I know that accel data is present in 2.6 kernels. It would also be cool to get this working on powerbooks (and what's really cool is that I guess they have a 3rd axis). In fact it looks like that would be easier because the code already exists:

Eventually I'll get something running on the iPhone, too. :)

Do you want to see the code? You can check it out at sourceforge. Here are some handy URLS: (project page) (code) (svn access)

Note that I tacked on a DLL export routine to main() for giggles.

I'll be integrating with the included space invaders code, and perhaps JInput, in the coming weeks.

No comments: