40 ****************************************************************************/ |
40 ****************************************************************************/ |
41 |
41 |
42 // Internal Headers |
42 // Internal Headers |
43 #include "rotationsensorsym.h" |
43 #include "rotationsensorsym.h" |
44 |
44 |
|
45 #include <sensrvgeneralproperties.h> |
|
46 |
45 /** |
47 /** |
46 * set the id of the proximity sensor |
48 * set the id of the proximity sensor |
47 */ |
49 */ |
48 const char *CRotationSensorSym::id("sym.rotation"); |
50 char const * const CRotationSensorSym::id("sym.rotation"); |
|
51 |
|
52 const TInt KMinimumRange = -180; |
|
53 const TInt KMaximumRange = 180; |
49 |
54 |
50 /** |
55 /** |
51 * Factory function, this is used to create the rotation sensor object |
56 * Factory function, this is used to create the rotation sensor object |
52 * @return CRotationSensorSym if successful, leaves on failure |
57 * @return CRotationSensorSym if successful, leaves on failure |
53 */ |
58 */ |
94 return; |
99 return; |
95 } |
100 } |
96 // Get a lock on the reading data |
101 // Get a lock on the reading data |
97 iBackendData.iReadingLock.Wait(); |
102 iBackendData.iReadingLock.Wait(); |
98 // To Do verify with ds and ramsay |
103 // To Do verify with ds and ramsay |
99 iReading.setX(iData.iDeviceRotationAboutXAxis); |
104 |
100 iReading.setY(iData.iDeviceRotationAboutYAxis-180); |
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 |
101 if(iData.iDeviceRotationAboutZAxis == TSensrvRotationData::KSensrvRotationUndefined) |
131 if(iData.iDeviceRotationAboutZAxis == TSensrvRotationData::KSensrvRotationUndefined) |
102 { |
132 { |
103 sensor()->setProperty("hasZ", QVariant(FALSE)); |
133 sensor()->setProperty("hasZ", QVariant(FALSE)); |
104 } |
134 } |
105 else |
135 else |
106 { |
136 { |
107 sensor()->setProperty("hasZ", QVariant(TRUE)); |
137 sensor()->setProperty("hasZ", QVariant(TRUE)); |
108 iReading.setZ(iData.iDeviceRotationAboutZAxis-180); |
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 } |
109 } |
148 } |
110 // Set the timestamp |
149 // Set the timestamp |
111 iReading.setTimestamp(iData.iTimeStamp.Int64()); |
150 iReading.setTimestamp(iData.iTimeStamp.Int64()); |
112 // Release the lock |
151 // Release the lock |
113 iBackendData.iReadingLock.Signal(); |
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); |
114 } |
172 } |
115 |
173 |
116 |
174 |
117 /** |
175 /** |
118 * Second phase constructor |
176 * Second phase constructor |