Dr. Vesselin Bontchev wrote:
Hello folks,
While my application is working, it flashes various information on a form and
it's an annoyance if the device decides to go to sleep in the middle of the
process. What is the proper way of preventing that?
The Palm OS Programmer's Companion
http://www.palmos.com/dev/support/docs/palmos/PalmOSCompanion/AppStartupAndStop.html#998079
suggests registering to receive notifications about the
sysNotifySleepRequestEvent even and then doing
((SleepEventParamType *) (notify->notifyDetailsP))->deferSleep++;
If I do that, the device indeed doesn't go to sleep for the duration of the
process. Unfortunately, it refuses to go to sleep after the process has
finished and I have unregistered with the Nitification manager. Even the power
button cannot turn the device off any more - I have to reset it.
The Companion also says:
"After you defer sleep, your code is free to finish what it was doing. When it is
finished, you must allow the system to continue with the sleep event. To do so, create a
keyDownEvent with the resumeSleepChr and the command key bit set (to signal that the
character is virtual) and add it to the event queue. When the system receives this event,
it will again broadcast the sysNotifySleepRequestEvent to all clients. If deferSleep is 0
after all clients return, then the system knows it is safe to go to sleep, and it
broadcasts the sysNotifySleepNotifyEvent to all of its clients."
It doesn't explain how exactly to do that. I tried the following:
EventType theEvent;
MemSet (&theEvent, sizeof (EventType), 0);
theEvent.eType = keyDownEvent;
theEvent.data.keyDown.chr = resumeSleepChr;
theEvent.data.keyDown.keyCode = 0;
theEvent.data.keyDown.modifiers = commandKeyMask;
EvtAddEventToQueue (&theEvent);
and it works - but *too* well, in the sense that it unconditionally puts the
device to sleep!
How can I do that properly, folks? I want the auto-off attempts to fail while
the process is going on - but I don't want to block the power-off button and I
don't want the device to go to sleep immediately after the process has
finished; I want it to do that only if enough idle time has passed.
Or should I use some completely different approach? Like, messing up with the
auto-off settings (SysSetAutoOffTime), resetting the auto-off timer
(EvtResetAutoOffTimer) or something else like that?
http://www.palmos.com/dev/support/docs/palmos/PalmOSReference/SystemEventManager.html#1071368
Regards,
Vesselin
Hmm, how about only sending the resumeSleepChr if-and-only-if you have
first received the sysNotifySleepRequestEvent?
In other words, only tell the system to continue with a deferred sleep
event if you have deferred it. If you have never received the
notification, then don't queue the event ...
... it looks like the system remembers it is in a defered state if it
sent the event so it won't turn off no matter what, but it doesn't check
that its in that state if you send the resume event -- it just assumes
you know what you are doing.
Chris Olson
--
chris | Roleplayer, Palm PDA Programmer, Avid Reader, Husband, Wanna-
@pdaguy | be-Writer, Geek, Black Belt, Coder, Father of 2, Cycler, 6'5"
.com | Long, Red, Pony-tailed hair, Bearded, 235pd Teddy Bear
--
For information on using the PalmSource Developer Forums, or to unsubscribe,
please see http://www.palmos.com/dev/support/forums/