|
1 /* |
|
2 * Copyright (c) 2009 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: TTCStateTiltListenData class declaration. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef TCSTATETILTLISTENDATA_H |
|
20 #define TCSTATETILTLISTENDATA_H |
|
21 |
|
22 // INCLUDES |
|
23 #include <tiltcompensation.h> |
|
24 #include <e32property.h> |
|
25 |
|
26 #include "tcstatetilt.h" |
|
27 #include "tcsendeventtimer.h" |
|
28 #include "tccenrepobserver.h" |
|
29 |
|
30 // FORWARD DECLARATIONS |
|
31 class CTCSendEventTimer; |
|
32 |
|
33 // CLASS DECLARATION |
|
34 class TTiltXYZValue |
|
35 { |
|
36 public: |
|
37 inline TTiltXYZValue() {}; |
|
38 inline TTiltXYZValue( TInt16 aX, TInt16 aY, TInt16 aZ) : iX(aX), iY(aY), iZ(aZ) {}; |
|
39 TInt16 iX; |
|
40 TInt16 iY; |
|
41 TInt16 iZ; |
|
42 }; |
|
43 |
|
44 /** |
|
45 * Listen data state for tilt channel. |
|
46 * |
|
47 * @lib None |
|
48 * @since S60 5.0 |
|
49 */ |
|
50 NONSHARABLE_CLASS( CTCStateTiltListenData ): public CTCStateTilt, |
|
51 public MSendDataCallBack, |
|
52 public MTCCenrepObserver |
|
53 { |
|
54 |
|
55 //friend class CTCSendEventTimer; |
|
56 |
|
57 private: // Data types |
|
58 |
|
59 // Bit flags to indicate data compensation state |
|
60 enum TTiltDataBit |
|
61 { |
|
62 ENone = 0x0, |
|
63 EAccelerometerData = 0x1, |
|
64 EMagnetometerData = 0x2, |
|
65 EForceBufferFull = 0x4 |
|
66 }; |
|
67 |
|
68 public: |
|
69 |
|
70 /** |
|
71 * Two phased constructor. |
|
72 * |
|
73 * @param aStatePool State pool interface. |
|
74 * @param aTransactionHandler Transaction handler interface. |
|
75 * @return CTCStateTiltListenData |
|
76 */ |
|
77 static CTCStateTiltListenData* NewL( MTCStatePool& aStatePool, |
|
78 MTCTransactionHandler& aTransactionHandler ); |
|
79 |
|
80 /** |
|
81 * Two phased constructor. |
|
82 * |
|
83 * @param aStatePool State pool interface. |
|
84 * @param aTransactionHandler Transaction handler interface. |
|
85 * @return CTCStateTiltListenData |
|
86 */ |
|
87 static CTCStateTiltListenData* NewLC( MTCStatePool& aStatePool, |
|
88 MTCTransactionHandler& aTransactionHandler ); |
|
89 |
|
90 ~CTCStateTiltListenData(); |
|
91 |
|
92 // @see MSendDataCallBack |
|
93 void SendDataAfterTimer(); |
|
94 |
|
95 public: |
|
96 |
|
97 // From MTCCenrepObserver |
|
98 void CenrepValueChanged( TUint32 aKey, CRepository& aRepository ); |
|
99 |
|
100 private: // From base classes |
|
101 |
|
102 // @see TTCStateBase |
|
103 void HandleEventL( TTCEventId aId, TTCEvent* aEvent ); |
|
104 |
|
105 // @see TTCStateBase |
|
106 void HandleTransactionCompletedL( TTCTransactionId aTransactionId, TInt aError ); |
|
107 |
|
108 // @see TTCStateBase |
|
109 void HandleStateEntryL(); |
|
110 |
|
111 // @see TTCStateBase |
|
112 void HandleStateExitL(); |
|
113 |
|
114 private: |
|
115 |
|
116 /** |
|
117 * C++ constructor |
|
118 * |
|
119 * @param aStatePool |
|
120 * @return aTransactionHandler |
|
121 */ |
|
122 CTCStateTiltListenData( MTCStatePool& aStatePool, |
|
123 MTCTransactionHandler& aTransactionHandler ); |
|
124 |
|
125 /** |
|
126 * 2nd phase of construction |
|
127 */ |
|
128 void ConstructL(); |
|
129 |
|
130 private: // New methods |
|
131 |
|
132 // Compensate tilt angle |
|
133 TBool CalculateTilt(); |
|
134 |
|
135 // Flush buffer and change state |
|
136 void CompleteEventL(); |
|
137 |
|
138 // Reset internal data |
|
139 void ResetState( TBool aWriteCountIncluded ); |
|
140 |
|
141 // Get updated cenrep value |
|
142 void GetCenrepValue( CRepository& aCenRep, |
|
143 TUint32 aKey, TInt aIndex ); |
|
144 |
|
145 protected: |
|
146 |
|
147 // From CActive |
|
148 void DoCancel(); |
|
149 |
|
150 // From CActive |
|
151 void RunL(); |
|
152 |
|
153 // From CActive |
|
154 TInt RunError( TInt aError ); |
|
155 |
|
156 private: // Data |
|
157 |
|
158 // Property for Pub/Sub |
|
159 RProperty iSubscribe; |
|
160 |
|
161 /** Tilt input */ |
|
162 TTiltCompensationInput iInput; |
|
163 |
|
164 /** Write count */ |
|
165 TInt iWriteCount; |
|
166 |
|
167 /** Current sampling time */ |
|
168 TTime iTime; |
|
169 |
|
170 // The data rate that is used |
|
171 TInt iHzSamplingRate; |
|
172 |
|
173 // Pointer to the timer |
|
174 CTCSendEventTimer* iTimerToSend; |
|
175 |
|
176 // Flag that states if the property has changed |
|
177 TBool iHasChanged; |
|
178 |
|
179 // The requested amount of data |
|
180 TInt iRequestedDataCount; |
|
181 |
|
182 TInt16 iPreviousTheta; |
|
183 // Tilt compensation parameters |
|
184 RParamsArray iParamsArray; |
|
185 // Handle to the compensation library |
|
186 RLibrary iTiltLib; |
|
187 // A function pointer to compensation function |
|
188 // from the compensation library. |
|
189 CompensateFuncWithParams iCompensationFunc; |
|
190 |
|
191 // Observer for compensation parameter changes. Owned. |
|
192 CTCCenrepObserver* iCenrepObserver; |
|
193 |
|
194 // Arrays for calculating average values for accelerometer and magnetometer time windows |
|
195 RArray<TTiltXYZValue> iArrayMag; |
|
196 RArray<TTiltXYZValue> iArrayAcc; |
|
197 |
|
198 // Sizes of accelerometer and magnetometer time windows |
|
199 TInt iSizeOfAccArray; |
|
200 TInt iSizeOfMagArray; |
|
201 |
|
202 }; |
|
203 |
|
204 #endif // TCSTATETILTLISTENDATA_H |
|
205 |
|
206 // End of File |