|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the Qt Mobility Components. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
15 ** |
|
16 ** GNU Lesser General Public License Usage |
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 |
|
42 // Internal Headers |
|
43 #include "rotationsensorsym.h" |
|
44 |
|
45 #include <sensrvgeneralproperties.h> |
|
46 |
|
47 /** |
|
48 * set the id of the proximity sensor |
|
49 */ |
|
50 char const * const CRotationSensorSym::id("sym.rotation"); |
|
51 |
|
52 const TInt KMinimumRange = -180; |
|
53 const TInt KMaximumRange = 180; |
|
54 |
|
55 /** |
|
56 * Factory function, this is used to create the rotation sensor object |
|
57 * @return CRotationSensorSym if successful, leaves on failure |
|
58 */ |
|
59 CRotationSensorSym* CRotationSensorSym::NewL(QSensor *sensor) |
|
60 { |
|
61 CRotationSensorSym* self = new (ELeave) CRotationSensorSym(sensor); |
|
62 CleanupStack::PushL(self); |
|
63 self->ConstructL(); |
|
64 CleanupStack::Pop(); |
|
65 return self; |
|
66 } |
|
67 |
|
68 /** |
|
69 * Destructor |
|
70 * Closes the backend resources |
|
71 */ |
|
72 CRotationSensorSym::~CRotationSensorSym() |
|
73 { |
|
74 // Release the backend resources |
|
75 Close(); |
|
76 } |
|
77 |
|
78 /** |
|
79 * Default constructor |
|
80 */ |
|
81 CRotationSensorSym::CRotationSensorSym(QSensor *sensor):CSensorBackendSym(sensor) |
|
82 { |
|
83 setReading<QRotationReading>(&iReading); |
|
84 iBackendData.iSensorType = KSensrvChannelTypeIdRotationData; |
|
85 } |
|
86 |
|
87 /* |
|
88 * RecvData is used to retrieve the sensor reading from sensor server |
|
89 * It is implemented here to handle rotation sensor specific |
|
90 * reading data and provides conversion and utility code |
|
91 */ |
|
92 void CRotationSensorSym::RecvData(CSensrvChannel &aChannel) |
|
93 { |
|
94 TPckg<TSensrvRotationData> rotationpkg( iData ); |
|
95 TInt ret = aChannel.GetData( rotationpkg ); |
|
96 if(KErrNone != ret) |
|
97 { |
|
98 // If there is no reading available, return without setting |
|
99 return; |
|
100 } |
|
101 // Get a lock on the reading data |
|
102 iBackendData.iReadingLock.Wait(); |
|
103 // To Do verify with ds and ramsay |
|
104 |
|
105 // For x axis symbian provides reading from 0 to 359 range |
|
106 // This logic maps value to Qt range -90 to 90 |
|
107 if(iData.iDeviceRotationAboutXAxis >= 0 && iData.iDeviceRotationAboutXAxis <= 180) |
|
108 { |
|
109 iReading.setX(90 - iData.iDeviceRotationAboutXAxis); |
|
110 } |
|
111 else if(iData.iDeviceRotationAboutXAxis > 180 && iData.iDeviceRotationAboutXAxis <= 270) |
|
112 { |
|
113 iReading.setX(iData.iDeviceRotationAboutXAxis - 270); |
|
114 } |
|
115 else if(iData.iDeviceRotationAboutXAxis > 270 && iData.iDeviceRotationAboutXAxis < 360) |
|
116 { |
|
117 iReading.setX(iData.iDeviceRotationAboutXAxis - 270); |
|
118 } |
|
119 |
|
120 // For y axis symbian provides reading from 0 to 359 range |
|
121 // This logic maps value to Qt range -180 to 180 |
|
122 if(iData.iDeviceRotationAboutYAxis >= 0 && iData.iDeviceRotationAboutYAxis <= 180) |
|
123 { |
|
124 iReading.setY(iData.iDeviceRotationAboutYAxis); |
|
125 } |
|
126 else if(iData.iDeviceRotationAboutYAxis > 180 && iData.iDeviceRotationAboutYAxis < 360) |
|
127 { |
|
128 iReading.setY(iData.iDeviceRotationAboutYAxis - 360); |
|
129 } |
|
130 |
|
131 if(iData.iDeviceRotationAboutZAxis == TSensrvRotationData::KSensrvRotationUndefined) |
|
132 { |
|
133 sensor()->setProperty("hasZ", QVariant(FALSE)); |
|
134 } |
|
135 else |
|
136 { |
|
137 sensor()->setProperty("hasZ", QVariant(TRUE)); |
|
138 // For z axis symbian provides reading from 0 to 359 range |
|
139 // This logic maps value to Qt range -180 to 180 |
|
140 if(iData.iDeviceRotationAboutZAxis >= 0 && iData.iDeviceRotationAboutZAxis <= 180) |
|
141 { |
|
142 iReading.setZ(iData.iDeviceRotationAboutZAxis); |
|
143 } |
|
144 else if(iData.iDeviceRotationAboutZAxis > 180 && iData.iDeviceRotationAboutZAxis < 360) |
|
145 { |
|
146 iReading.setZ(iData.iDeviceRotationAboutZAxis - 360); |
|
147 } |
|
148 } |
|
149 // Set the timestamp |
|
150 iReading.setTimestamp(iData.iTimeStamp.Int64()); |
|
151 // Release the lock |
|
152 iBackendData.iReadingLock.Signal(); |
|
153 } |
|
154 |
|
155 /** |
|
156 * Overriding this method in rotation sensor to hard code value of |
|
157 * mesurement range from -180 to 180 as Qt wants |
|
158 * Symbian provides measurement range from 0 to 359 |
|
159 */ |
|
160 void CRotationSensorSym::GetMeasurementrangeAndAccuracy() |
|
161 { |
|
162 TReal accuracy = 0; |
|
163 TSensrvProperty accuracyProperty; |
|
164 TRAPD(err, iBackendData.iSensorChannel->GetPropertyL(KSensrvPropIdChannelAccuracy, ESensrvSingleProperty, accuracyProperty)); |
|
165 if(err == KErrNone) |
|
166 { |
|
167 accuracyProperty.GetValue(accuracy); |
|
168 } |
|
169 // Hard coding values -180 and 180 as Qt expects y and z axis |
|
170 // values range from -180 to 180. |
|
171 addOutputRange(KMinimumRange, KMaximumRange, accuracy); |
|
172 } |
|
173 |
|
174 |
|
175 /** |
|
176 * Second phase constructor |
|
177 * Initialize the backend resources |
|
178 */ |
|
179 void CRotationSensorSym::ConstructL() |
|
180 { |
|
181 //Initialize the backend resources |
|
182 InitializeL(); |
|
183 } |
|
184 |