Symbian手机振动API
2010-07-22 01:41:00 来源:WEB开发网1. 添加头文件,库文件
#include
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对象。
更多精彩
赞助商链接