|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2009 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 "magnetometersensorsym.h" |
|
44 |
|
45 /** |
|
46 * set the id of the magnetometer sensor |
|
47 */ |
|
48 const char *CMagnetometerSensorSym::id("sym.magnetometer"); |
|
49 |
|
50 /** |
|
51 * Factory function, this is used to create the magnetometer sensor object |
|
52 * @return CMagnetometerSensorSym if successful, leaves on failure |
|
53 */ |
|
54 CMagnetometerSensorSym* CMagnetometerSensorSym::NewL(QSensor *sensor) |
|
55 { |
|
56 CMagnetometerSensorSym* self = new (ELeave) CMagnetometerSensorSym(sensor); |
|
57 CleanupStack::PushL(self); |
|
58 self->ConstructL(); |
|
59 CleanupStack::Pop(); |
|
60 return self; |
|
61 } |
|
62 |
|
63 /** |
|
64 * Destructor |
|
65 * Closes the backend resources |
|
66 */ |
|
67 CMagnetometerSensorSym::~CMagnetometerSensorSym() |
|
68 { |
|
69 //Closes the backend resources |
|
70 Close(); |
|
71 } |
|
72 |
|
73 /** |
|
74 * Default constructor |
|
75 */ |
|
76 CMagnetometerSensorSym::CMagnetometerSensorSym(QSensor *sensor):CSensorBackendSym(sensor), |
|
77 iCalibrationLevel(0.0) |
|
78 { |
|
79 if(sensor) |
|
80 { |
|
81 setReading<QMagnetometerReading>(&iReading); |
|
82 } |
|
83 iBackendData.iSensorType = KSensrvChannelTypeIdMagnetometerXYZAxisData; |
|
84 //Enable Property listening, required to get Calibration level |
|
85 SetListening(ETrue, ETrue); |
|
86 } |
|
87 |
|
88 /** |
|
89 * start is overridden to allow retrieving initial calibration property before |
|
90 * and to set the required value type flags |
|
91 */ |
|
92 void CMagnetometerSensorSym::start() |
|
93 { |
|
94 if(sensor()) |
|
95 { |
|
96 // Initialize the values |
|
97 iReading.setX(0); |
|
98 iReading.setY(0); |
|
99 iReading.setZ(0); |
|
100 // Set the required type of values |
|
101 QVariant v = sensor()->property("returnGeoValues"); |
|
102 iReturnGeoValues = (v.isValid() && v.toBool()); // if the property isn't set it's false |
|
103 } |
|
104 // get current property value for calibration and set it to reading |
|
105 TSensrvProperty calibration; |
|
106 TRAPD(err, iBackendData.iSensorChannel->GetPropertyL(KSensrvPropCalibrationLevel,ESensrvSingleProperty, calibration)); |
|
107 // If error in getting the calibration level, continue to start the sensor |
|
108 // as it is not a fatal error |
|
109 if ( err == KErrNone ) |
|
110 { |
|
111 TInt calibrationVal; |
|
112 calibration.GetValue(calibrationVal); |
|
113 iCalibrationLevel = calibrationVal * (1.0/3.0); |
|
114 } |
|
115 // Call backend start |
|
116 CSensorBackendSym::start(); |
|
117 } |
|
118 |
|
119 /* |
|
120 * RecvData is used to retrieve the sensor reading from sensor server |
|
121 * It is implemented here to handle magnetometer sensor specific |
|
122 * reading data and provides conversion and utility code |
|
123 */ |
|
124 void CMagnetometerSensorSym::RecvData(CSensrvChannel &aChannel) |
|
125 { |
|
126 TPckg<TSensrvMagnetometerAxisData> magnetometerpkg( iData ); |
|
127 TInt ret = aChannel.GetData( magnetometerpkg ); |
|
128 if(KErrNone != ret) |
|
129 { |
|
130 // If there is no reading available, return without setting |
|
131 return; |
|
132 } |
|
133 // Get a lock on the reading data |
|
134 iBackendData.iReadingLock.Wait(); |
|
135 // If Geo values are requested set it |
|
136 if(iReturnGeoValues) |
|
137 { |
|
138 iReading.setX(iData.iAxisXCalibrated); |
|
139 iReading.setY(iData.iAxisYCalibrated); |
|
140 iReading.setZ(iData.iAxisZCalibrated); |
|
141 } |
|
142 // If Raw values are requested set it |
|
143 else |
|
144 { |
|
145 iReading.setX(iData.iAxisXRaw); |
|
146 iReading.setY(iData.iAxisYRaw); |
|
147 iReading.setZ(iData.iAxisZRaw); |
|
148 } |
|
149 // Set the timestamp |
|
150 iReading.setTimestamp(iData.iTimeStamp.Int64()); |
|
151 // Set the calibration level |
|
152 iReading.setCalibrationLevel(iCalibrationLevel); |
|
153 // Release the lock |
|
154 iBackendData.iReadingLock.Signal(); |
|
155 } |
|
156 |
|
157 /** |
|
158 * HandlePropertyChange is called from backend, to indicate a change in property |
|
159 */ |
|
160 void CMagnetometerSensorSym::HandlePropertyChange(CSensrvChannel &/*aChannel*/, const TSensrvProperty &aChangedProperty) |
|
161 { |
|
162 if(aChangedProperty.GetPropertyId() != KSensrvPropCalibrationLevel) |
|
163 { |
|
164 // Do nothing, if calibration property has not changed |
|
165 return; |
|
166 } |
|
167 TInt calibrationlevel; |
|
168 aChangedProperty.GetValue(calibrationlevel); |
|
169 // As Qt requires calibration level in qreal but symbian provides in enum |
|
170 // It has been agreed with DS Team that the following mechanism will be |
|
171 // used till discussions with qt mobility are complete |
|
172 iCalibrationLevel = (1.0/3.0) * calibrationlevel; |
|
173 } |
|
174 |
|
175 /* |
|
176 * Used to retrieve the current calibration level |
|
177 * iCalibrationLevel is automatically updated whenever there is a change |
|
178 * in calibration level |
|
179 */ |
|
180 qreal CMagnetometerSensorSym::GetCalibrationLevel() |
|
181 { |
|
182 return iCalibrationLevel; |
|
183 } |
|
184 |
|
185 /** |
|
186 * Second phase constructor |
|
187 * Initialize the backend resources |
|
188 */ |
|
189 void CMagnetometerSensorSym::ConstructL() |
|
190 { |
|
191 InitializeL(); |
|
192 } |
|
193 |