Windows Phone 7 Accelerometer Kit
Hi fellow readers! These past few weeks have been busy. Between the traveling around the country to promote the Imagine Cup 2011 competition at the Universities (are you registered at Imagine Cup 2011? Help us realize the millennium goals at http://www.imaginecup.com/ ), the Sapo Codebits event at Pavilhão Atlântico, my thesis and some experiences with Windows Phone 7, the time has passed by rather quickly!
In the last post I mentioned some work I was doing for Windows Phone 7 (WP7) and finally, in the beginning of this month, I was able to release a working version of my accelerometer kit. Please feel free to go to http://wp7accelerometerkit.codeplex.com/ , download it and try it out yourselves. At codeplex’s documentation tab (http://wp7accelerometerkit.codeplex.com/documentation) or in the READ ME ALL.docx included in the project download, you can find all the necessary information you need to use this kit.
So how does it work? The kit is made of 3 major components:
1) A Console application (AccelerometerServer) : This console application hosts a WCF Service that will bridge all the projects on this solution. It provides a service that lets you retrieve and store information about the acceleration and rotation values for the Windows Phone.
2) A, Silverlight OOB (out of browser) application (ControlPanelOOB) : This application is not required for the toolkit to work properly. It's meant to be more of a debugging assist tool. It will easily let you read the acceleration and rotation values that the accelerometer is sending at all time. In future versions i hope to expand this so that it will have other helpful functionalities
3) A XNA Windows Game application (WP7XNAAccelerometerSimulator) : This has a model of a Windows Phone 7 and lets you rotate it as you wish. According to the position of the Windows Phone in this simulator, it will calculate the appropriate accelerometer values and send them to the server.
Besides these components there’s a a Windows Phone Class Library (AccelerometerWP7ClassLibrary) which is what you insert in the application you want to test the accelerometer behaviour. This DLL provides a similar interface as the Accelerometer class in the Windows Phone 7 tools.
To use the Kit I’ve included a compiled version of the 3 components that you can easily run by executing a batch file in Administrator mode. It’s important that you run the batch file in Administrator mode (right click "Run as administrator”) or else the Console application won’t have the necessary priviliges to host a WCF Service and the kit will fail to start. I’ve also made it so that when you close the XNA app, it will close the other 2 components.
To use the DLL just add a reference to your project, browse to the DLL directory (I’ve included a compiled DLL in the download version at “Accelerometer Kit Application\AccelerometerSimulatorDLL”) and then you can use the simulator’s code as you would use the Accelerometer class from the Windows Phone 7 tools. You can even have code for both accelerometers so that you don’t have to change your code when running your application on the simulator or on the Phone itself by using #if statements as explained in the documentation.
To control Windows Phone orientation in the XNA simulator you can use the mouse or the arrow keys plus A and D Keys. To use the mouse you can drag horizontally or vertically over the orange sphere to pitch or roll the phone. Drag over the green torus, located above the orange sphere, to yaw the phone. These mouse controls aren't very good, they need to be improved so i advise you to use the keys to control the phone's orientation. The Left and Right arrow keys control the phone's pitch, the Up and Down arrow keys control the phone's roll, the A and D keys control the phone's yaw.
Here’s an image of the Control Panel and the XNA simulator (click on it to see full size):

The Phone starts with the same orientation as the one in emulator which is standing on an horizontal surface with the screen facing up.
That’s it, I hope you find this Kit useful. Download it at http://wp7accelerometerkit.codeplex.com/ and leave any comments here or at Codeplex.