Limited Promotion: Mesa 2 and Allegro 2/3 Accessories
search

Disable auto-suspend timer API

10 Dec 2003

Power conservation for the Allegro is an important issue because it runs on batteries. Because of this, the operating system is designed to suspend itself into a low-power mode after a period of inactivity. This is not ideal for all situations. For example, if your program is logging data without user intervention, data are not stored when the device goes into suspend mode.

In Windows CE 3.0, the suspend mode can be disabled in the Power application in the Control Panel on your Allegro.

If the disable options in the Control Panel do not meet your needs, there is an API to do this that works on all CE devices. Windows CE has the SystemIdleTimerReset API, which takes no parameters and has no return value. When this API is called, the system countdown to device suspension starts over from the beginning. Because the minimum countdown time is one minute, calling SystemIdleTimerReset at least once every 60 seconds stops the device from suspending itself. The easiest way to do this is to use the following thread:

DWORD WINAPI AvoidSuspendThread(LPVOID pv)
{
  // Application code should set g_bAvoidSuspend to false when
  // it`s OK to enter suspend mode again
  while ( g_bAvoidSuspend )
  {
    SystemIdleTimerReset();
    Sleep(60 * 1000);
  }
  return 0;