Introduction
Have you tried to keep the device which is running on WinCE.NET without going to suspend while watching video. Here's how to do it without changing the power settings manually.
Background
I was developing a video play back module for WinCE.NET 4.2 and encountered a problem that the system goes to suspend mode according to the settings in the registry while watching a video. First, the backlight goes off and afterwards the system goes to suspend mode. The way normally we do is change the settings in power manager which is not practical every time.
Using the code
I tried to stop it calling SystemIdleTimerReset()
but it was unable to stop the device going to suspend sometimes. Because, we have to check the timeout when the power manager event gets fired and call the SystemIdleTimerReset()
before it. Calling SystemIdleTimerReset()
in a thread or timer works. But we need to consider about the performance since it is a mobile device.
So I tried to do it by firing a key board event to the application message loop. Key board events were generated in a timer process and did it as follows:
#define VK_NONAME 0xFC
#define KEYEVENTF_KEYUP 0x2
keybd_event(VK_NONAME, 0, KEYEVENTF_KEYUP, 0);
It worked fine. Device did not go to suspend mode. But application gets an extra message, and since it is a mobile device, I thought it is better to get rid of this extra process and find a nice solution which does not affect the application performance. Finally, I was able to develop a nice and robust class which does the task I want as it is. So I called it SuspendKiller
. SuspendKiller
uses the registry, power manager notification call and Backlight power request call to accomplish the task.
Suspend Killer functions in the following sequence:
- Loads the settings from the registry and saves those in an array for future reference.
- Sets the new settings to
Never (0)
in the relevant registry keys.
- Notifies the Power Manager event to re-load the settings from the registry.
- Turn On the backlight with full power.
- When the function is called with
FALSE
parameter, it reveres everything. (Sets the original values, releases the backlight power.)
It does not affect the application performance since we do it once when the media is about to play and stop.
To do this task, I tried many approaches and also tried with interrupts. But I think this solution is nice and clean. Also tested with iMX21 ADS with WinCE.NET 4.2 and worked perfectly while watching a video for more than one hour.