All Forums
 Microsoft Windows CE
 eVC Application Development
 Programmatic Sleep and Wakeup
 Forum Locked
 Send Topic to a Friend
 Printer Friendly
Author Topic  

ctacke

877 Posts

Posted - 08 Oct 2002 :  12:11:02  Show Profile  Email Poster
Q. How do I put my ADS system to sleep and wake it up again through code?

Putting the device to sleep is done using the GwesPowerOffSystem() API (or by simulating a VK_OFF keypress).

Waking up is a bit more challenging because you must use the CeRunAppAtTime() API to run some app at a specific time. This may be your app or another app.

The following sample puts the device to sleep then wakes the system up after 10 seconds, displaying the Control Panel.

First it registers the Control Panel to run 15 seconds from the current time (note math should only be performed on FILETIME structures, hence the conversion).
Then it waits 1 second for the registration to complete before calling GwesPowerOffSystem()


#include "windows.h"
#include "notify.h"

extern "C" __declspec(dllimport) void GwesPowerOffSystem();

int WINAPI WinMain( HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
SYSTEMTIME st;
FILETIME ft;
LONGLONG time64 = 0;
int delay = 15; // # of seconds to wait before waking back up

// get current time
GetLocalTime(&st);

// increment by [delay] seconds
SystemTimeToFileTime(&st, &ft);

DEBUGMSG(TRUE, (_T("Current time\r\n%02i:%02i:%02i\r\n"), st.wHour, st.wMinute, st.wSecond));

// *** store file time to time64
time64 = ft.dwHighDateTime;
time64 *= 0x100000000;
time64 |= ((LONGLONG) ft.dwLowDateTime);
// ***

time64 += (delay * 10000000);

// *** store time64 back to file time
ft.dwHighDateTime = (DWORD) (time64/0x100000000);
ft.dwLowDateTime = (DWORD) (time64%0x100000000);
// ***

FileTimeToSystemTime(&ft, &st);

DEBUGMSG(TRUE, (_T("Run at time\r\n%02i:%02i:%02i\r\n"), st.wHour, st.wMinute, st.wSecond));

// register app to run
#if UNDER_CE == 300
CeRunAppAtTime(, &st);
#else
// register app to run
UserNotificationTrigger trigger;
UserNotificationType notification;

ZeroMemory (&trigger, sizeof (UserNotificationTrigger)) ;
ZeroMemory (¬ification, sizeof (UserNotificationType)) ;

trigger.dwSize = sizeof(UserNotificationTrigger);
trigger.dwType = CNT_TIME;
trigger.lpszApplication = _T("\\windows\\control.exe");
trigger.lpszArguments = NULL;
trigger.stStartTime = st;
trigger.stEndTime = st;


HANDLE hNotify = CeSetUserNotificationEx(0, &trigger, & notification);
if(hNotify == NULL)
{
    DEBUGMSG(TRUE, (_T("Failed to set Notification: %i\r\n"), GetLastError()));
    return 0;
}
DEBUGMSG(TRUE, (_T("Notification handle: 0x%08x\r\n"), hNotify));
#endif

Sleep(1000);

// suspend
GwesPowerOffSystem();

return 0;
}


For further reading, see the CE power management topic index.


Edited by akidder 3-dec-2002: Add link to vk_off topic.
Edited by akidder 11-Feb-2003: add link to topic index
Edited by ctacke Feb 2, 04: added CeSetUserNotificationEx code

akidder

1519 Posts

Posted - 06 Dec 2002 :  14:29:56  Show Profile  Email Poster
In practice, you would create a dummy application that you would call upon wakeup instead of the Control Panel (control.exe). Your app can do something real (eg. debug port or write to log file) or it can just exit and do nothing. The main point is to get the system awake and running again.

You would store the dummy application in flash along with your application. You could also call your own application if you included a mutex that prevented your app from running more than once.
Go to Top of Page

rfuller

2 Posts

Posted - 16 Jan 2003 :  18:05:45  Show Profile  Email Poster
I have copied the code shown above into my application. It appears to work fine unless I have a Compact Flash card plugged into my Bitsy Plus running Windows CE 3.0. When a CF card is plugged in, and I go through the sleep/wakeup cycle more than once, I always get a "Storage Card Warning" exception pop up when transitioning from sleep mode to run mode. The warning message body asks, "Would you like the system to format the Storage Card folder so that the system can use it? WARNING: If you select Yes, any files in the Storage Card will be erased!" The CF card does not need to be formatted.
Go to Top of Page

ctacke

877 Posts

Posted - 02 Feb 2004 :  16:52:25  Show Profile  Email Poster
Update

The CeRunAppAtTime has been obsoleted in CE 4.x. Instead you should use CeSetUserNotificationEx.

I have updated the code above to reflect that change.
Go to Top of Page
  Topic  
 Forum Locked
 Send Topic to a Friend
 Printer Friendly
Jump To:
Eurotech Support Forums © Eurotech Inc. Go To Top Of Page
This page was generated in 0.03 seconds. Snitz Forums 2000