diff -r 43e37759235e -r 51a74ef9ed63 Symbian3/SDK/Source/GUID-64AC6F53-A9A5-46FD-BCC6-4A9BD8D4DB5C.dita --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Symbian3/SDK/Source/GUID-64AC6F53-A9A5-46FD-BCC6-4A9BD8D4DB5C.dita Wed Mar 31 11:11:55 2010 +0100 @@ -0,0 +1,123 @@ + + + + + +Compensating +Sensor Data for Display OrientationYou 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:

    +
  1. Open a Sensor Channel +for communication. For details, see Using +Sensor Channels APIs

  2. +
  3. Implement the data listener +interface. For details see, Receiving +Data from Sensors

  4. +
  5. Register as a listener +with any of the sensor types using an instance of CSensrvChannel.

  6. +
  7. 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 .

  8. +
+

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.

  • +
+ +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: + + + + +Sensor Channel Type +Data Class + + + + +Accelerometer axis data +TSensrvAccelerometerAxisData + + +Magnetometer axis data +TSensrvMagnetometerAxisData + + +Accelerometer double-tap +TSensrvTappingData + + + +
+
+
+Example

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.

+
\ No newline at end of file