You can use the sensor data compensator APIs to correct the display and device orientation data.
The sensor data compensator APIs allows you to compensate sensor data values, based on:
Display Orientation, when the display is changed from portrait to landscape.
Device Orientation, when the keyboard is opened, resulting in the display being set at an angle to the keyboard. For example, N97.
Before you begin using the sensor data compensator APIs, you must do the following:
Open a Sensor Channel for communication. For details, see Using Sensor Channels APIs
Implement the data listener interface. For details see, Receiving Data from Sensors
Register as a listener
with any of the sensor types using an instance of CSensrvChannel
.
Ensure that the data received from the sensor channel is not already compensated using the CSensrvChannel::GetPropertyL() function, as shown in the following example:
// 'iChannel' contains an open channel TSensrvProperty property; TRAPD( err, iChannel->GetPropertyL( KSensrvPropIdChannelDataCompensation, KSensrvItemIndexNone, property ) ); if ( err == KErrNone && property.PropertyType() == ESensrvIntProperty ) { // Channel data is compensated, check the compensation type TInt compensationType; property.GetValue( compensationType ); // 'compensationType' contains now a value from TSensorCompensationType enumeration declared in sensordatacompensationtypes.h } else { // Channel data is not compensated }
For more information, see Retrieving channel properties .
Create an instance
of CSensorDataCompensator
.
iCompensator = CSensorDataCompensator::NewL(TSensrvAccelerometerAxisData::KDataTypeId,ESensorCompensateDeviceAndUIOrientation);
Use the CSensorDataCompensator::Compensate()
function
to correct the sensor data received from the following channel types and related
classes:
The following example illustrates the usage of sensor data compensator APIs to correct axis data received from accelerometer sensor.
#include <sensordatacompensator.h> // link against sensordatacompensator.lib void CMyClass::ConstructL() { // iSensorChannel already instantiated and registered if ( !AlreadyCompensated() ) { iCompensator = CSensorDataCompensator::NewL( TSensrvAccelerometerAxisData::KDataTypeId, ESensorCompensateDeviceAndUIOrientation ); } } CMyClass::~CMyClass() { delete iCompensator; } void CMyClass::DataReceived( CSensrvChannel& aChannel, TInt /*aCount*/, TInt /*aDataLost*/ ) { TPckgBuf <TSensrvAccelerometerAxisData> dataBuf; iSensorChannel -> GetData( dataBuf ); if ( iCompensator ) { if ( iCompensator->Compensate( dataBuf ) == KErrNone ) { // Now use the compensated data. } }
End the session with the sensor channel using the CSensrvChannel::CloseChannel() function.