Symbian手机振动API

来源:互联网 发布:矩阵实际应用问题 编辑:程序博客网 时间:2024/04/28 03:09

1. 添加头文件,库文件

  #include // For CHWRMVibra, HWRMVibraClient.lib

  2. 声明并实例化用于控制振动的成员

  class CVibraControl;

  CVibraControl* iControl;

  在ConstructL()函数中实例化

  iControl = VibraFactory::NewL();

  3.实现振动函数

  /**

  * DoVibrateL.

  * Called when you want to vibra device

  * @param aDuration Duration of the vibration measured in milliseconds.

  * A value of 0 specifies that the vibration should continue indefinitly

  * and should be stopped with a call to StopVibra.

  * @param aIntensity Intensity of the vibra in decimal is -100 to 100,

  * which shows the percentage of the vibra motor full rotation speed.

  * When intensity is negative, the vibra motor rotates in the negative direction.

  * When intensity is positive, the vibra motor rotates in the positive direction.

  * Value 0 stops the vibra.

  */

  void CVibraTestAppUi::DoVibrateL( TInt aDuration , TInt aIntensity )

  {

  if ( CVibraControl::EVibraModeON == iControl->VibraSettings() ) // get vibration setting in the user profile

  {

  TRAPD(err,iControl->StartVibraL(aDuration, aIntensity));

  }

  }

  需要说明的是StartVibraL函数是异步的,所以不能在调用振动后立即销毁CVibraControl对象,否则手机不会震动的。aDuration表示振动持续时间,以毫秒记(1000表示1S),但由于系统对硬件的保护和电池的限制,一次振动最长持续10S;aIntensity为频率,就是电机的转速(范围为-100~+100),负值表示反转,在真机上测试感觉不太明显,一般取30左右即可。

  4.使用完毕需要释放CVibraControl对象

转载:http://blog.csdn.net/fg313071405/article/details/6370536