|
1 <?xml version="1.0" encoding="utf-8"?> |
|
2 <!-- Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies) All rights reserved. --> |
|
3 <!-- This component and the accompanying materials are made available under the terms of the License |
|
4 "Eclipse Public License v1.0" which accompanies this distribution, |
|
5 and is available at the URL "http://www.eclipse.org/legal/epl-v10.html". --> |
|
6 <!-- Initial Contributors: |
|
7 Nokia Corporation - initial contribution. |
|
8 Contributors: |
|
9 --> |
|
10 <!DOCTYPE task |
|
11 PUBLIC "-//OASIS//DTD DITA Task//EN" "task.dtd"> |
|
12 <task id="GUID-64AC6F53-A9A5-46FD-BCC6-4A9BD8D4DB5C" xml:lang="en"><title>Compensating |
|
13 Sensor Data for Display Orientation</title><shortdesc>You can use the sensor data compensator APIs to correct the display |
|
14 and device orientation data.</shortdesc><prolog><metadata><keywords/></metadata></prolog><taskbody> |
|
15 <prereq id="GUID-A7AAEFBD-92F7-4143-AF04-CB7604C63B12"><p>Before you begin |
|
16 using the sensor data compensator APIs, you must do the following:</p><ol> |
|
17 <li id="GUID-A2F385CE-1902-42DB-91F0-6359174BD31B"><p>Open a Sensor Channel |
|
18 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 |
|
19 Sensor Channels APIs</xref></p></li> |
|
20 <li id="GUID-D7CC2C9C-ADA4-4C20-9F83-1D194778D1A9"><p>Implement the data listener |
|
21 interface. For details see, <xref href="GUID-BA0D9DA9-3B54-4964-A4D6-9ADA4DEB7231.dita">Receiving |
|
22 Data from Sensors</xref></p></li> |
|
23 <li id="GUID-34B18C12-F93C-4509-8E6F-4A0C2998ADB7"><p>Register as a listener |
|
24 with any of the sensor types using an instance of <parmname>CSensrvChannel</parmname>.</p></li> |
|
25 <li id="GUID-527FEDAB-FAF3-4A8B-BF58-D300C0DC04E8"><p>Ensure that the data |
|
26 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, |
|
27 as shown in the following example:</p><codeblock xml:space="preserve">// 'iChannel' contains an open channel |
|
28 TSensrvProperty property; |
|
29 TRAPD( err, iChannel->GetPropertyL( KSensrvPropIdChannelDataCompensation, KSensrvItemIndexNone, property ) ); |
|
30 if ( err == KErrNone && property.PropertyType() == ESensrvIntProperty ) |
|
31 { |
|
32 // Channel data is compensated, check the compensation type |
|
33 TInt compensationType; |
|
34 property.GetValue( compensationType ); |
|
35 // 'compensationType' contains now a value from TSensorCompensationType enumeration declared in sensordatacompensationtypes.h |
|
36 } |
|
37 else |
|
38 { |
|
39 // Channel data is not compensated |
|
40 }</codeblock><p>For more information, see <xref href="GUID-83630B57-D842-4B60-8AF0-D2965251DE29.dita">Retrieving |
|
41 channel properties</xref> .</p></li> |
|
42 </ol> </prereq> |
|
43 <context id="GUID-02653FE0-162F-46A1-A4BC-7DD48350432B"> <p>The sensor |
|
44 data compensator APIs allows you to compensate sensor data values, based on:</p><ul> |
|
45 <li><p>Display Orientation, when the display is changed from portrait to landscape.</p></li> |
|
46 <li><p>Device Orientation, when the keyboard is opened, resulting in the display |
|
47 being set at an angle to the keyboard. For example, N97.</p></li> |
|
48 </ul> </context> |
|
49 <steps id="GUID-4DD07DEC-6017-4237-BE46-1D69E5FBD744-GENID-1-7-1-8-1-1-8-1-5-1-4-1-3-3"> |
|
50 <step id="GUID-9A69E5AD-E938-4092-A8C2-CB65C37C8962-GENID-1-7-1-8-1-1-8-1-5-1-4-1-3-3-1"><cmd>Create an instance |
|
51 of <parmname>CSensorDataCompensator</parmname>.</cmd> |
|
52 <stepxmp><codeblock xml:space="preserve">iCompensator = CSensorDataCompensator::NewL(TSensrvAccelerometerAxisData::KDataTypeId,ESensorCompensateDeviceAndUIOrientation);</codeblock></stepxmp> |
|
53 </step> |
|
54 <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 |
|
55 to correct the sensor data received from the following channel types and related |
|
56 classes:</cmd> |
|
57 <info><table id="GUID-1726B6BF-D170-4769-8E98-21BA6318E95F"> |
|
58 <tgroup cols="2"><colspec colname="col1"/><colspec colname="col2"/> |
|
59 <thead> |
|
60 <row> |
|
61 <entry>Sensor Channel Type</entry> |
|
62 <entry>Data Class</entry> |
|
63 </row> |
|
64 </thead> |
|
65 <tbody> |
|
66 <row> |
|
67 <entry>Accelerometer axis data</entry> |
|
68 <entry><codeph>TSensrvAccelerometerAxisData</codeph></entry> |
|
69 </row> |
|
70 <row> |
|
71 <entry>Magnetometer axis data</entry> |
|
72 <entry><codeph>TSensrvMagnetometerAxisData</codeph></entry> |
|
73 </row> |
|
74 <row> |
|
75 <entry>Accelerometer double-tap</entry> |
|
76 <entry><codeph>TSensrvTappingData</codeph></entry> |
|
77 </row> |
|
78 </tbody> |
|
79 </tgroup> |
|
80 </table></info> |
|
81 </step> |
|
82 </steps> |
|
83 <example><title>Example</title><p>The following example illustrates the usage |
|
84 of sensor data compensator APIs to correct axis data received from accelerometer |
|
85 sensor.</p><codeblock xml:space="preserve">#include <sensordatacompensator.h> // link against sensordatacompensator.lib |
|
86 |
|
87 void CMyClass::ConstructL() |
|
88 |
|
89 { |
|
90 // iSensorChannel already instantiated and registered |
|
91 if ( !AlreadyCompensated() ) |
|
92 { |
|
93 iCompensator = CSensorDataCompensator::NewL( |
|
94 TSensrvAccelerometerAxisData::KDataTypeId, |
|
95 ESensorCompensateDeviceAndUIOrientation ); |
|
96 } |
|
97 } |
|
98 |
|
99 CMyClass::~CMyClass() |
|
100 |
|
101 { |
|
102 delete iCompensator; |
|
103 } |
|
104 |
|
105 void CMyClass::DataReceived( CSensrvChannel& aChannel, |
|
106 |
|
107 TInt /*aCount*/, |
|
108 TInt /*aDataLost*/ ) |
|
109 { |
|
110 |
|
111 TPckgBuf <TSensrvAccelerometerAxisData> dataBuf; |
|
112 iSensorChannel -> GetData( dataBuf ); |
|
113 |
|
114 if ( iCompensator ) |
|
115 { |
|
116 if ( iCompensator->Compensate( dataBuf ) == KErrNone ) |
|
117 { |
|
118 // Now use the compensated data. |
|
119 } |
|
120 }</codeblock></example> |
|
121 <postreq id="GUID-F834E8DF-C906-43E9-B49B-9B0ACB116E9B"><p>End the session |
|
122 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> |
|
123 </taskbody></task> |