Symbian3/SDK/Source/GUID-64AC6F53-A9A5-46FD-BCC6-4A9BD8D4DB5C.dita
author Graeme Price <GRAEME.PRICE@NOKIA.COM>
Fri, 15 Oct 2010 14:32:18 +0100
changeset 15 307f4279f433
parent 13 48780e181b38
permissions -rw-r--r--
Initial contribution of the Adaptation Documentation.

<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies) All rights reserved. -->
<!-- This component and the accompanying materials are made available under the terms of the License 
"Eclipse Public License v1.0" which accompanies this distribution, 
and is available at the URL "http://www.eclipse.org/legal/epl-v10.html". -->
<!-- Initial Contributors:
    Nokia Corporation - initial contribution.
Contributors: 
-->
<!DOCTYPE task
  PUBLIC "-//OASIS//DTD DITA Task//EN" "task.dtd">
<task id="GUID-64AC6F53-A9A5-46FD-BCC6-4A9BD8D4DB5C" xml:lang="en"><title>Compensating
Sensor Data for Display Orientation</title><shortdesc>You can use the sensor data compensator APIs to correct the display
and device orientation data.</shortdesc><prolog><metadata><keywords/></metadata></prolog><taskbody>
<prereq id="GUID-A7AAEFBD-92F7-4143-AF04-CB7604C63B12"><p>Before you begin
using the sensor data compensator APIs, you must do the following:</p><ol>
<li id="GUID-A2F385CE-1902-42DB-91F0-6359174BD31B"><p>Open a Sensor Channel
for communication. For details, see <xref href="GUID-4B709839-8EEF-4AD2-9868-9AF0176B1E5B.dita#GUID-4B709839-8EEF-4AD2-9868-9AF0176B1E5B/GUID-30E6033F-E316-4BDB-AF22-2369463DF709">Using
Sensor Channels APIs</xref></p></li>
<li id="GUID-D7CC2C9C-ADA4-4C20-9F83-1D194778D1A9"><p>Implement the data listener
interface. For details see, <xref href="GUID-BA0D9DA9-3B54-4964-A4D6-9ADA4DEB7231.dita">Receiving
Data from Sensors</xref></p></li>
<li id="GUID-34B18C12-F93C-4509-8E6F-4A0C2998ADB7"><p>Register as a listener
with any of the sensor types using an instance of <parmname>CSensrvChannel</parmname>.</p></li>
<li id="GUID-527FEDAB-FAF3-4A8B-BF58-D300C0DC04E8"><p>Ensure that the data
received from the sensor channel is not already compensated using the <xref href="GUID-22DC917F-D833-3531-AB2D-A6E2D52EF844.dita#GUID-22DC917F-D833-3531-AB2D-A6E2D52EF844/GUID-1E9D960B-23C4-30DF-A184-7E978AC9AC1B"><apiname>CSensrvChannel::GetPropertyL()</apiname></xref> function,
as shown in the following example:</p><codeblock xml:space="preserve">// 'iChannel' contains an open channel
TSensrvProperty property;
TRAPD( err, iChannel-&gt;GetPropertyL( KSensrvPropIdChannelDataCompensation, KSensrvItemIndexNone, property ) );
if ( err == KErrNone &amp;&amp; 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
     }</codeblock><p>For more information, see <xref href="GUID-83630B57-D842-4B60-8AF0-D2965251DE29.dita">Retrieving
channel properties</xref> .</p></li>
</ol>           </prereq>
<context id="GUID-02653FE0-162F-46A1-A4BC-7DD48350432B">       <p>The sensor
data compensator APIs allows you to compensate sensor data values, based on:</p><ul>
<li><p>Display Orientation, when the display is changed from portrait to landscape.</p></li>
<li><p>Device Orientation, when the keyboard is opened, resulting in the display
being set at an angle to the keyboard. For example, N97.</p></li>
</ul>     </context>
<steps id="GUID-4DD07DEC-6017-4237-BE46-1D69E5FBD744-GENID-1-10-1-11-1-1-6-1-5-1-4-1-3-3">
<step id="GUID-9A69E5AD-E938-4092-A8C2-CB65C37C8962-GENID-1-10-1-11-1-1-6-1-5-1-4-1-3-3-1"><cmd>Create an instance
of <parmname>CSensorDataCompensator</parmname>.</cmd>
<stepxmp><codeblock xml:space="preserve">iCompensator = CSensorDataCompensator::NewL(TSensrvAccelerometerAxisData::KDataTypeId,ESensorCompensateDeviceAndUIOrientation);</codeblock></stepxmp>
</step>
<step id="GUID-AE833279-71EA-43FC-AB2E-E4CFAF277A02"><cmd>Use the <xref href="GUID-D32C68EB-AB82-3C2D-98F1-280401FD1763.dita#GUID-D32C68EB-AB82-3C2D-98F1-280401FD1763/GUID-A400CB98-7D89-323F-92A8-EE5D581BEFA4"><apiname>CSensorDataCompensator::Compensate()</apiname></xref> function
to correct the sensor data received from the following channel types and related
classes:</cmd>
<info><table id="GUID-1726B6BF-D170-4769-8E98-21BA6318E95F">
<tgroup cols="2"><colspec colname="col1"/><colspec colname="col2"/>
<thead>
<row>
<entry>Sensor Channel Type</entry>
<entry>Data Class</entry>
</row>
</thead>
<tbody>
<row>
<entry>Accelerometer axis data</entry>
<entry><codeph>TSensrvAccelerometerAxisData</codeph></entry>
</row>
<row>
<entry>Magnetometer axis data</entry>
<entry><codeph>TSensrvMagnetometerAxisData</codeph></entry>
</row>
<row>
<entry>Accelerometer double-tap</entry>
<entry><codeph>TSensrvTappingData</codeph></entry>
</row>
</tbody>
</tgroup>
</table></info>
</step>
</steps>
<example><title>Example</title><p>The following example illustrates the usage
of sensor data compensator APIs to correct axis data received from accelerometer
sensor.</p><codeblock xml:space="preserve">#include &lt;sensordatacompensator.h&gt; // 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&amp; aChannel,

                            TInt /*aCount*/, 
                            TInt /*aDataLost*/ )
   {
    
   TPckgBuf  &lt;TSensrvAccelerometerAxisData&gt; dataBuf;
   iSensorChannel -&gt; GetData( dataBuf );

   if ( iCompensator )
       {
       if ( iCompensator-&gt;Compensate( dataBuf ) == KErrNone )
           {
           // Now use the compensated data.
           }
       }</codeblock></example>
<postreq id="GUID-F834E8DF-C906-43E9-B49B-9B0ACB116E9B"><p>End the session
with the sensor channel using the <xref href="GUID-22DC917F-D833-3531-AB2D-A6E2D52EF844.dita#GUID-22DC917F-D833-3531-AB2D-A6E2D52EF844/GUID-0B8F50A6-2CA1-316A-82AB-AA026005E810"><apiname>CSensrvChannel::CloseChannel()</apiname></xref> function.</p></postreq>
</taskbody></task>