Using Windows Phone As Windows 7 Accelerometer Sensor
Join the DZone community and get the full member experience.Join For Free
i just had a cool idea! (actually i had it like 6 month ago, but bear with me).
my idea involves mixing some of the features in windows 7 with some of the features in windows phone 7, to create a glorious mix!
one of the new features in windows 7 is the sensor api which provides a standard interface for accessing sensors of various types, like accelerometer , etc..
windows phone 7
windows phone 7 comes with a few sensors out of the box, among them: accelerometer!
what if we use windows phone 7 accelerometer sensor as a standard device on windows 7?
so how can we accomplish that? let's break the idea to steps:
step 1 : create a software driver
i’ll start with creating a dummy software driver. this driver will implement what's necessary to be a standard windows 7 accelerometer sensor, but at this stage will simply return constant data.
in order to write a sensor driver for windows 7 i’ll need to use user mode driver framework (umdf), a com-like, c++ framework for writing user-mode drivers in windows 7.
step 2 : transfer windows phone 7 sensor data into the pc
the next step is to find a way to transfer the accelerometer data from a windows phone device into the pc. one possible way of doing this implementing a local wcf service on the desktop that the phone will keep calling with accelerometer data. this will require an application to run on the phone to keep the data flowing.
step 3 : consume the wcf service from the phone
using the service from the previous step we can now consume it in a simple windows phone application that all it does is getting the accelerometer sensor data using the phone api and call the wcf service with the latest data.
step 4 : make the software driver consume the windows phone 7 data
now that i have a software driver that returns dummy accelerometer data and a way to get real accelerometer data from the windows phone, all i need to do is connecting the dots and make my accelerometer driver return the real data. to do this i'll need some kind of inter process communication to transfer the data from the wcf service to the driver.
long story short…
i present to you the windows phone accelerometer driver for windows 7 !
the full source code for this project can be found on the codeplex project site .
some implementation details
the actual driver was fairly easy to implement since i used the codeproject article " writing a sensor driver for the wiimote on windows 7 " by rajasekharan vengalil as a base for my windows phone 7 driver. you can find the driver source code in the project named wp7accelerometerdriver .
as mentioned earlier i've implemented a simple local wcf service for transferring the accelerometer data from the phone to the driver. you can find the service source code in the project named wp7accelerometerservice . the service uses named pipes to communicate with the driver.
the phone application is a very simple one that consumes the wcf service and call it whenever a new accelerometer value is available. you can find its source code in the project named wp7accelerometerclient .
finally, if you want to check the functionality of the accelerometer driver you can use either the sensordiagnostics project or the more fun planedemo project, which i borrowed for sergey zwezdin blog .
how to install?
1. download and extract project binaries or source from the codeplex project site .
2. open cmd as administrator
3. go to the folder \driver\install\
5. when the following notification appears, select " install this driver software anyway ":
6. enable installed sensor in the control panel
7. run the wcf service from as administrator . if you run it from visual studio, make sure you ran visual studio as administrator.
8. run the windows phone client on a real device while connected to the pc and enter your pc (lan) ip
9. that's it! you can now sit back and enjoy the ride using the planedemo application or sensordiagnostics , or any other software that uses the accelerometer sensor.
how to uninstall?
if you want to uninstall the driver simply go to the device manager , select the " wp7 accelerometer sensor " device from the sensors category, select uninstall from the context menu and make sure you mark the checkbox to delete the driver .
i've seen the project works both on a real device and using the phone emulator, however it's not a one-click install. i expect users to have problems with the installation. if you encounter some problems, please post on the codeplex project site forum page and i'll do my best to help.
also, if you want to improve the source code (maybe adding gps support?) or the installation procedure, i'll be happy to include your improvements and even include you as one of the project members on codeplex.
this project was pure fun since it combines many useful technologies to create real value. among the technologies you can find: c++, com, umdf, c#, wcf, wp7, etc..
Published at DZone with permission of Arik Poznanski, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.