Wednesday 27 October 2010

Accessing the phone vibrator

How can I access the vibrate function from my apps you may say...?

Well the vibrate function is part of the NLED (or notification LED) driver. You can use the NLED functions to pulse or turn on/off the motor in the same way as any LED. To find the vibrator search through the list of LEDs until you find one with a cycle time of -1, this indicates the vibrator.

The following code is complete example of searching through the available LEDs and turning on and off only the vibrate function. This should work on any Windows Mobile or Windows CE with a compatible NLED driver:


#include "nled.h"

enum Status
{
OFF = 0,
ON,
BLINK
};

int GetLedCount()
{
int count = 0;
NLED_COUNT_INFO nci;
if (NLedGetDeviceInfo(NLED_COUNT_INFO_ID, &nci))
{
count = nci.cLeds;
}
return count;
}

int ledCount = GetLedCount();

void SetLedStatus(Status status)
{
NLED_SETTINGS_INFO nsi;
NLED_SUPPORTS_INFO nInfo;
nsi.OffOnBlink = (uint)status;
for (int i = 0; i < ledCount; i++)
{
// request information from this led, we're looking for a
// cycleAdjust of -1 which indicates the vibrator
nInfo.LedNum = i;
NLedGetDeviceInfo(NLED_SUPPORTS_INFO_ID, &nInfo);
if (nInfo.lCycleAdjust == -1)
{
nsi.LedNum = (uint)i;
NLedSetDevice(NLED_SETTINGS_INFO_ID, &nsi);
}
}
}

void VibrateOn()
{
SetLedStatus(Status::ON);
}

void VibrateOff()
{
SetLedStatus(Status::OFF);
}


int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPTSTR lpCmdLine, int nCmdShow)
{
VibrateOn();
Sleep(500);
VibrateOff();
}

Tuesday 12 October 2010

Missing Ordinals in Windows CE

If you get the message:

ERROR: function @ Ordinal 297 missing
Please Check your SYSGEN variable!!!


Then the problem is most likely to be a missing funciton in CoreDLL, to check which it is go to the private sources:

\WINCE600\PRIVATE\WINCEOS\COREOS\CORE\DLL>notepad core_common.def

In this you should be able to search for the ordinal number

; @CESYSGEN IF COREDLL_BATTERY
BatteryDrvrGetLevels=BatteryDrvrGetLevels @297
BatteryDrvrSupportsChangeNotification=BatteryDrvrSupportsChangeNotification @298
BatteryGetLifeTimeInfo=BatteryGetLifeTimeInfo @713
BatteryNotifyOfTimeChange=BatteryNotifyOfTimeChange @714
GetSystemPowerStatusEx=GetSystemPowerStatusEx @715
GetSystemPowerStatusEx2=GetSystemPowerStatusEx2 @1358
; @CESYSGEN ENDIF