Jilt - a library to read the sudden motion sensor on Apple Powerbooks and MacBooks using Java

Apple added a wonderful feature to its recent laptops - an internal sensor that can measure the tilt and gravity. They do this in order to protect the data on the hard disk; in case you drop your laptop, the operating system can quickly shut down the hard disk before the computer crashes on the floor.

Of course, such a sensor can do a lot more, and it would be a pity to use it only for computers that crash on the floor. So many people created nice little applications, like the carpenters scale widget, the rotating windows hack or the all-purpose Lilt software.

Some time ago I hacked together a JNI library for Java in order to make it possible for our geometry software Cinderella to read the data from the sudden motion sensor. This enables us to have more realistic physics simulation - the gravity in the simulation corresponds to the real gravity!

Unfortunately, the interface changed for the new MacBook Pro computers, and so we decided to remove this feature from the version of Cinderella released in June 2006. However, some weeks ago I stumbled across the Unimotion library and I gave it another try. The result is a JNI library for Java that should work on all Apple computers that have a sudden motion sensor. I could test it only on two models, however, so I'd love to get some feedback.

Demo Video

http://www.youtube.com/v/aM0PrEu-xO8

Download

The jilt library itself is available here, it is licensed unter LGPL, as is the unimotion library from where I copied most of the code.

Documentation

Include the jar file into your classpath and the libjilt.jnilib in your native library path and call de.cinderella.mac.AMSReader.getAMSType() to get an integer that represents the type of the sudden motion sensor. Then call de.cinderella.mac.AMSReader.getAMSData(int type, int[] out) with this type and a 3-integer array. This array will be filled with the sudden motion sensors x-,y-, and z-data.

You can also use
java -jar AMSReader.jar
on the command line to retrieve the current data of the sensor.

Bug reports etc.

Please mail me if you have any suggestions, bug reports, feature requests or whatever.

Further links

Several other people have done similar things, for example Daniel Shiffman. His approach uses the original unimotion library, which seems to make more sense.

Powered by MediaWiki