RSS

ShockDraw v1.0 Released

Sun, Jul 13, 2008

ShockDraw

ShockDrawShockDraw is a proof of concept program that I wrote to learn how to read the accelerometer in notebooks. Just start up ShockDraw and tilt your notebook to draw on the screen. Tilt it left and the line on the screen will move left, tilt it back and the line will move up on the screen. It isn’t meant to be a full game or anything other than a tech demo. I have provided both an executable and the source code if you are interested in seeing how it works.

If you are interested in the nerdy details, here is pretty much all you need to know. This is the Win32 method and the struct layout that you need to read the Accelerometer data in your notebook. Either this is poorly documented or I’m terrible at Googling, but all the example structs I found were incorrect. Most of the documentation I found didn’t have enough properties in the struct, which caused the ShockproofGetAccelerometerData method to overflow the struct and start writing over program memory. A buffer overflow in all it’s glory. Some other examples didn’t have the correct data types, which also caused some crazy problems. So, for future reference, here is what the struct looks like in C#:

[DllImport("sensor.dll")]
public static extern void ShockproofGetAccelerometerData(ref AccData accData);

[StructLayout(LayoutKind.Sequential)]
public struct AccData {
internal int status;
internal short x;
internal short y;
internal ushort xx;
internal ushort yy;
internal sbyte c;
internal ushort x0;
internal ushort y0;
}

Presto, now you’re rolling. Enjoy!

Update: I have changed the video from being hosted on my site to being hosted on YouTube for anyone that wants to share it.

This post was written by:

Jon Tackabury
Binary Fortress Software, Lead Developer

2 Comments For This Post

  1. krishna Says:

    Congrats!! I need to show this flash app in my blog.
    How do I? Please let me know.
    Regards,
    krishna

  2. Jon Tackabury Says:

    Krishna: I have just moved the video to YouTube if you would like to share it. You can find it here:
    http://www.youtube.com/watch?v=pNks1OzTTOg