Preventing Automatic Power Off
- From: "Shankar" <syoganat@xxxxxxxxx>
- Date: Wed, 19 Oct 2005 14:15:31 -0700
I am trying to prevent the device from auto powering off. I tried the
following code on a device that is running PPC 2002, it works fine but when
I tried it on a device running Windows Mobile 2003 OS, it is not working
correctly.
1. The Get option always returning 0
2. The set option is always failing.
My sample code is below:
void
CSystemParameters::SetSystemTimouts(DWORD iSecs)
{
DWORD batIdle, acIdle, wakeUpIdle, shortestIdle;
TCHAR szOutput[200];
// get the values
SystemParametersInfo(SPI_GETBATTERYIDLETIMEOUT,0,&batIdle,0);
SystemParametersInfo(SPI_GETEXTERNALIDLETIMEOUT,0,&acIdle,0);
SystemParametersInfo(SPI_GETWAKEUPIDLETIMEOUT,0,&wakeUpIdle,0);
// determine which is the lowest non-zero value
shortestIdle=batIdle;
shortestIdle=((acIdle>0)&&(acIdle<shortestIdle)) ? acIdle :
(((wakeUpIdle>0)&&(wakeUpIdle<shortestIdle)) ? wakeUpIdle : shortestIdle);
if (shortestIdle==0)
// if all values are zero, the device will never timeout
wsprintf(szOutput,_T("Battery Idle Timeout: %d\nAC Power Idle Timeout:
%d\nWakeup Idle Timeout: %d\nThe device will not timeout."),batIdle, acIdle,
wakeUpIdle);
else
{
// otherwise, you need to reset the idle timer more
// frequently than the lowest timeout value
wsprintf(szOutput,_T("Battery Idle Timeout: %d\nAC Power Idle Timeout:
%d\nWakeup Idle Timeout: %d\nYou need to call SystemIdleTimerReset at least
every %d sec"),batIdle, acIdle, wakeUpIdle, shortestIdle-1);
}
MessageBox(hWnd,szOutput,_T("Results"),MB_OK);
file://------------------------------------------
// Save the current values.
if ((SystemParametersInfo(SPI_GETBATTERYIDLETIMEOUT,0,&sm_batIdle,0)) == 0)
{
AfxMessageBox(_T("Failed BAT Idle Get"));
}
SystemParametersInfo(SPI_GETEXTERNALIDLETIMEOUT,0,&sm_acIdle,0);
SystemParametersInfo(SPI_GETWAKEUPIDLETIMEOUT, 0,&sm_wakeUpIdle,0);
tStr.Format(_T("Bat = %d Ac = %d Wake = %d"), sm_batIdle, sm_acIdle,
sm_wakeUpIdle);
AfxMessageBox(tStr);
// Turn off the timeouts.
if ((SystemParametersInfo(SPI_SETBATTERYIDLETIMEOUT,
iSecs,0,SPIF_UPDATEINIFILE)) == 0)
{
AfxMessageBox(_T("Failed BAT Idle Setup"));
}
SystemParametersInfo(SPI_SETEXTERNALIDLETIMEOUT,iSecs,0,SPIF_UPDATEINIFILE)
;
SystemParametersInfo(SPI_SETWAKEUPIDLETIMEOUT, iSecs,0,SPIF_UPDATEINIFILE);
if ((SystemParametersInfo(SPI_GETBATTERYIDLETIMEOUT,0,&sm_batIdle,0)) == 0)
{
AfxMessageBox(_T("Failed BAT Idle Get"));
}
SystemParametersInfo(SPI_GETEXTERNALIDLETIMEOUT,0,&sm_acIdle,0);
SystemParametersInfo(SPI_GETWAKEUPIDLETIMEOUT, 0,&sm_wakeUpIdle,0);
tStr.Format(_T("Bat = %d Ac = %d Wake = %d"), sm_batIdle, sm_acIdle,
sm_wakeUpIdle);
AfxMessageBox(tStr);
}
--
Shankar
.
- Prev by Date: Can't attach to process on CE device
- Next by Date: Device driver & threads
- Previous by thread: Can't attach to process on CE device
- Next by thread: Device driver & threads
- Index(es):
Relevant Pages
|