« Watson crash in RIL_GetCellTowerInfo() | Detecting user activity/inactivity in a Windows Mobile app » |
Keeping the backlight lit in a Windows Mobile app
Monday, December 21, 2009
To keep the backlight on, you may think it makes sense to call
SystemIdleTimerReset()
repeatedly. (Or at least I thought so.) But this doesn't work on all (most?) phones:
[DllImport("coredll.dll")] public static extern void SystemIdleTimerReset(); public static void Main(string[] args) { // Reset the idle timer every 10 seconds, starting now var Timer = new Timer(SystemIdleTimerReset, null, 0, 10000); // do useful stuff... }
This does work, however:
[DllImport("coredll.dll")] public static extern void SystemIdleTimerReset(); [DllImport("coredll.dll")] public static extern IntPtr SetPowerRequirement( string device, int deviceState, int deviceFlags, IntPtr systemState, int stateFlags); [DllImport("coredll.dll")] public static extern int ReleasePowerRequirement(IntPtr handle); public enum CEDEVICE_POWER_STATE { PwrDeviceUnspecified = -1, D0 = 0, // full on D1, D2, D3, D4, // off PwrDeviceMaximum } public static void Main(string[] args) { var Timer = new Timer(SystemIdleTimerReset, null, 0, 10000); IntPtr handle = SetPowerRequirement( "BKL1:", (int) CEDEVICE_POWER_STATE.D1, 1, IntPtr.Zero, 0 ); // do useful stuff... ReleasePowerRequirement(handle); }
SetPowerRequirement()
forces the system to remain in a higher power consumption state than it otherwise would be in.
CEDEVICE_POWER_STATE.D0
is
"Full On"; D1
is "Low On" and D4
is "Off." Be sure to
ReleasePowerRequirement()
when you're done.
The BLK1:
is the backlight device name. It's been the same on all the phones I've tested on,
but there aren't any guarantees. To find out what the name is on your particular phone, look in the registry in
HKLM\Drivers\BuiltIn. There will be a key called Backlight or Frontlight or something similar. The device name seems
to be determined by the values Prefix and Index (on my phones these are BKL and 1).
Comments
David on Thursday, December 31, 2009 at 01:28
No, nobody reads this, but hopefully it will be of help for people who are trying to solve similar issues and search for the right keywords?
Alex on Sunday, February 7, 2010 at 12:53
Oh well, I came here and has been extremely helpful.
After couple hours of googling finally this is the only code that works for me.
Thanks a lot.
Maylene on Sunday, December 27, 2009 at 19:20
I only come here to look at that picture of Morgan with oranges on her head. Does anyone else actually come here?