40 ****************************************************************************/ |
40 ****************************************************************************/ |
41 |
41 |
42 // Internal Headers |
42 // Internal Headers |
43 #include "magnetometersensorsym.h" |
43 #include "magnetometersensorsym.h" |
44 |
44 |
|
45 #include <sensrvgeneralproperties.h> |
|
46 |
45 /** |
47 /** |
46 * set the id of the magnetometer sensor |
48 * set the id of the magnetometer sensor |
47 */ |
49 */ |
48 const char *CMagnetometerSensorSym::id("sym.magnetometer"); |
50 char const * const CMagnetometerSensorSym::id("sym.magnetometer"); |
49 |
51 |
50 /** |
52 /** |
51 * Factory function, this is used to create the magnetometer sensor object |
53 * Factory function, this is used to create the magnetometer sensor object |
52 * @return CMagnetometerSensorSym if successful, leaves on failure |
54 * @return CMagnetometerSensorSym if successful, leaves on failure |
53 */ |
55 */ |
99 iReading.setZ(0); |
102 iReading.setZ(0); |
100 // Set the required type of values |
103 // Set the required type of values |
101 QVariant v = sensor()->property("returnGeoValues"); |
104 QVariant v = sensor()->property("returnGeoValues"); |
102 iReturnGeoValues = (v.isValid() && v.toBool()); // if the property isn't set it's false |
105 iReturnGeoValues = (v.isValid() && v.toBool()); // if the property isn't set it's false |
103 } |
106 } |
|
107 TInt err; |
104 // get current property value for calibration and set it to reading |
108 // get current property value for calibration and set it to reading |
105 TSensrvProperty calibration; |
109 TSensrvProperty calibration; |
106 TRAPD(err, iBackendData.iSensorChannel->GetPropertyL(KSensrvPropCalibrationLevel,ESensrvSingleProperty, calibration)); |
110 TRAP(err, iBackendData.iSensorChannel->GetPropertyL(KSensrvPropCalibrationLevel, ESensrvSingleProperty, calibration)); |
107 // If error in getting the calibration level, continue to start the sensor |
111 // If error in getting the calibration level, continue to start the sensor |
108 // as it is not a fatal error |
112 // as it is not a fatal error |
109 if ( err == KErrNone ) |
113 if ( err == KErrNone ) |
110 { |
114 { |
111 TInt calibrationVal; |
115 TInt calibrationVal; |
112 calibration.GetValue(calibrationVal); |
116 calibration.GetValue(calibrationVal); |
113 iCalibrationLevel = calibrationVal * (1.0/3.0); |
117 iCalibrationLevel = calibrationVal * (1.0/3.0); |
114 } |
118 } |
115 // Call backend start |
119 // Call backend start |
116 CSensorBackendSym::start(); |
120 CSensorBackendSym::start(); |
|
121 |
|
122 |
|
123 TSensrvProperty dataFormatProperty; |
|
124 TRAP(err, iBackendData.iSensorChannel->GetPropertyL(KSensrvPropIdChannelDataFormat, ESensrvSingleProperty, dataFormatProperty)); |
|
125 if(err == KErrNone) |
|
126 { |
|
127 TInt dataFormat; |
|
128 dataFormatProperty.GetValue(dataFormat); |
|
129 if(dataFormat == ESensrvChannelDataFormatScaled) |
|
130 { |
|
131 TSensrvProperty scaleRangeProperty; |
|
132 TRAP(err, iBackendData.iSensorChannel->GetPropertyL(KSensrvPropIdScaledRange, KSensrvItemIndexNone, scaleRangeProperty)); |
|
133 if(err == KErrNone) |
|
134 { |
|
135 if(scaleRangeProperty.GetArrayIndex() == ESensrvSingleProperty) |
|
136 { |
|
137 if(scaleRangeProperty.PropertyType() == ESensrvIntProperty) |
|
138 { |
|
139 scaleRangeProperty.GetMaxValue(iScaleRange); |
|
140 } |
|
141 else if(scaleRangeProperty.PropertyType() == ESensrvRealProperty) |
|
142 { |
|
143 TReal realScale; |
|
144 scaleRangeProperty.GetMaxValue(realScale); |
|
145 iScaleRange = realScale; |
|
146 } |
|
147 } |
|
148 else if(scaleRangeProperty.GetArrayIndex() == ESensrvArrayPropertyInfo) |
|
149 { |
|
150 TInt index; |
|
151 if(scaleRangeProperty.PropertyType() == ESensrvIntProperty) |
|
152 { |
|
153 scaleRangeProperty.GetValue(index); |
|
154 } |
|
155 else if(scaleRangeProperty.PropertyType() == ESensrvRealProperty) |
|
156 { |
|
157 TReal realIndex; |
|
158 scaleRangeProperty.GetValue(realIndex); |
|
159 index = realIndex; |
|
160 } |
|
161 TRAP(err, iBackendData.iSensorChannel->GetPropertyL(KSensrvPropIdScaledRange, KSensrvItemIndexNone, index, scaleRangeProperty)); |
|
162 if(err == KErrNone) |
|
163 { |
|
164 if(scaleRangeProperty.PropertyType() == ESensrvIntProperty) |
|
165 { |
|
166 scaleRangeProperty.GetMaxValue(iScaleRange); |
|
167 } |
|
168 else if(scaleRangeProperty.PropertyType() == ESensrvRealProperty) |
|
169 { |
|
170 TReal realScaleRange; |
|
171 scaleRangeProperty.GetMaxValue(realScaleRange); |
|
172 iScaleRange = realScaleRange; |
|
173 } |
|
174 } |
|
175 } |
|
176 } |
|
177 } |
|
178 } |
117 } |
179 } |
118 |
180 |
119 /* |
181 /* |
120 * RecvData is used to retrieve the sensor reading from sensor server |
182 * RecvData is used to retrieve the sensor reading from sensor server |
121 * It is implemented here to handle magnetometer sensor specific |
183 * It is implemented here to handle magnetometer sensor specific |
128 if(KErrNone != ret) |
190 if(KErrNone != ret) |
129 { |
191 { |
130 // If there is no reading available, return without setting |
192 // If there is no reading available, return without setting |
131 return; |
193 return; |
132 } |
194 } |
133 // Get a lock on the reading data |
195 |
134 iBackendData.iReadingLock.Wait(); |
196 TReal x, y, z; |
135 // If Geo values are requested set it |
197 // If Geo values are requested set it |
136 if(iReturnGeoValues) |
198 if(iReturnGeoValues) |
137 { |
199 { |
138 iReading.setX(iData.iAxisXCalibrated); |
200 x = iData.iAxisXCalibrated; |
139 iReading.setY(iData.iAxisYCalibrated); |
201 y = iData.iAxisYCalibrated; |
140 iReading.setZ(iData.iAxisZCalibrated); |
202 z = iData.iAxisZCalibrated; |
141 } |
203 } |
142 // If Raw values are requested set it |
204 // If Raw values are requested set it |
143 else |
205 else |
144 { |
206 { |
145 iReading.setX(iData.iAxisXRaw); |
207 x = iData.iAxisXRaw; |
146 iReading.setY(iData.iAxisYRaw); |
208 y = iData.iAxisYRaw; |
147 iReading.setZ(iData.iAxisZRaw); |
209 z = iData.iAxisZRaw; |
148 } |
210 } |
|
211 // Scale adjustments |
|
212 if(iScaleRange) |
|
213 { |
|
214 qoutputrangelist rangeList = sensor()->outputRanges(); |
|
215 TReal maxValue = rangeList[sensor()->outputRange()].maximum; |
|
216 x = (x/iScaleRange) * maxValue; |
|
217 y = (y/iScaleRange) * maxValue; |
|
218 z = (z/iScaleRange) * maxValue; |
|
219 } |
|
220 // Get a lock on the reading data |
|
221 iBackendData.iReadingLock.Wait(); |
|
222 iReading.setX(x); |
|
223 iReading.setY(y); |
|
224 iReading.setZ(z); |
149 // Set the timestamp |
225 // Set the timestamp |
150 iReading.setTimestamp(iData.iTimeStamp.Int64()); |
226 iReading.setTimestamp(iData.iTimeStamp.Int64()); |
151 // Set the calibration level |
227 // Set the calibration level |
152 iReading.setCalibrationLevel(iCalibrationLevel); |
228 iReading.setCalibrationLevel(iCalibrationLevel); |
153 // Release the lock |
229 // Release the lock |