Although HTC did not provide a public API for the G Sensor (shame on them for this), Scott Seligman reverse engineered it which eventually led to a Codeplex project on this subject. The code you see here was ported from the C# version of the Codeplex project back to C++.
The application is quite simple: it merely connects to the G Sensor data source, samples it every 200 ms and displays the tilt values on the screen. As usual, I used WTL to write this simple app and its main features are:
- The HTCGSensor class that implements an interface to the HTC G Sensor API;
- The view window (CHtcSensorView) that samples the G Sensor data every 200 milliseconds and displays the tilt values;
- The frame window (CHtcSensorFrame) where the sampling timer is started (see the OnCreate handler)
Sample code: HtcSensor.zip
The sample application requires an HTC device with a G Sensor like the Diamond. You can use this information in a number of different ways on the device. On a forthcoming post, I will show how you can consume this information on a desktop .NET 3.5 application.