2 * Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
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".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
29 * Minimum allowed intensity setting for vibra. When intensity is negative,
30 * the vibra motor rotates in the negative direction.
36 const TInt KHWRMVibraMinIntensity = -100;
39 * Minimum allowed intensity setting for vibra pulse.
44 const TInt KHWRMVibraMinPulseIntensity = 1;
48 * Maximum allowed intensity setting for vibra. When intensity is positive,
49 * the vibra motor rotates in the positive direction. Value 0 effectively
55 const TInt KHWRMVibraMaxIntensity = 100;
58 * Maximum allowed duration value in milliseconds. Maximum vibrating time
59 * supported by device is declared in KVibraCtrlMaxTime cenrep-key.
62 * Note that duration probably has device specific
63 * maximum duration that is much lower.
68 const TInt KHWRMVibraMaxDuration = (KMaxTInt / 1000) - 1;
71 * KHWRMVibraInfiniteDuration specifies, that vibrating should continue maximum
72 * vibrating time supported by device if vibrating is not explicitly stopped.
78 const TInt KHWRMVibraInfiniteDuration = 0;
81 class MHWRMVibraObserver;
82 class MHWRMVibraFeedbackObserver;
85 * The class used to control the device vibra.
87 * HW Resource Manager Vibra API is a library API providing ability to control
88 * the device vibra. The API provides also methods to retrieve the current settings
89 * of the vibration feature in the user profile and the current status of the vibra.
91 * The type of HW Resource Manager Vibra API is a synchronous method call meaning
92 * the method call will block the client application. The API is meant for all
93 * applications which need to control the device vibra.
95 * The API consist of the classes CHWRMVibra and MHWRMVibraObserver. If the client
96 * requires up-to-date status information, it should also provide callback pointer
97 * of the MHWRMVibraObserver implementing class for the NewL-method.
102 * #include <hwrmvibra.h>
104 * // A CHWRMVibra instance can be created by using NewL() or NewLC() methods.
105 * // Up-to-date status information not required, no callbacks.
106 * CHWRMVibra* vibra = CHWRMVibra::NewL();
108 * // After this, vibra can be directly controlled via the provided class methods.
109 * vibra->StartVibraL(5000); // Start vibra for five seconds
110 * vibra->StopVibraL(); // Immediately stop vibra
112 * // To clean up, delete the created object:
119 class CHWRMVibra : public CBase
123 * Vibration setting in the user profile.
128 Not initialized yet or there is an error condion.
130 EVibraModeUnknown = 0,
132 Vibration setting in the user profile is on.
136 Vibration setting in the user profile is off.
142 * Status of the vibration feature
147 Vibra is not initialized yet or status is uncertain because of an error condition.
149 EVibraStatusUnknown = 0,
151 Vibra is set off in the user profile or some application is specifically blocking vibra.
153 EVibraStatusNotAllowed,
164 * Tactile feedback vibration setting in the user profile.
166 enum TVibraFeedbackModeState
168 EVibraFeedbackModeUnknown = 0, ///< Not initialized yet or there is an error condion.
169 EVibraFeedbackModeON, ///< Feedback vibration setting in the user profile is on.
170 EVibraFeedbackModeOFF ///< Feedback vibration setting in the user profile is off.
174 * Two-phased constructor.
176 * @return A pointer to a new instance of the CHWRMVibra class.
178 * @leave KErrNotSupported Device doesn't support vibration feature.
179 * @leave KErrNoMemory There is a memory allocation failure.
181 IMPORT_C static CHWRMVibra* NewL();
184 * Two-phased constructor.
185 * Leaves instance to cleanup stack.
187 * @return A pointer to a new instance of the CHWRMVibra class.
189 * @leave KErrNotSupported Device doesn't support vibration feature.
190 * @leave KErrNoMemory There is a memory allocation failure.
192 IMPORT_C static CHWRMVibra* NewLC();
195 * Two-phased constructor.
196 * Use this method for creating a vibra client with callbacks.
198 * @param aCallback Pointer to callback instance
199 * @return A pointer to a new instance of the CHWRMVibra class.
201 * @leave KErrNotSupported Device doesn't support vibration feature.
202 * @leave KErrNoMemory There is a memory allocation failure.
204 IMPORT_C static CHWRMVibra* NewL(MHWRMVibraObserver* aCallback);
207 * Two-phased constructor.
208 * Use this method for creating a vibra client with callbacks.
209 * Leaves instance to cleanup stack.
211 * @param aCallback Pointer to callback instance
212 * @return A pointer to a new instance of the CHWRMVibra class.
214 * @leave KErrNotSupported Device doesn't support vibration feature.
215 * @leave KErrNoMemory There is a memory allocation failure.
217 IMPORT_C static CHWRMVibra* NewLC(MHWRMVibraObserver* aCallback);
219 public: // New functions
222 * Reserves vibration feature exclusively for this client.
223 * A higher priority client may cause lower priority client reservation
224 * to be temporarily suspended. Commands can still be issued in suspended
225 * state, but they will not be acted upon unless suspension is lifted
226 * within specified duration.
227 * The suspended client will not get any notification about suspension.
228 * If vibra is already reserved by a higher or equal priority application,
229 * reserving will still succeed, but reservation is immediately suspended.
231 * Calling this method is equal to call ReserveVibraL(EFalse, EFalse),
232 * i.e. any previously frozen state will not be restored and CCoeEnv
233 * background/foreground status is always used to control further reservations.
235 * @leave KErrAccessDenied No CCoeEnv present.
236 * @leave KErrNotReady Trying to reserve while on background.
237 * @leave KErrNoMemory There is a memory allocation failure.
239 virtual void ReserveVibraL()=0;
242 * Reserves vibration feature exclusively for this client.
243 * A higher priority client may cause lower priority client reservation
244 * to be temporarily suspended. Commands can still be issued in suspended
245 * state, but they will not be acted upon unless suspension is lifted
246 * within specified duration.
247 * The suspended client will not get any notification about suspension.
248 * If vibra is already reserved by a higher or equal priority application,
249 * reserving will still succeed, but reservation is immediately suspended.
252 * @param aRestoreState If ETrue, the state frozen on last release will be
253 * restored upon successful reservation.
254 * I.e. if vibra was on when it was released by this
255 * client the last time, it would continue the vibrating
256 * upon successful reservation.
257 * For the first reservation of each session this
258 * parameter is always considered EFalse regardless of
259 * what is supplied, as there is no previous frozen state
261 * @param aForceNoCCoeEnv If EFalse, then reservation requires that this client
262 * has the keyboard focus at the time of reservation and
263 * vibra will be automatically released and re-reserved
264 * based on the keyboard focus status of this client.
265 * This also implies that CCoeEnv::Static() != NULL is
267 * If ETrue, the client will not require CCoeEnv to be
268 * present nor does it automatically reserve/release vibra
269 * by depending on foreground/background status of the
271 * Only trusted clients are allowed to set this flag to
272 * ETrue. A client is considered trusted if it has nonstandard
273 * priority defined in the internal vibra policy of the
274 * HW Resource Manager. A client can be defined trusted
277 * @leave KErrAccessDenied Parameter aForceNoCCoeEnv is ETrue and client is not
279 * @leave KErrBadHandle Parameter aForceNoCCoeEnv is EFalse and no CCoeEnv present.
280 * @leave KErrNotReady Trying to reserve while on background and parameter
281 * aForceNoCCoeEnv is EFalse.
282 * @leave KErrNoMemory There is a memory allocation failure.
284 virtual void ReserveVibraL(TBool aRestoreState, TBool aForceNoCCoeEnv)=0;
287 * Releases vibration feature if it was previously reserved for this client.
288 * If this client has not reserved vibration feature, does nothing.
289 * If vibra is on when it is released and no other client has a suspended
290 * reservation, vibra is stopped.
292 virtual void ReleaseVibra()=0;
296 * Starts the device vibration feature with the product specific default
298 * If StartVibraL is called again before the first vibration completes
299 * then the first vibration is interrupted and the second vibrations
300 * starts immediately -- i.e. The periods of vibration are not cumulative.
302 * The vibration can be interrupted with the method StopVibraL before
303 * the specified interval has elapsed.
305 * Vibra settings of the vibration feature in the user profile
308 * Note: The device may have implementation defined or hardware imposed
309 * limits to the duration of the vibration feature. In such
310 * circumstances any vibration will cut off at that limit even if
311 * the duration parameter is greater than the limit.
313 * @param aDuration Duration of the vibration measured in milliseconds.
314 * A value of 0 specifies that the vibration should
315 * continue indefinetely and should be stopped with a
316 * call to StopVibraL. Duration can have maximum value
317 * of KHWRMVibraMaxDuration.
319 * @leave KErrArgument Duration is invalid.
320 * @leave KErrAccessDenied Vibration setting in the user profile is not set.
321 * @leave KErrBadHandle Vibra session has been invalidated.
322 * @leave KErrLocked Vibra is locked down because too much continuous use
323 * or explicitly blocked by for example some vibration
324 * sensitive accessory.
325 * @leave KErrTimedOut Timeout occurred in controlling vibra.
326 * @leave KErrInUse Vibra is not reserved to this client but it is
327 * reserved to some other client.
328 * @leave KErrNoMemory There is a memory allocation failure.
329 * @leave KErrGeneral There is a hardware error.
331 * @see MHWRMVibraObserver
333 virtual void StartVibraL(TInt aDuration)=0;
336 * Starts the device vibration feature. If StartVibraL is called again before
337 * the first vibration completes then the first vibration is interrupted
338 * and the second vibrations starts immediately -- i.e. The periods of
339 * vibration are not cumulative.
341 * The vibration can be interrupted with the method StopVibraL before
342 * the specified interval has elapsed.
344 * Vibra settings of the vibration feature in the user profile
347 * Note: The device may have implementation defined or hardware imposed
348 * limits to the duration of the vibration feature. In such
349 * circumstances any vibration will cut off at that limit even if
350 * the duration parameter is greater than the limit.
352 * @param aDuration Duration of the vibration measured in milliseconds.
353 * A value of 0 specifies that the vibration should
354 * continue indefinitly and should be stopped with a
355 * call to StopVibraL. Duration can have maximum value
356 * of KHWRMVibraMaxDuration.
357 * @param aIntensity Intensity of the vibra in decimal is -100 to 100,
358 * which shows the percentage of the vibra motor full
359 * rotation speed. When intensity is negative,
360 * the vibra motor rotates in the negative direction.
361 * When intensity is positive, the vibra motor rotates
362 * in the positive direction. Value 0 stops the vibra.
363 * NOTE: The device might have hardware-imposed limits
364 * on supported vibra intensity values, so actual
365 * effect might vary between different hardware.
367 * @leave KErrNotSupported The device doesn't support user-defined
369 * @leave KErrArgument One of the parameters is out of range.
370 * @leave KErrAccessDenied Vibration setting in the user profile
372 * @leave KErrBadHandle Vibra session has been invalidated.
373 * @leave KErrLocked Vibra is locked down because too much continuous use
374 * or explicitly blocked by for example some vibration
375 * sensitive accessory.
376 * @leave KErrTimedOut Timeout occurred in controlling vibra.
377 * @leave KErrInUse Vibra is not reserved to this client but it is
378 * reserved to some other client.
379 * @leave KErrNoMemory There is a memory allocation failure.
380 * @leave KErrGeneral There is a hardware error.
382 * @see MHWRMVibraObserver
384 virtual void StartVibraL(TInt aDuration, TInt aIntensity)=0;
387 * Interrupts the device vibration that is started with the StartVibraL
388 * method immediately.
390 * @leave KErrBadHandle Vibra session has been invalidated.
391 * @leave KErrTimedOut Timeout occurred in controlling vibra.
392 * @leave KErrInUse Vibra is not reserved to this client but it is
393 * reserved to some other client.
394 * @leave KErrNoMemory There is a memory allocation failure.
395 * @leave KErrGeneral There is a hardware error.
397 * @see MHWRMVibraObserver
399 virtual void StopVibraL()=0;
402 * This method retrieves the current settings of the vibration feature
403 * in the user profile. The developer can check the Vibra settings
404 * in the profile and if there is no Vibra active but it is needed by
405 * the client application then the user can be informed.
407 * @return TVibraModeState indicating the current vibra mode setting.
409 * @see TVibraModeState
410 * @see MHWRMVibraObserver
412 virtual TVibraModeState VibraSettings() const=0;
415 * This method retrieves the current vibra status.
417 * @return TVibraStatus indicating the current vibra status
420 * @see MHWRMVibraObserver
422 virtual TVibraStatus VibraStatus() const=0;
425 * This method is intended only for firmware build time configured
426 * privileged clients.
428 * Executes a tactile feedback vibration pulse with product
429 * specific default intensity and duration.
430 * If PulseVibraL is called before ongoing vibration completes and
431 * PulseVibraL calling client has higher priority than executing client,
432 * pulse request is accepted. Also possible vibra-reservations are bypassed.
433 * If client calling PulseVibraL has lower or equal priority
434 * than executing client, ongoing vibration is not affected.
436 * Tactile feedback vibration settings of the vibration feature in the
437 * user profile must be active.
439 * Note: The device may have implementation defined or hardware imposed
440 * limits to the duration of the vibration feature. In such
441 * circumstances any vibration will cut off at that limit even if
442 * the duration parameter is greater than the limit.
444 * @param aDuration Duration of the vibration measured in milliseconds.
445 * Duration can have maximum value
446 * of KHWRMVibraMaxDuration.
448 * @leave KErrAccessDenied Vibration setting in the user profile is not set
449 * or client is not privileged to use pulse feature.
450 * @leave KErrBadHandle Vibra session has been invalidated.
451 * @leave KErrLocked Vibra is locked down because too much continuous use
452 * or explicitly blocked by for example some vibration
453 * sensitive accessory.
454 * @leave KErrTimedOut Timeout occurred in controlling vibra.
455 * @leave KErrInUse Vibra is not reserved to this client but it is
456 * reserved to some other client or ongoing vibration
457 * has been requested by higher priority client.
458 * @leave KErrNoMemory There is a memory allocation failure.
459 * @leave KErrGeneral There is a hardware error.
461 * @see MHWRMVibraFeedbackObserver
463 virtual void PulseVibraL()=0;
466 * This method is intended only for firmware build time configured
467 * privileged clients.
469 * Executes a tactile feedback vibration pulse with product
470 * specific default intensity and specified duration.
471 * If PulseVibraL is called before ongoing vibration completes and
472 * PulseVibraL calling client has higher priority than executing client,
473 * pulse request is accepted. Also possible vibra-reservations are bypassed.
474 * If client calling PulseVibraL has lower or equal priority
475 * than executing client, ongoing vibration is not affected.
477 * Tactile feedback vibration settings of the vibration feature in the
478 * user profile must be active.
480 * Note: The device may have implementation defined or hardware imposed
481 * limits to the duration of the vibration feature. In such
482 * circumstances any vibration will cut off at that limit even if
483 * the duration parameter is greater than the limit.
485 * @param aDuration Duration of the vibration measured in milliseconds.
486 * Duration can have maximum value
487 * of KHWRMVibraMaxDuration.
489 * @leave KErrArgument One of the parameters is out of range.
490 * @leave KErrAccessDenied Vibration setting in the user profile is not set
491 * or client is not privileged to use pulse feature.
492 * @leave KErrBadHandle Vibra session has been invalidated.
493 * @leave KErrLocked Vibra is locked down because too much continuous use
494 * or explicitly blocked by for example some vibration
495 * sensitive accessory.
496 * @leave KErrTimedOut Timeout occurred in controlling vibra.
497 * @leave KErrInUse Vibra is not reserved to this client but it is
498 * reserved to some other client or ongoing vibration
499 * has been requested by higher priority client.
500 * @leave KErrNoMemory There is a memory allocation failure.
501 * @leave KErrGeneral There is a hardware error.
503 * @see MHWRMVibraFeedbackObserver
505 virtual void PulseVibraL(TInt aDuration)=0;
508 * This method is intended only for firmware build time configured
509 * privileged clients.
511 * Executes a tactile feedback vibration pulse.
512 * If PulseVibraL is called before ongoing vibration completes and
513 * PulseVibraL calling client has higher priority than executing client,
514 * pulse request is accepted. Also possible vibra-reservations are bypassed.
515 * If client calling PulseVibraL has lower or equal priority
516 * than executing client, ongoing vibration is not affected.
518 * Tactile feedback vibration settings of the vibration feature in the
519 * user profile must be active.
521 * Note: The device may have implementation defined or hardware imposed
522 * limits to the duration of the vibration feature. In such
523 * circumstances any vibration will cut off at that limit even if
524 * the duration parameter is greater than the limit.
526 * @param aDuration Duration of the vibration measured in milliseconds.
527 * Duration can have maximum value
528 * of KHWRMVibraMaxDuration.
529 * @param aIntensity Intensity of the pulse in decimal is KHWRMVibraMinPulseIntensity
530 * to KHWRMVibraMaxIntensity, which shows the percentage
531 * of the vibra motor full rotation speed.
532 * NOTE: The device might have hardware-imposed limits
533 * on supported vibra intensity values, so actual
534 * effect might vary between different hardware.
535 * @leave KErrNotSupported The device doesn't support user-defined
538 * @leave KErrArgument One of the parameters is out of range.
539 * @leave KErrAccessDenied Vibration setting in the user profile is not set
540 * or client is not privileged to use pulse feature.
541 * @leave KErrBadHandle Vibra session has been invalidated.
542 * @leave KErrLocked Vibra is locked down because too much continuous use
543 * or explicitly blocked by for example some vibration
544 * sensitive accessory.
545 * @leave KErrTimedOut Timeout occurred in controlling vibra.
546 * @leave KErrInUse Vibra is not reserved to this client but it is
547 * reserved to some other client or ongoing vibration
548 * has been requested by higher priority client.
549 * @leave KErrNoMemory There is a memory allocation failure.
550 * @leave KErrGeneral There is a hardware error.
552 * @see MHWRMVibraFeedbackObserver
554 virtual void PulseVibraL(TInt aDuration, TInt aIntensity)=0;
557 * Use this method for setting feedback observer.
559 * @param aCallback Pointer to callback instance
561 virtual void SetFeedbackObserver(MHWRMVibraFeedbackObserver* aCallback)=0;
564 * This method retrieves the current settings of the feedback vibration feature
565 * in the user profile. The developer can check the feedback vibration settings
566 * in the profile and if there is no feedback vibration active but it is needed by
567 * the client application then the user can be informed. However, client needs to
568 * explicitly register to listen these changes via SetFeedbackObserver-method.
570 * @return TVibraFeedbackModeState indicating the current vibra feedback mode setting.
572 * @see TVibraFeedbackModeState
573 * @see MHWRMVibraFeedbackObserver
575 virtual TVibraFeedbackModeState VibraFeedbackSettings() const=0;
579 * A callback interface for vibra status reporting.
581 * If the client requires up-to-date status information, the client needs
582 * to derive a class from the MHWRMVibraObserver interface and implement
583 * the VibraModeChanged() and VibraStatusChanged() methods.
585 * A callback object header example:
589 * #include <hwrmvibra.h> // Link against HWRMVibraClient.lib.
591 * class CTest : public CBase,
592 * public MHWRMVibraObserver
599 * static CTest* NewL();
601 * // from MHWRMVibraObserver
602 * virtual void VibraModeChanged(CHWRMVibra::TVibraModeState aStatus);
603 * virtual void VibraStatusChanged(CHWRMVibra::TVibraStatus aStatus);
606 * CHWRMVibra* iVibra;
610 * A callback method implementation example:
613 * void CTest::VibraStatusChanged(CHWRMVibra::TVibraStatus aStatus)
617 * case CHWRMVibra::EVibraStatusUnknown:
618 * RDebug::Print(_L("### Vibra state changed: EVibraStatusUnknown"));
620 * case CHWRMVibra::EVibraStatusNotAllowed:
621 * RDebug::Print(_L("### Vibra state changed: EVibraStatusNotAllowed"));
623 * case CHWRMVibra::EVibraStatusStopped:
624 * RDebug::Print(_L("### Vibra state changed: EVibraStatusStopped"));
626 * case CHWRMVibra::EVibraStatusOn:
627 * RDebug::Print(_L("### Vibra state changed: EVibraStatusOn"));
630 * RDebug::Print(_L("### Vibra state changed: UNDEFINED !"));
639 class MHWRMVibraObserver
644 * Called when the vibration setting in the user profile is changed.
646 * @param aStatus Indicates the new setting.
648 * @see CHWRMVibra::TVibraModeState
650 virtual void VibraModeChanged(CHWRMVibra::TVibraModeState aStatus) = 0;
653 * Called when the device vibration feature state changes
655 * @param aStatus Indicates vibra status.
657 * @see CHWRMVibra::TVibraStatus
659 virtual void VibraStatusChanged(CHWRMVibra::TVibraStatus aStatus) = 0;
667 class MHWRMVibraFeedbackObserver
672 * Called when the tactile feedback vibration setting in the user profile is changed.
674 * @param aMode Indicates the new setting.
676 * @see CHWRMVibra::TVibraFeedbackModeState
678 virtual void VibraFeedbackModeChanged(CHWRMVibra::TVibraFeedbackModeState aMode) = 0;
682 #endif // HWRMVIBRA_H