|
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: Implementation for controlling S60 device lights. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include <HtiDispatcherInterface.h> |
|
21 #include <HTILogging.h> |
|
22 #include "HtiLightsController.h" |
|
23 |
|
24 // CONSTANTS |
|
25 const static TUid KSysInfoServiceUid = { 0x10210CC7 }; |
|
26 |
|
27 const static TInt KLightStatusCmdLength = 2; |
|
28 const static TInt KLightOnCmdLength = 6; |
|
29 const static TInt KLightOffCmdLength = 5; |
|
30 const static TInt KLightBlinkCmdLength = 9; |
|
31 |
|
32 enum TSysInfoLightControlCommand |
|
33 { |
|
34 ELightStatus = 0x30, |
|
35 ELightOn = 0x31, |
|
36 ELightOff = 0x32, |
|
37 ELightBlink = 0x33 |
|
38 }; |
|
39 |
|
40 _LIT8( KErrDescrArgument, "Invalid argument" ); |
|
41 _LIT8( KErrDescrLightOn, "LightOn failed" ); |
|
42 _LIT8( KErrDescrLightOff, "LightOff failed" ); |
|
43 _LIT8( KErrDescrLightBlink, "LightBlink failed" ); |
|
44 |
|
45 // ============================ MEMBER FUNCTIONS =============================== |
|
46 |
|
47 // ----------------------------------------------------------------------------- |
|
48 // CHtiLightsController::NewL |
|
49 // Two-phased constructor. |
|
50 // ----------------------------------------------------------------------------- |
|
51 // |
|
52 CHtiLightsController* CHtiLightsController::NewL( MHtiDispatcher* aDispatcher ) |
|
53 { |
|
54 CHtiLightsController* self = new (ELeave) CHtiLightsController( |
|
55 aDispatcher ); |
|
56 CleanupStack::PushL( self ); |
|
57 self->ConstructL(); |
|
58 CleanupStack::Pop(); |
|
59 return self; |
|
60 } |
|
61 |
|
62 |
|
63 // ----------------------------------------------------------------------------- |
|
64 // CHtiLightsController::CHtiLightsController |
|
65 // C++ default constructor. |
|
66 // ----------------------------------------------------------------------------- |
|
67 // |
|
68 CHtiLightsController::CHtiLightsController( |
|
69 MHtiDispatcher* aDispatcher ):iDispatcher( aDispatcher ), |
|
70 iCommand( 0 ), |
|
71 iTarget( 0 ), |
|
72 iDuration( 0 ), |
|
73 iOnDuration( 0 ), |
|
74 iOffDuration( 0 ), |
|
75 iIntensity( 0 ), |
|
76 iFade( EFalse ) |
|
77 { |
|
78 } |
|
79 |
|
80 |
|
81 // ----------------------------------------------------------------------------- |
|
82 // CHtiLightsController::~CHtiLightsController() |
|
83 // Destructor |
|
84 // ----------------------------------------------------------------------------- |
|
85 // |
|
86 CHtiLightsController::~CHtiLightsController() |
|
87 { |
|
88 HTI_LOG_TEXT("CHtiLightsController destroy"); |
|
89 delete iLight; |
|
90 } |
|
91 |
|
92 // Second phase construction |
|
93 void CHtiLightsController::ConstructL() |
|
94 { |
|
95 HTI_LOG_TEXT("CHtiLightsController::ConstructL"); |
|
96 iLight = CHWRMLight::NewL( this ); |
|
97 } |
|
98 |
|
99 |
|
100 // ----------------------------------------------------------------------------- |
|
101 // CHtiLightsController::ProcessMessageL |
|
102 // Called by the plugin when there is a message to be processed by |
|
103 // the lights controller. |
|
104 // ----------------------------------------------------------------------------- |
|
105 // |
|
106 void CHtiLightsController::ProcessMessageL( const TDesC8& aMessage, |
|
107 TDes8& aReply ) |
|
108 { |
|
109 HTI_LOG_FUNC_IN( "CHtiLightsController::ProcessMessageL" ); |
|
110 |
|
111 iCommand = aMessage[0]; |
|
112 iReply.Zero(); |
|
113 |
|
114 switch ( iCommand ) |
|
115 { |
|
116 case ELightStatus: |
|
117 { |
|
118 HTI_LOG_TEXT( "ELightStatus" ); |
|
119 HandleLightStatusL( aMessage ); |
|
120 break; |
|
121 } |
|
122 |
|
123 case ELightOn: |
|
124 { |
|
125 HTI_LOG_TEXT( "ELightOn" ); |
|
126 HandleLightOnL( aMessage ); |
|
127 break; |
|
128 } |
|
129 |
|
130 case ELightOff: |
|
131 { |
|
132 HTI_LOG_TEXT( "ELightOff" ); |
|
133 HandleLightOffL( aMessage ); |
|
134 break; |
|
135 } |
|
136 |
|
137 case ELightBlink: |
|
138 { |
|
139 HTI_LOG_TEXT( "ELightBlink" ); |
|
140 HandleLightBlinkL( aMessage ); |
|
141 break; |
|
142 } |
|
143 |
|
144 default: |
|
145 { |
|
146 // If comes here it's an error from caller. |
|
147 User::Leave( KErrArgument ); |
|
148 } |
|
149 } |
|
150 |
|
151 aReply.Copy( iReply ); |
|
152 |
|
153 HTI_LOG_FUNC_OUT("CHtiLightsController::ProcessMessageL"); |
|
154 } |
|
155 |
|
156 |
|
157 // ----------------------------------------------------------------------------- |
|
158 // CHtiLightsController::HandleLightStatusL |
|
159 // Gets the status of the given light target. |
|
160 // Returns "Not supported" for S60 2.x |
|
161 // ----------------------------------------------------------------------------- |
|
162 // |
|
163 void CHtiLightsController::HandleLightStatusL( const TDesC8& aMessage ) |
|
164 { |
|
165 HTI_LOG_FUNC_IN( "CHtiLightsController::HandleLightStatusL" ); |
|
166 |
|
167 if ( aMessage.Length() != KLightStatusCmdLength ) |
|
168 { |
|
169 iDispatcher->DispatchOutgoingErrorMessage( |
|
170 KErrArgument, KErrDescrArgument, KSysInfoServiceUid ); |
|
171 } |
|
172 |
|
173 else |
|
174 { |
|
175 iTarget = aMessage[1]; |
|
176 iReply.Append( iLight->LightStatus( iTarget ) ); |
|
177 } |
|
178 HTI_LOG_FUNC_OUT( "CHtiLightsController::HandleLightStatusL" ); |
|
179 } |
|
180 |
|
181 |
|
182 // ----------------------------------------------------------------------------- |
|
183 // CHtiLightsController::HandleLightOnL |
|
184 // Turns on light with specified parameters. |
|
185 // For S60 2.x just turns on lights forever, parameters are ignored. |
|
186 // ----------------------------------------------------------------------------- |
|
187 // |
|
188 void CHtiLightsController::HandleLightOnL( const TDesC8& aMessage ) |
|
189 { |
|
190 HTI_LOG_FUNC_IN( "CHtiLightsController::HandleLightOnL" ); |
|
191 |
|
192 if ( aMessage.Length() != KLightOnCmdLength ) |
|
193 { |
|
194 iDispatcher->DispatchOutgoingErrorMessage( |
|
195 KErrArgument, KErrDescrArgument, KSysInfoServiceUid ); |
|
196 return; |
|
197 } |
|
198 |
|
199 // parse values from message |
|
200 iTarget = aMessage[1]; |
|
201 iDuration = aMessage[2] + ( aMessage[3] << 8 ); |
|
202 iIntensity = aMessage[4]; |
|
203 iFade = (TBool)aMessage[5]; |
|
204 |
|
205 TInt err = KErrNone; |
|
206 |
|
207 // normalize possibly abnormal values |
|
208 if ( iIntensity < KHWRMLightMinIntensity ) |
|
209 iIntensity = KHWRMDefaultIntensity; |
|
210 |
|
211 if ( iIntensity > KHWRMLightMaxIntensity ) |
|
212 iIntensity = KHWRMLightMaxIntensity; |
|
213 |
|
214 if ( iDuration < 1 ) iDuration = KHWRMInfiniteDuration; |
|
215 |
|
216 // shoot |
|
217 TRAP( err, iLight->LightOnL( iTarget, iDuration, iIntensity, iFade ) ); |
|
218 |
|
219 if ( err ) |
|
220 { |
|
221 iDispatcher->DispatchOutgoingErrorMessage( |
|
222 err, KErrDescrLightOn, KSysInfoServiceUid ); |
|
223 } |
|
224 |
|
225 else |
|
226 { |
|
227 iReply.Append( 0 ); |
|
228 } |
|
229 |
|
230 HTI_LOG_FUNC_OUT( "CHtiLightsController::HandleLightOnL "); |
|
231 } |
|
232 |
|
233 |
|
234 // ----------------------------------------------------------------------------- |
|
235 // CHtiLightsController::HandleLightOffL |
|
236 // Turns off light with specified parameters. |
|
237 // Returns "Not supported" for S60 2.x |
|
238 // ----------------------------------------------------------------------------- |
|
239 // |
|
240 void CHtiLightsController::HandleLightOffL( const TDesC8& aMessage ) |
|
241 { |
|
242 HTI_LOG_FUNC_IN( "CHtiLightsController::HandleLightOffL" ); |
|
243 |
|
244 if ( aMessage.Length() != KLightOffCmdLength ) |
|
245 { |
|
246 iDispatcher->DispatchOutgoingErrorMessage( |
|
247 KErrArgument, KErrDescrArgument, KSysInfoServiceUid ); |
|
248 return; |
|
249 } |
|
250 |
|
251 // parse values from message |
|
252 iTarget = aMessage[1]; |
|
253 iDuration = aMessage[2] + ( aMessage[3] << 8 ); |
|
254 iFade = (TBool)aMessage[4]; |
|
255 |
|
256 // normalize possibly abnormal values |
|
257 if ( iDuration < 1 ) iDuration = KHWRMInfiniteDuration; |
|
258 |
|
259 // shoot |
|
260 TRAPD( err, iLight->LightOffL( iTarget, iDuration, iFade ) ); |
|
261 |
|
262 if ( err ) |
|
263 { |
|
264 iDispatcher->DispatchOutgoingErrorMessage( |
|
265 err, KErrDescrLightOff, KSysInfoServiceUid ); |
|
266 } |
|
267 |
|
268 else |
|
269 { |
|
270 iReply.Append( 0 ); |
|
271 } |
|
272 HTI_LOG_FUNC_OUT( "CHtiLightsController::HandleLightOffL" ); |
|
273 } |
|
274 |
|
275 |
|
276 // ----------------------------------------------------------------------------- |
|
277 // CHtiLightsController::HandleLightBlinkL |
|
278 // Blinks light with specified parameters. |
|
279 // Returns "Not supported" for S60 2.x |
|
280 // ----------------------------------------------------------------------------- |
|
281 // |
|
282 void CHtiLightsController::HandleLightBlinkL( const TDesC8& aMessage ) |
|
283 { |
|
284 HTI_LOG_FUNC_IN( "CHtiLightsController::HandleLightBlinkL" ); |
|
285 |
|
286 if ( aMessage.Length() != KLightBlinkCmdLength ) |
|
287 { |
|
288 iDispatcher->DispatchOutgoingErrorMessage( |
|
289 KErrArgument, KErrDescrArgument, KSysInfoServiceUid ); |
|
290 return; |
|
291 } |
|
292 |
|
293 // parse values from message |
|
294 iTarget = aMessage[1]; |
|
295 iDuration = aMessage[2] + ( aMessage[3] << 8 ); |
|
296 iOnDuration = aMessage[4] + ( aMessage[5] << 8 ); |
|
297 iOffDuration = aMessage[6] + ( aMessage[7] << 8 ); |
|
298 iIntensity = aMessage[8]; |
|
299 |
|
300 // normalize possibly abnormal values |
|
301 if ( iIntensity < KHWRMLightMinIntensity ) |
|
302 iIntensity = KHWRMDefaultIntensity; |
|
303 |
|
304 if ( iIntensity > KHWRMLightMaxIntensity ) |
|
305 iIntensity = KHWRMLightMaxIntensity; |
|
306 |
|
307 if ( iDuration < 1 ) iDuration = KHWRMInfiniteDuration; |
|
308 |
|
309 if ( iOnDuration < 1 || iOffDuration < 1 ) |
|
310 { |
|
311 iOnDuration = KHWRMDefaultCycleTime; |
|
312 iOffDuration = KHWRMDefaultCycleTime; |
|
313 } |
|
314 |
|
315 // shoot |
|
316 TRAPD( err, iLight->LightBlinkL( |
|
317 iTarget, iDuration, iOnDuration, iOffDuration, iIntensity ) ); |
|
318 |
|
319 if ( err ) |
|
320 { |
|
321 iDispatcher->DispatchOutgoingErrorMessage( |
|
322 err, KErrDescrLightBlink, KSysInfoServiceUid ); |
|
323 } |
|
324 |
|
325 else |
|
326 { |
|
327 iReply.Append( 0 ); |
|
328 } |
|
329 HTI_LOG_FUNC_OUT( "CHtiLightsController::HandleLightBlinkL" ); |
|
330 } |
|
331 |
|
332 |
|
333 // ----------------------------------------------------------------------------- |
|
334 // CHtiLightsController::LightStatusChanged |
|
335 // Called when status of any light target changes. |
|
336 // If infinite duration is requested, restores the state back to what was |
|
337 // last requested. |
|
338 // This method does not exist for S60 2.x |
|
339 // ----------------------------------------------------------------------------- |
|
340 // |
|
341 void CHtiLightsController::LightStatusChanged( TInt aTarget, |
|
342 CHWRMLight::TLightStatus aStatus ) |
|
343 { |
|
344 HTI_LOG_FORMAT( "Light status changed for target %d", aTarget ); |
|
345 HTI_LOG_FORMAT( "New status = %d", aStatus ); |
|
346 HTI_LOG_FORMAT( "Current target = %d", iTarget ); |
|
347 |
|
348 TInt target = aTarget & iTarget; |
|
349 if ( !target ) |
|
350 { |
|
351 HTI_LOG_TEXT( "Not interested about the target" ); |
|
352 return; |
|
353 } |
|
354 |
|
355 HTI_LOG_TEXT( "Matches current target" ); |
|
356 |
|
357 if ( iDuration != KHWRMInfiniteDuration ) |
|
358 { |
|
359 return; |
|
360 } |
|
361 |
|
362 if ( ( aStatus == CHWRMLight::ELightOn && iCommand == ELightOn ) || |
|
363 ( aStatus == CHWRMLight::ELightOff && iCommand == ELightOff ) || |
|
364 ( aStatus == CHWRMLight::ELightBlink && iCommand == ELightBlink ) ) |
|
365 { |
|
366 HTI_LOG_TEXT( "Status already OK" ); |
|
367 return; |
|
368 } |
|
369 |
|
370 HTI_LOG_TEXT( "Infinite duration wanted - restore light status" ); |
|
371 switch ( iCommand ) |
|
372 { |
|
373 case ELightOn: |
|
374 { |
|
375 // Ignore error |
|
376 TRAPD( err, iLight->LightOnL( |
|
377 target, iDuration, iIntensity, iFade ) ); |
|
378 HTI_LOG_FORMAT( "LightOnL return code %d", err ); |
|
379 err = err; // to get rid of compiler warning for non-logging |
|
380 break; |
|
381 } |
|
382 case ELightOff: |
|
383 { |
|
384 // Ignore error |
|
385 TRAPD( err, iLight->LightOffL( target, iDuration, iFade ) ); |
|
386 HTI_LOG_FORMAT( "LightOffL return code %d", err ); |
|
387 err = err; // to get rid of compiler warning for non-logging |
|
388 break; |
|
389 } |
|
390 case ELightBlink: |
|
391 { |
|
392 // Ignore error |
|
393 TRAPD( err, iLight->LightBlinkL( |
|
394 target, iDuration, iOnDuration, |
|
395 iOffDuration, iIntensity ) ); |
|
396 HTI_LOG_FORMAT( "LightBlinkL return code %d", err ); |
|
397 err = err; // to get rid of compiler warning for non-logging |
|
398 break; |
|
399 } |
|
400 default: |
|
401 break; |
|
402 } |
|
403 } |
|
404 |
|
405 // End of file |