Solution Content's
This solution contains 4 projects:

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.
4) A Windows Phone Class Library (AccelerometerWP7ClassLibrary) : This DLL is what has to be inserted on the application we want to test the accelerometer behaviour. It provides a similar interface has the Accelerometer class in the Windows Phone 7 tools.

What you need to do in your application
To use the kit in your Windows Phone 7 application you have to:
1) Add a reference to the AccelerometerWP7ClassLibrary's DLL. You can either use the DLL in the Accelerometer Kit Application\AccelerometerSimulatorDLL folder or build the solution and then browse to the AccelerometerWP7ClassLibrary\bin folder where you'll find the DLL.
2) Instantiate the AccelerometerSimulator and add the an EventHandler for the ReadingChanged event. You can use ifdef statements that will use the simulator code if you're running your application on the emulator or the real accelerometer if your application is deployed on a Windows Phone, for example:

Start of Code Usage Example

Instantiate the accelerometer
Accelerometer accelWindowsPhone = new Accelerometer();
AccelerometerSimulator accelSimulator = new AccelerometerSimulator();

Add the EventHandler
accelWindowsPhone.ReadingChanged += new EventHandler<AccelerometerReadingEventArgs>(accelWindowsPhone_ReadingChanged);
accelSimulator.ReadingChanged += new AccelerometerSimulator.EventHandler<AccelerometerWP7ClassLibrary.AccelerometerSimulatorReadingEventArgs>(accelSimulator_ReadingChanged);

Access the accelerometer values
void accelSimulator_ReadingChanged(object sender, AccelerometerWP7ClassLibrary.AccelerometerSimulatorReadingEventArgs e)
double accelerationX = e.X;
double accelerationY = e.Y;
double accelerationZ = e.Z;

//do whatever you want with the acceleration values
End of Code Usage Example

How to start the Accelerometer Simulator Kit
If you're interested in seeing how the program was build you should explore the solution. The code is all documented to ease your understanding and mine also =).
If you just want to use the kit then open the Accelerometer Kit Application folder and run the Start WP7 Accelerometer Kit (Admin mode only) batch file in admin mode (Right click and choose “Run as administrator”). It needs to run in admin mode or else Windows will not let you start the server application. The batch file will start the server, the control panel, and the XNA simulator. That's all you need to do to start the Kit!
Warning :
If you're not using an 64bit OS change the beginning of the last line of the batch file (to edit you can just open it with notepad for example):
- Instead of "%ProgramFiles(x86)% change to "%ProgramFiles%
- Basically what needs to happen is that the need to have the correct path to "sllauncher.exe" and the above change garantees it if you're not using a 64bit OS.

How to use
Once you've added added the AccelerometerWP7ClassLibrary's DLL to your project, added the code to use the AccelerometerSimulator and started the Kit you can use the mouse or the arrow keys plus A and D Keys to control the Windows Phone orientation.
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. This 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,

Future enhancements
1) Get a better model for the Windows Phone. I made a box and applied a texture on it. It's not the ugliest thing but it's not that great. The texture is also rounded on the corners so it would be nice if i could get a matching model. Anyone interested in doing this?
2) Improve the mouse control system. I don't really like the currect mouse control system but i haven't had time to implement a better one. If anyone has ideas about how it should be please share them.
3) Add more options for the Control Panel. It would be nice to be able to reset the phone's orientation for example.
4) Merge the console application with the XNA project and change polling system to callback system. What's happening now is that i'm checking the server for new info every X info but i should use callbacks to be notified when there's new info.
5) Add support for shaking the windows phone.

Aditional remarks
The Windows Phone initial position is the same as the emulator's which is horizontally face up, like if it was standing on a desk.
Hope you enjoy it, please leave feedback =)

Last edited Nov 4, 2010 at 7:41 PM by 3xistenz, version 7


No comments yet.