|
1 /* |
|
2 * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Channel class of Orientation SSY |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef __SSYORIENTATION_H__ |
|
20 #define __SSYORIENTATION_H__ |
|
21 |
|
22 |
|
23 // INCLUDES |
|
24 #include <sensrvdatalistener.h> |
|
25 #include <sensrvchannelinfo.h> |
|
26 #include <sensrvorientationsensor.h> |
|
27 #include <centralrepository.h> |
|
28 #include "SsyChannel.h" |
|
29 #include "SsyTrace.h" |
|
30 #include "Ssyeventtimer.h" |
|
31 #include "OrientationCRListener.h" |
|
32 #include "OrientationConfiguration.h" |
|
33 |
|
34 // FORWARD DECLARATIONS |
|
35 class CSensrvChannelFinder; |
|
36 class CSensrvChannel; |
|
37 class MSendDataCallBack; |
|
38 class CSsyOrientationEventTimer; |
|
39 class TOrientationConfiguration; |
|
40 class TAngleAndTimerConfig; |
|
41 class CSsyOrientationCRListener; |
|
42 class CSensorDataCompensator; |
|
43 |
|
44 // CONSTANTS |
|
45 /** |
|
46 * TRotation |
|
47 */ |
|
48 enum TRotation |
|
49 { |
|
50 ERotationAboutXaxis = 0, |
|
51 ERotationAboutYaxis, |
|
52 ERotationAboutZaxis |
|
53 }; |
|
54 |
|
55 // CLASS DECLARATION |
|
56 |
|
57 /** |
|
58 * CSSYOrientation class |
|
59 * |
|
60 * Orientation calculation and sensorserver client class for orientation ssy. |
|
61 * |
|
62 * @lib orientationssy.lib |
|
63 * @since S60 5.0 |
|
64 */ |
|
65 NONSHARABLE_CLASS( CSSYOrientation ) : public CBase, |
|
66 public MSensrvDataListener, |
|
67 public MSendDataCallBack, |
|
68 public MCenRepCallBack |
|
69 { |
|
70 |
|
71 public: |
|
72 |
|
73 /** |
|
74 * State of the timer |
|
75 */ |
|
76 enum TTimerState |
|
77 { |
|
78 EUninitialized = 0, |
|
79 EStopped, |
|
80 ERunning |
|
81 }; |
|
82 |
|
83 public: // From CActive |
|
84 void RunL(); |
|
85 void DoCancel(); |
|
86 |
|
87 /** |
|
88 * C++ constructor. |
|
89 * |
|
90 * @param aChannelType Identifies the type of the channel |
|
91 */ |
|
92 CSSYOrientation( const TSensrvChannelTypeId aChannelType ); |
|
93 |
|
94 /** |
|
95 * Destructor |
|
96 */ |
|
97 virtual ~CSSYOrientation(); |
|
98 |
|
99 /* |
|
100 * Second Phase Consructor |
|
101 */ |
|
102 void ConstructL(); |
|
103 |
|
104 /** |
|
105 * Create configurations for angles and timers |
|
106 */ |
|
107 void CreateConfigurations(); |
|
108 |
|
109 /** |
|
110 * Used for creating configuration for angle definitions |
|
111 * |
|
112 * @param aConfigurationForState the configuration to set. |
|
113 */ |
|
114 void SetConfigurationForState( |
|
115 const TOrientationConfiguration& |
|
116 aConfigurationForState ); |
|
117 |
|
118 /** |
|
119 * Used for getting configuration for angle definitions |
|
120 * |
|
121 * @param aOrientation to get. |
|
122 * @param aConfigurationForState that is returned. |
|
123 */ |
|
124 void GetConfigurationForState( |
|
125 const TSensrvOrientationData::TSensrvDeviceOrientation aOrientation, |
|
126 TOrientationConfiguration& aConfigurationForState ); |
|
127 |
|
128 /** |
|
129 * From MSensrvDataListener. Indicates data is available in the receiving buffer. |
|
130 * |
|
131 * @param aChannel Channel which has received the data |
|
132 * @param aCount Number of data items received |
|
133 * @param aDataLost Number of data items lost |
|
134 */ |
|
135 void DataReceived( CSensrvChannel& aChannel, |
|
136 TInt aCount, |
|
137 TInt aDataLost ); |
|
138 |
|
139 /** |
|
140 * From MSensrvDataListener. Data listening failed. |
|
141 * |
|
142 * @param aChannel Channel that received error |
|
143 * @param aError Error cause |
|
144 */ |
|
145 void DataError( CSensrvChannel& aChannel, |
|
146 TSensrvErrorSeverity aError ); |
|
147 |
|
148 /** |
|
149 * Returns a pointer to a specified interface - to allow future extension |
|
150 * of this class without breaking binary compatibility |
|
151 * |
|
152 * @since S60 5.0 |
|
153 * @param aInterfaceUid Identifier of the interface to be retrieved |
|
154 * @param aInterface A reference to a pointer that retrieves the specified interface. |
|
155 */ |
|
156 void GetDataListenerInterfaceL( TUid aInterfaceUid, |
|
157 TAny*& aInterface ); |
|
158 |
|
159 /** |
|
160 * Open channel to sensor server. Used by the channel object. |
|
161 */ |
|
162 void OpenChannelL(); |
|
163 |
|
164 /** |
|
165 * Close channel from sensor server. Used by the channel object. |
|
166 */ |
|
167 void CloseChannelL(); |
|
168 |
|
169 /** |
|
170 * Start listening a channel from sensor server. Used by the channel object. |
|
171 */ |
|
172 void StartListeningL(); |
|
173 |
|
174 /** |
|
175 * Stop listening a channel from sensor server. Used by the channel object. |
|
176 */ |
|
177 void StopListeningL(); |
|
178 |
|
179 /** |
|
180 * Register to get data from the sensor server. Used by the channel object. |
|
181 * |
|
182 * @param aChannel Channel object where to receive data |
|
183 */ |
|
184 void GetDataFromHardware( CSSYChannel* aChannel ); |
|
185 |
|
186 /** |
|
187 * Gets max data rate from accelerometer SSY |
|
188 * |
|
189 * @param aProperty Contains search criteria for property. On |
|
190 * completion, contains found property information. This |
|
191 * property is set to read only as it is not owned by orientation |
|
192 * SSY. |
|
193 */ |
|
194 void GetMaxDataRateL( TSensrvProperty& aProperty ); |
|
195 |
|
196 /** |
|
197 * Calculate device rotation based on the received data. |
|
198 * |
|
199 * @param aAxis1 This is Z-axis when calculating X- or Y-axis rotation. |
|
200 * X-axis when calculating Z-axis rotation. |
|
201 * @param aAxis2 This is Y-axis when calculating X- or Z-axis rotation. |
|
202 * X-axis when calculating Y-axis rotation. |
|
203 * @param aRotation Defines the third axis |
|
204 * @return Rotation of calculated third axis |
|
205 */ |
|
206 TInt CalculateDeviceRotationInDegrees( |
|
207 const TInt aAxis1, |
|
208 const TInt aAxis2, |
|
209 const TRotation aRotation ); |
|
210 |
|
211 /** |
|
212 * Calculates the spherical coordinates from the acceleration vector. |
|
213 * |
|
214 * @param aAxisX X Axis of the vector |
|
215 * @param aAxisY Y axis of the vector |
|
216 * @param aAxisZ Z axis of the vector |
|
217 * @param aZenithAngle The zenithe ange of the vector. |
|
218 * @param aAzimuthAngle The azimuth angle of the vector. |
|
219 * @return Standard Symbian error codes. |
|
220 */ |
|
221 TInt CalculateSphericalPolarCoordinates( |
|
222 const TInt aAxisX, |
|
223 const TInt aAxisY, |
|
224 const TInt aAxisZ, |
|
225 TInt& aZenithAngle, |
|
226 TInt& aAzimuthAngle ); |
|
227 |
|
228 /** |
|
229 * Calculate device orientation based on the received data. |
|
230 * |
|
231 * @param aZenithAngle the calculated zenith angle. |
|
232 * @param aAzimuthAngle the calculated azimuth angle. |
|
233 * @return The device orientation. |
|
234 */ |
|
235 TSensrvOrientationData::TSensrvDeviceOrientation CalculateDeviceOrientation( |
|
236 const TInt aZenithAngle, |
|
237 const TInt aAzimuthAngle ); |
|
238 |
|
239 TBool IsOrientation( |
|
240 const TInt aZenithAngle, |
|
241 const TInt aAzimuthAngle, |
|
242 TInt aCorrectionToState, |
|
243 TInt aCorrectionToState1, |
|
244 TInt aCorrectionToState2, |
|
245 TInt aCorrectionToState3 ); |
|
246 |
|
247 protected: |
|
248 |
|
249 // @see MSendDataCallBack |
|
250 void SendDataAfterTimer(); |
|
251 |
|
252 private: |
|
253 |
|
254 /** |
|
255 * Channel type. |
|
256 */ |
|
257 TSensrvChannelTypeId iChannelType; |
|
258 |
|
259 /** |
|
260 * Orientation ssy channel. Not owned. Pointer is assigned |
|
261 * in GetDataFromHardware function. |
|
262 */ |
|
263 CSSYChannel* iChannel; |
|
264 |
|
265 /** |
|
266 * Sensor server channel finder. |
|
267 */ |
|
268 CSensrvChannelFinder* iChannelFinder; |
|
269 |
|
270 /** |
|
271 * List of channelinfos. |
|
272 */ |
|
273 RSensrvChannelInfoList iChannelInfoList; |
|
274 |
|
275 /** |
|
276 * Sensor server channel. |
|
277 */ |
|
278 CSensrvChannel* iSensorChannel; |
|
279 |
|
280 /** |
|
281 * Previous TSensrvOrientationData. |
|
282 */ |
|
283 TSensrvOrientationData iOrientationEvent; |
|
284 |
|
285 /** |
|
286 * Current state of orientation. |
|
287 */ |
|
288 TSensrvOrientationData iCurrentOrientationState; |
|
289 |
|
290 /** |
|
291 * Previous TSensrvRotationData. |
|
292 */ |
|
293 TSensrvRotationData iRotationEvent; |
|
294 |
|
295 /** |
|
296 * State of the timer |
|
297 */ |
|
298 TTimerState iTimerState; |
|
299 |
|
300 /** |
|
301 * Pointer to the timer instance, owned |
|
302 */ |
|
303 CSsyOrientationEventTimer* iEventTimer; |
|
304 |
|
305 /** |
|
306 * The array of orientation that is calculated |
|
307 */ |
|
308 RArray<TInt> iOrientationArray; |
|
309 |
|
310 /** |
|
311 * The configuration for the current state. |
|
312 */ |
|
313 TOrientationConfiguration iConfigForCurrentState; |
|
314 |
|
315 /** |
|
316 * The array containing the different configurations. |
|
317 */ |
|
318 RArray<TOrientationConfiguration> iConfigArray; |
|
319 |
|
320 /** |
|
321 * Pointer to central repository, owned |
|
322 */ |
|
323 CRepository* iRepository; |
|
324 |
|
325 #ifdef AUTO_ORIENTAION_TEST |
|
326 /** |
|
327 * Pointer to the CR listener object, owned. |
|
328 * This is used only for test application. The testing flag must be |
|
329 * defined in order to use this. |
|
330 */ |
|
331 CSsyOrientationCRListener* iCRListener; |
|
332 #endif |
|
333 |
|
334 /** |
|
335 * Boolean indicating is received data first one |
|
336 */ |
|
337 TBool iFirstDataReceived; |
|
338 |
|
339 /** |
|
340 * Sensor compensator. |
|
341 */ |
|
342 CSensorDataCompensator* iCompensator; |
|
343 |
|
344 }; |
|
345 |
|
346 #endif // __SSYORIENTATION_H__ |
|
347 |
|
348 // End of File |