On Thursday 27 March 2003 09:22 am, [EMAIL PROTECTED] wrote:

> 2) What is the event for detecting the PDA is going to sleep?

OS >= 3.2

Boolean is_os_32(void)
{
    UInt32 romVersion;
    FtrGet(sysFtrCreator, sysFtrNumROMVersion, &romVersion);
    /* some NotifyMgr things need >= 3.2 */
    if (romVersion >= 0x03200000) return true;
    return false;
}

void register_sleep(void)
{
    UInt16 cardNo;
    LocalID dbID;
    if (!is_os_32()) return;
    if (!SysCurAppDatabase(&cardNo, &dbID)) {
        SysNotifyRegister(cardNo, dbID,
            sysNotifySleepNotifyEvent,
            NULL, sysNotifyNormalPriority, NULL);
    }
}

void register_wake(void)
{
    UInt16 cardNo;
    LocalID dbID;
    if (!is_os_32()) return;
    if (!SysCurAppDatabase(&cardNo, &dbID)) {
        SysNotifyRegister(cardNo, dbID,
            sysNotifyLateWakeupEvent,
            NULL, sysNotifyNormalPriority, NULL);
    }
}

.. PilotMain(UInt16 cmd ..)

    SysNotifyParamType *snpt;

    switch (cmd) {

    case sysAppLaunchCmdNotify:
        snpt = (SysNotifyParamType *)cmdPBP;
        switch (snpt->notifyType) {
        case sysNotifySleepNotifyEvent:
            break;
        case sysNotifyLateWakeupEvent:
        }
        break;

    case sysAppLaunchCmdSystemReset:
    case sysAppLaunchCmdSyncNotify:
        register_sleep();
        register_wake();
        break;

> 1) How do you prevent the PDA from going to sleep while running your
> application

As Dave Lippincott wrote, EvtResetAutoOffTimer() calls within your event 
loop.  There are also techniques which can be done via NotifyMgr.  This 
would be used if you need to defer sleep which isn't necessarily caused by 
auto-off.  For example, if you wanted to prevent sleeping due to the lid 
being closed on the Treo :)  Of course you wouldn't want to do that while a 
phone call is active or you would get a very large bill.

>From TreoHelper:

void register_sleeprequest(void)
{
    UInt16 cardNo;
    LocalID dbID;
    if (!is_os_32()) return;
    if (!SysCurAppDatabase(&cardNo, &dbID)) {
        SysNotifyRegister(cardNo, dbID,
            sysNotifySleepRequestEvent,
            NULL, sysNotifyNormalPriority, NULL);
    }
}

    SysNotifyParamType *snpt;
    SleepEventParamType *sept;

    snpt = (SysNotifyParamType *)cmdPBP;
    switch (snpt->notifyType) {
    case sysNotifySleepRequestEvent:
        sept = (SleepEventParamType *)(snpt->notifyDetailsP);
        if ((sept->reason == sysSleepPowerButton) &&
            !HsAttrGet(hsAttrSysSleepReason, 0, &tui16) &&
            (tui16 == hsSysSleepLid)) {
            LoadPrefs(&tprefs);
            if (tprefs.stayonlidnetwork) {
                if (!LoadPhoneLibrary(&tplibref)) {
                    if (!PhnLibGetPhoneCallStatus(tplibref, &tui32)) {
                        /*
                         * So, if a SleepLid request comes in, and we have
                         * our prefs set for it, and the phonecallstatus
                         * shows a data call active, then we defer sleep.
                         */
                        if (tui32&phnGPRSCallActive) sept->deferSleep++;
                    }
                    ClosePhoneLibrary(tplibref);
                }
            }
        }
        break;

You detect the sysNotifySleepRequestEvent and increment the deferSleep 
parameter.

-- 
/* Chris Faherty <[EMAIL PROTECTED]> */

-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/support/forums/

Reply via email to