|
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 "accelerometersym.h" |
|
44 #include <sensrvgeneralproperties.h> |
|
45 |
|
46 #define GRAVITATION_CONSTANT 9.812865328 //According to wikipedia link http://en.wikipedia.org/wiki/Standard_gravity |
|
47 |
|
48 /** |
|
49 * set the id of the accelerometer sensor |
|
50 */ |
|
51 char const * const CAccelerometerSensorSym::id("sym.accelerometer"); |
|
52 |
|
53 /** |
|
54 * Factory function, this is used to create the accelerometer object |
|
55 * @return CAccelerometerSensorSym if successful, leaves on failure |
|
56 */ |
|
57 CAccelerometerSensorSym* CAccelerometerSensorSym::NewL(QSensor *sensor) |
|
58 { |
|
59 CAccelerometerSensorSym* self = new (ELeave) CAccelerometerSensorSym(sensor); |
|
60 CleanupStack::PushL(self); |
|
61 self->ConstructL(); |
|
62 CleanupStack::Pop(); |
|
63 return self; |
|
64 } |
|
65 |
|
66 /** |
|
67 * Destructor |
|
68 * Closes the backend resources |
|
69 */ |
|
70 CAccelerometerSensorSym::~CAccelerometerSensorSym() |
|
71 { |
|
72 // Release the backend resources |
|
73 Close(); |
|
74 } |
|
75 |
|
76 /** |
|
77 * Default constructor |
|
78 */ |
|
79 CAccelerometerSensorSym::CAccelerometerSensorSym(QSensor *sensor):CSensorBackendSym(sensor), |
|
80 iScaleRange(0), |
|
81 iUnit(0) |
|
82 { |
|
83 setReading<QAccelerometerReading>(&iReading); |
|
84 iBackendData.iSensorType = KSensrvChannelTypeIdAccelerometerXYZAxisData; |
|
85 //Disable property listening |
|
86 SetListening(ETrue, EFalse); |
|
87 } |
|
88 |
|
89 void CAccelerometerSensorSym::start() |
|
90 { |
|
91 TSensrvProperty dataFormatProperty; |
|
92 TInt err; |
|
93 CSensorBackendSym::start(); |
|
94 TRAP(err, iBackendData.iSensorChannel->GetPropertyL(KSensrvPropIdChannelDataFormat, ESensrvSingleProperty, dataFormatProperty)); |
|
95 if(err == KErrNone) |
|
96 { |
|
97 TSensrvProperty scaleRangeProperty; |
|
98 TRAP(err, iBackendData.iSensorChannel->GetPropertyL(KSensrvPropIdScaledRange, KSensrvItemIndexNone, scaleRangeProperty)); |
|
99 if(err == KErrNone) |
|
100 { |
|
101 if(scaleRangeProperty.GetArrayIndex() == ESensrvSingleProperty) |
|
102 { |
|
103 if(scaleRangeProperty.PropertyType() == ESensrvIntProperty) |
|
104 { |
|
105 scaleRangeProperty.GetMaxValue(iScaleRange); |
|
106 } |
|
107 else if(scaleRangeProperty.PropertyType() == ESensrvRealProperty) |
|
108 { |
|
109 TReal realScale; |
|
110 scaleRangeProperty.GetMaxValue(realScale); |
|
111 iScaleRange = realScale; |
|
112 } |
|
113 } |
|
114 else if(scaleRangeProperty.GetArrayIndex() == ESensrvArrayPropertyInfo) |
|
115 { |
|
116 TInt index; |
|
117 if(scaleRangeProperty.PropertyType() == ESensrvIntProperty) |
|
118 { |
|
119 scaleRangeProperty.GetValue(index); |
|
120 } |
|
121 else if(scaleRangeProperty.PropertyType() == ESensrvRealProperty) |
|
122 { |
|
123 TReal realIndex; |
|
124 scaleRangeProperty.GetValue(realIndex); |
|
125 index = realIndex; |
|
126 } |
|
127 TRAP(err, iBackendData.iSensorChannel->GetPropertyL(KSensrvPropIdScaledRange, KSensrvItemIndexNone, index, scaleRangeProperty)); |
|
128 if(err == KErrNone) |
|
129 { |
|
130 if(scaleRangeProperty.PropertyType() == ESensrvIntProperty) |
|
131 { |
|
132 scaleRangeProperty.GetMaxValue(iScaleRange); |
|
133 } |
|
134 else if(scaleRangeProperty.PropertyType() == ESensrvRealProperty) |
|
135 { |
|
136 TReal realScaleRange; |
|
137 scaleRangeProperty.GetMaxValue(realScaleRange); |
|
138 iScaleRange = realScaleRange; |
|
139 } |
|
140 } |
|
141 } |
|
142 } |
|
143 } |
|
144 } |
|
145 |
|
146 /* |
|
147 * RecvData is used to retrieve the sensor reading from sensor server |
|
148 * It is implemented here to handle accelerometer sensor specific |
|
149 * reading data and provides conversion and utility code |
|
150 */ |
|
151 void CAccelerometerSensorSym::RecvData(CSensrvChannel &aChannel) |
|
152 { |
|
153 TPckg<TSensrvAccelerometerAxisData> accelerometerpkg( iData ); |
|
154 TInt ret = aChannel.GetData( accelerometerpkg ); |
|
155 if(KErrNone != ret) |
|
156 { |
|
157 // If there is no reading available, return without setting |
|
158 return; |
|
159 } |
|
160 TReal x = iData.iAxisX; |
|
161 TReal y = iData.iAxisY; |
|
162 TReal z = iData.iAxisZ; |
|
163 //Converting unit to m/s^2 |
|
164 if(iScaleRange && iUnit == ESensevChannelUnitAcceleration) |
|
165 { |
|
166 qoutputrangelist rangeList = sensor()->outputRanges(); |
|
167 int outputRange = sensor()->outputRange(); |
|
168 if (outputRange == -1) |
|
169 outputRange = 0; |
|
170 TReal maxValue = rangeList[outputRange].maximum; |
|
171 x = (x/iScaleRange) * maxValue; |
|
172 y = (y/iScaleRange) * maxValue; |
|
173 z = (z/iScaleRange) * maxValue; |
|
174 } |
|
175 else if(iUnit == ESensrvChannelUnitGravityConstant) |
|
176 { |
|
177 //conversion is yet to done |
|
178 } |
|
179 // Get a lock on the reading data |
|
180 iBackendData.iReadingLock.Wait(); |
|
181 // Set qt mobility accelerometer reading with data from sensor server |
|
182 iReading.setX(x); |
|
183 iReading.setY(y); |
|
184 iReading.setZ(z); |
|
185 // Set the timestamp |
|
186 iReading.setTimestamp(iData.iTimeStamp.Int64()); |
|
187 // Release the lock |
|
188 iBackendData.iReadingLock.Signal(); |
|
189 } |
|
190 |
|
191 /** |
|
192 * Second phase constructor |
|
193 * Initialize the backend resources |
|
194 */ |
|
195 void CAccelerometerSensorSym::ConstructL() |
|
196 { |
|
197 //Initialize the backend resources |
|
198 InitializeL(); |
|
199 |
|
200 TInt err; |
|
201 TSensrvProperty unitProperty; |
|
202 TRAP(err, iBackendData.iSensorChannel->GetPropertyL(KSensrvPropIdChannelUnit, ESensrvSingleProperty, unitProperty)); |
|
203 if(err == KErrNone) |
|
204 { |
|
205 unitProperty.GetValue(iUnit); |
|
206 } |
|
207 } |
|
208 |