Time to turn out the lights…

Time to provide a little balance to the previous piece on SetPowerRequirement for Smartphone which looked at the scenario of ensuring the backlight remained on. You might also want to manually turn off the backlight (or another peripherial) to save power. You can do this with SetDevicePower. You pass in the identifier of the hardware device (“BKL1:” being the backlight on most devices), and a power state – thus the backlight can be powered off with the following:-

SetDevicePower(“BKL1:”, POWER_NAME, DevicePowerState.D4);

POWER_NAME is passed in to the flags argument to indicate that the first argument represents a device name. The Power states run from D0 full power to D4 power off. And without further ado, the P/Invoke:- 

public enum DevicePowerState : int
Unspecified = -1,
D0 = 0, // Full On: full power, full functionality
D1, // Low Power On: fully functional at low power/performance
D2, // Standby: partially powered with automatic wake
D3, // Sleep: partially powered with device initiated wake
D4, // Off: unpowered

private const int POWER_NAME = 0x00000001;

private static extern int SetDevicePower(
string pvDevice,
int dwDeviceFlags,
DevicePowerState DeviceState);

6 thoughts on “Time to turn out the lights…”

  1. César, depends what piece of hardware you turn off, BKL1: will turn off the backlight but the hardware buttons, screen and touchscreen will continue to work.


  2. We have tested in differents smartphones (imate sp3i, mpx220 and spv200) and the behaviour are different as you say.. in my case i lost the control of the keyboard.. it is the way the hardware implements this D4 isnt it?

  3. Is it possible to replace "BKL1:" in SetDevicePower("BKL1:", POWER_NAME, DevicePowerState.D4); with "COM2:" in order to keep the GPS awake when the pocket pc goes into suspend mode ?

  4. It depends on the particular device in question -it only works if the driver implements certain power management functionality so it wont have an effect on all drivers. As far as I can tell you would need to actually keep the device out of suspend mode in order to keep the COM port open, you could turn off the screen but the rest of the device would still have to be "powered up"


  5. Where can I get specific information about the power management ? Programming the pocket pc is so frustrating because I really can’t find any information, especially information about API’s.
    At the moment I’m writing a ppc application which captures gps data. Everything works fine, but the ppc’s battery last only for about 4 hours. So now I’ve extended my app with some API’s who turn off the ppc after receiving gps data in 20 secs and than after 1 minute the ppc app starts again (with CeRunAppAtTime) receiving gps data. (This way the battery lasts for about 20 hours). However, when the com port is closed and opened again periodically, the gps receiver has to do a restart so it takes some time to record the first NMEA string with good data quality. So that’s the reason why I would like the gps not to go in suspend mode. If it stays on then I have good data each time my app starts itself.

Comments are closed.