Monthly Archive for January, 2012

Access the mac sudden motion sensor with an AIR native extension

AIR on mobile enables you to access the accelerometer of the mobile device. But what about the motion sensor in your macbook / macbook pro computer on the desktop? All macbooks come with a “sudden motion sensor”, which shuts down the hard disk when the laptop moves too much.

I wrote an AIR native extension, to access this sensor information in AIR on OSX. I tried to mimic the Accelerometer API as much as possible, and make it easy to use in your AIR application.

You can check if the SuddenMotionSensor is supported on your mac, set the update interval and listen for accelerometer events:

if(SuddenMotionSensor.isSupported)
{
	suddenMotionSensor = new SuddenMotionSensor();
	suddenMotionSensor.setRequestedUpdateInterval(50);
	suddenMotionSensor.addEventListener(AccelerometerEvent.UPDATE, accelerometerUpdateHandler, false, 0, true);
}

You can then access the accelerometer info in the event handler:

private function accelerometerUpdateHandler(event:AccelerometerEvent):void
{
	trace(event.accelerationX, event.accelerationY, event.accelerationZ);
}

Download the sources & demos here, and have fun!

Accessing the kinect in javascript through websockets

Good morning all! (or evening, night, … depending on when you read this post of course). As you might know, I’ve been working on AIRKinect (as3nui.com) and I’ve got a side project AIRServer aswell (which allows you to setup air as a socket server, including websocket support).

Wouldn’t it be fun, to combine these two projects in a demo, so you can access the kinect information through a websocket? That’s exactly what I did. You run a desktop application on your computer, which is responsible for accessing the kinect, and exposing the skeleton information over a websocket. Using a javascript client, which supports websockets, you can connect to that server, and use the skeleton information in the javascript client :-)

In this demo, I’m just rendering the skeleton points in a canvas element, using three.js.

I’ve uploaded the sources and included binary installers for the desktop application (windows 7, OSX Lion). What you’ll need to do is install & launch the desktop application, and click on the “start server” button to listen for websocket connections on the given port. Make sure you’ve got the kinect sdk installed on your computer (windows) or openni on OSX.

Using the javascript client, you connect to your ip (if you’re testing on the same ip, 127.0.0.1 should be fine), and you can start dancing in the canvas element :-).