|
1 /* |
|
2 * Copyright (c) 2006-2006 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: CVibraAction class implementation. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "vibraaction.h" |
|
20 |
|
21 #include <cfactionindication.h> |
|
22 |
|
23 #include "vibratrace.h" |
|
24 #include "vibraactionobserver.h" |
|
25 |
|
26 // CONSTANTS |
|
27 |
|
28 const TInt KMultiplier = 1000; |
|
29 |
|
30 // MEMBER FUNCTIONS |
|
31 |
|
32 CVibraAction* CVibraAction::NewL( MVibraActionObserver& aObserver ) |
|
33 { |
|
34 FUNC_LOG; |
|
35 |
|
36 CVibraAction* self = CVibraAction::NewLC( aObserver ); |
|
37 CleanupStack::Pop( self ); |
|
38 |
|
39 return self; |
|
40 } |
|
41 |
|
42 CVibraAction* CVibraAction::NewLC( MVibraActionObserver& aObserver ) |
|
43 { |
|
44 FUNC_LOG; |
|
45 |
|
46 CVibraAction* self = new( ELeave ) CVibraAction( aObserver ); |
|
47 CleanupStack::PushL( self ); |
|
48 self->ConstructL(); |
|
49 |
|
50 return self; |
|
51 } |
|
52 |
|
53 // Destructor |
|
54 CVibraAction::~CVibraAction() |
|
55 { |
|
56 FUNC_LOG; |
|
57 |
|
58 Cancel(); |
|
59 delete iVibra; |
|
60 } |
|
61 |
|
62 // Vibra feedback should be as exact as possible. Set high priority. |
|
63 CVibraAction::CVibraAction( MVibraActionObserver& aObserver ): |
|
64 CTimer( EPriorityHigh ), |
|
65 iObserver( aObserver ) |
|
66 { |
|
67 FUNC_LOG; |
|
68 |
|
69 // Add into active scheduler if not already added |
|
70 if( !IsAdded() ) |
|
71 { |
|
72 CActiveScheduler::Add( this ); |
|
73 } |
|
74 } |
|
75 |
|
76 void CVibraAction::ConstructL() |
|
77 { |
|
78 FUNC_LOG; |
|
79 |
|
80 // Construct ctimer |
|
81 CTimer::ConstructL(); |
|
82 |
|
83 // Connect to vibra client |
|
84 iVibra = CHWRMVibra::NewL( this ); |
|
85 } |
|
86 |
|
87 // METHODS |
|
88 |
|
89 //----------------------------------------------------------------------------- |
|
90 // CVibraAction::StartVibraL |
|
91 //----------------------------------------------------------------------------- |
|
92 // |
|
93 CCFActionPlugIn::TExecutionTime CVibraAction::StartVibraL( |
|
94 const TVibraActionInfo& aVibraInfo ) |
|
95 { |
|
96 FUNC_LOG; |
|
97 |
|
98 CCFActionPlugIn::TExecutionTime time = CCFActionPlugIn::ENone; |
|
99 |
|
100 INFO( "Vibra started with params:"); |
|
101 INFO_1( ">> Delay: %d", aVibraInfo.iDelay ); |
|
102 INFO_1( ">> Duration: %d", aVibraInfo.iDuration ); |
|
103 INFO_1( ">> Intensity: %d", aVibraInfo.iIntensity ); |
|
104 INFO_1( ">> Repeats: %d", aVibraInfo.iRepeats ); |
|
105 INFO_1( ">> Repeat interval: %d", aVibraInfo.iRepeatInterval ); |
|
106 |
|
107 // First cancel ongoing timer if any |
|
108 Cancel(); |
|
109 |
|
110 // Store parameters |
|
111 iRepeats = 0; |
|
112 iInfo = aVibraInfo; |
|
113 if( iInfo.iDelay ) |
|
114 { |
|
115 // We have to delay vibra |
|
116 After( MicroSeconds( iInfo.iDelay ) ); |
|
117 time = CCFActionPlugIn::ELong; |
|
118 } |
|
119 else |
|
120 { |
|
121 // No delay, start right away |
|
122 time = DoRunVibraL(); |
|
123 } |
|
124 |
|
125 return time; |
|
126 } |
|
127 |
|
128 //----------------------------------------------------------------------------- |
|
129 // CVibraAction::StopVibra |
|
130 //----------------------------------------------------------------------------- |
|
131 // |
|
132 void CVibraAction::StopVibraL() |
|
133 { |
|
134 FUNC_LOG; |
|
135 |
|
136 // First cancel ongoing timer |
|
137 Cancel(); |
|
138 |
|
139 // Stop vibra |
|
140 DoStopVibraL(); |
|
141 |
|
142 INFO( "Vibra stopped"); |
|
143 } |
|
144 |
|
145 //----------------------------------------------------------------------------- |
|
146 // CVibraAction::RunL |
|
147 //----------------------------------------------------------------------------- |
|
148 // |
|
149 void CVibraAction::RunL() |
|
150 { |
|
151 FUNC_LOG; |
|
152 |
|
153 if( DoRunVibraL() == CCFActionPlugIn::ENone ) |
|
154 { |
|
155 // All repeats executed, finnish vibra action |
|
156 iObserver.VibraActionCompletedL(); |
|
157 } |
|
158 } |
|
159 |
|
160 // --------------------------------------------------------------------------- |
|
161 // CVibraAction::RunError |
|
162 // --------------------------------------------------------------------------- |
|
163 // |
|
164 TInt CVibraAction::RunError( TInt aError ) |
|
165 { |
|
166 FUNC_LOG; |
|
167 |
|
168 INFO_1( "CVibraAction::RunError: aError == %d", aError ); |
|
169 |
|
170 // Avoid Panic in CActiveScheduler |
|
171 aError = KErrNone; |
|
172 |
|
173 return aError; |
|
174 } |
|
175 |
|
176 |
|
177 //----------------------------------------------------------------------------- |
|
178 // CVibraAction::DoCancel |
|
179 //----------------------------------------------------------------------------- |
|
180 // |
|
181 void CVibraAction::DoCancel() |
|
182 { |
|
183 FUNC_LOG; |
|
184 |
|
185 // Stop vibra just in case |
|
186 TRAP_IGNORE( DoStopVibraL() ); |
|
187 } |
|
188 |
|
189 //----------------------------------------------------------------------------- |
|
190 // CVibraAction::VibraModeChanged |
|
191 //----------------------------------------------------------------------------- |
|
192 // |
|
193 void CVibraAction::VibraModeChanged( CHWRMVibra::TVibraModeState aStatus ) |
|
194 { |
|
195 FUNC_LOG; |
|
196 |
|
197 INFO_1( "Old vibra mode: %d", iVibraModeState ); |
|
198 iVibraModeState = aStatus; |
|
199 INFO_1( "New vibra mode: %d", iVibraModeState ); |
|
200 } |
|
201 |
|
202 //----------------------------------------------------------------------------- |
|
203 // CVibraAction::VibraStatusChanged |
|
204 //----------------------------------------------------------------------------- |
|
205 // |
|
206 void CVibraAction::VibraStatusChanged( |
|
207 CHWRMVibra::TVibraStatus /*aStatus*/ ) |
|
208 { |
|
209 FUNC_LOG; |
|
210 |
|
211 // Nothing to do |
|
212 } |
|
213 |
|
214 //----------------------------------------------------------------------------- |
|
215 // CVibraAction::DoRunVibraL |
|
216 //----------------------------------------------------------------------------- |
|
217 // |
|
218 CCFActionPlugIn::TExecutionTime CVibraAction::DoRunVibraL() |
|
219 { |
|
220 FUNC_LOG; |
|
221 |
|
222 CCFActionPlugIn::TExecutionTime time = CCFActionPlugIn::ENone; |
|
223 iVibra->StartVibraL( iInfo.iDuration, iInfo.iIntensity ); |
|
224 iRepeats++; |
|
225 |
|
226 INFO_1( "Vibra activated: times = %d", iRepeats ); |
|
227 |
|
228 if( iRepeats < iInfo.iRepeats ) |
|
229 { |
|
230 // We have repeats |
|
231 After( MicroSeconds( iInfo.iRepeatInterval ) ); |
|
232 time = CCFActionPlugIn::ELong; |
|
233 } |
|
234 |
|
235 return time; |
|
236 } |
|
237 |
|
238 //----------------------------------------------------------------------------- |
|
239 // CVibraAction::DoStopVibraL |
|
240 //----------------------------------------------------------------------------- |
|
241 // |
|
242 void CVibraAction::DoStopVibraL() |
|
243 { |
|
244 FUNC_LOG; |
|
245 |
|
246 iVibra->StopVibraL(); |
|
247 iRepeats = 0; |
|
248 } |
|
249 |
|
250 //----------------------------------------------------------------------------- |
|
251 // CVibraAction::MicroSeconds |
|
252 //----------------------------------------------------------------------------- |
|
253 // |
|
254 TTimeIntervalMicroSeconds32 CVibraAction::MicroSeconds( |
|
255 TInt aMilliSeconds ) const |
|
256 { |
|
257 FUNC_LOG; |
|
258 |
|
259 return TTimeIntervalMicroSeconds32( aMilliSeconds * KMultiplier ); |
|
260 } |