Page 1 of 1

Using the Vibrate feature in windows mobile.

#1 Mezius   User is offline

  • D.I.C Head
  • member icon

Reputation: 8
  • View blog
  • Posts: 72
  • Joined: 13-April 09

Posted 10 May 2009 - 09:53 PM

One of the more difficult and obscure things I've found when trying to write software for windows mobile is the vibrate feature. The documentation on how to use it is out there but only if you know the right terms to search for and it also take some digging.
A lot of sample code for this is done referencing OpenNetCF, which no longer supports or includes the vibration feature, which makes most of these examples irrelevant.

Let's start with where the vibrate feature can be found. In windows mobile 5 and 6 the feature is actually an LED device. This made it quite a bit harder to find.

So on to how to actually access this feature.

This first thing you'll need to do is create a structure for the different properties that can be set for the LED features.

			public int LedNum;

			public int OffOnBlink;

			public int TotalCycleTime;	

			public int OnTime;
			public int OffTime;

			public int MetaCycleOn;
			public int MetaCycleOff;

After creating the structure with the variables needed we need a call to import the DLL "Coredll".


The next piece is where to actually access this feature inside of the DLL. To do so you'll need to call the function "NLedSetDevice"

 extern static bool NLedSetDevice(int deviceId, ref NLED_SETTINGS_INFO info); //DevicID is the physical ID of the LED you wish to access. For vibrate it is generally ID 1.

Next we'll actually create the function that we can call when we need to use the vibrate feature.
static void SetVibrate(bool state)
			NLED_SETTINGS_INFO info = new NLED_SETTINGS_INFO(); //Instantiate a new object from the structure we created
			info.LedNum = 1; //Sets the LED number to be used, this is based on the LED device capabilities but in the case of virbation shouldn't matter.
			info.OffOnBlink = state ? 1 : 0;//sets the state of the LED, with vibrate it can only be on or off but a value of 2 for blink can base used in other cases
		   NLedSetDevice(1, ref info);// Actually sets the device to enable vibration or disable it. the 1 subsection is the DeviceID, in this case and most phone cases this will be device 1, the second subsection is passing the information from the info structure.


Information about each option inside the structure:


	LED number. The first LED is zero (0).


	Current setting. The following table shows the defined values.
	Value 	Description

	  0			  Off

	 1			   On

	 2			  Blink


	Total cycle time of a blink, in microseconds.


	On time of the cycle, in microseconds.


	Off time of the cycle, in microseconds.


	Number of on blink cycles.


	Number of off blink cycles.

Is This A Good Question/Topic? 0
  • +

Replies To: Using the Vibrate feature in windows mobile.

#2 kmajumder   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 20-October 09

Posted 20 October 2009 - 05:20 AM

hi all,
This post is very helpfull

But I want to ask u one question is it possible during a call

When I try this code in between a call it didn't take any affect
How to possible to vibrate a device when the phone is in talking mode

Thankx in advance
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1