Saturday, September 8, 2007

Vibrating your PocketPC device!

How to vibrate a PocketPC WM5.0 or 2003 device?

In smartphone platforms there is a Vibrate API which you can use.
Although MSDN mentioned that it exist in WM5.0,it isn't.
There was a mistake in MSDN documentations.

Searching all over internet I find that there are 2 ways to achieve this.
One way is to use Notify functions like CeSetUserNotificationEx,and setting trigger time to now.
But unless you display a dialog(using PUN_DIALOG),you can't use it and also it seems user settings override your program settings!

Another way is using NLed functions.
Although all people in Google groups and also Microsoft MVPs,mentioned there is no way to know the led number of vibrator,I find out when you use NLedGetDeviceInfo on a Led slot,and the lCycleAdjust is -1, it is your device vibrator's led number!

Here is the code I've written to use vibrate of my device!
I also checked it on some other devices and they all worked!

void LedOn(int id)
if (id < 0)
settings.LedNum= id;
settings.OffOnBlink= 1;
NLedSetDevice(NLED_SETTINGS_INFO_ID, &settings);

void LedOff(int id)
if (id < 0)
settings.LedNum= id;
settings.OffOnBlink= 0;
NLedSetDevice(NLED_SETTINGS_INFO_ID, &settings);

int GetVibratorLedNum(void)//-1 means no vibrator
int wCount = 0,VibrLed = -1;

if(NLedGetDeviceInfo(NLED_COUNT_INFO_ID, (PVOID) &nci))
wCount = (int) nci.cLeds;

for (int i=0;i<wCount;i++)
sup.LedNum = i;
if (sup.lCycleAdjust == -1)
VibrLed = i;
return VibrLed;
}- param1 + 1

You also need to add these to your source files!

extern "C" {
BOOL WINAPI NLedGetDeviceInfo( UINT nInfoId, void *pOutput );
BOOL WINAPI NLedSetDevice( UINT nDeviceId, void *pInput );

Also note that most PocketPcs do not support vibrators,mostly PocketPc Phone editions do.


Avi Bandel said...

That works fine in WM 5 and 6, but in WM 6.1 the whole screen flashes instead of the vibration going off.

Maybe the .lCycleAdjust property is not enough to tell if this is the vibration LED?

Avi Bandel said...

There are sometime more that just one LED with sup.lCycleAdjust == -1
What do we do then?

Anonymous said...

Cool blog you got here. I'd like to read a bit more about this matter. The only thing it would also be great to see here is a few photos of any devices.
Katherine Trider
Cell phone jammers

Selcuk Altunkaya said...

I couldnt do it :( can You help me ? Im developing some project with C# VS2008. I need vibrate wince device and also some sound alert I must make.