You can use the sensor data compensator APIs to correct the display and device orientation data.
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 .
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.
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.
Copyright ©2010 Nokia Corporation and/or its subsidiary(-ies).
All rights
reserved. Unless otherwise stated, these materials are provided under the terms of the Eclipse Public License
v1.0.