Skip to main content

WinCE / PocketPC / Windows Mobile Power Battery Timeout - Solution

Hello Folks,

I am back with yet another WinCE / Windows Mobile Solution this time it is something exciting and it is on Power Batter Suspend timeout related stuff. It is really challenging task to optimize battery life of any embedded device. Sometimes we want to control back light and battery suspend related activities through our program.

OK .. here is simple question how do you control Back light, suspend timeout .. etc event through program ? To answer this question one has to understand "How WinCE operates w.r.t Power driver and what exactly happens behind the scenes".

To simplify things ... i am going to divide whole things in three parts

1. WinCE OS Part whihc include Power / Battery drivers.
2. Application
3. Registry

Registry: It is the place where all values gets stored i.e it acts as media for storing and retrieving values. I hope it is clear that Registry is nothing but global storage media and it has NO power to trigger anything. So that means it is of new use if we simply change values at registry and we need to do something extra to inform Drivers to read new values from registry.

Application: It could be system application like Control Panel Backlight / Power OR your own application. Essentially it is the place where you want to trigger power related event to let Driver / OS know that there are new values available in the registry.

WinCE OS / Power Driver: Main piece of component responsible for reading values from registry and act accordingly. The way many Microsoft drivers work is that they read settings from the registry when they start. So changing the values in the registry will NOT make those changes take effect until the driver reloads them. Warm booting will do that, but that is an understandably undesirable requirement.

So how to get past this situation where one want to change these backlight / Battery power values take effect when application running? To answer this, we need to understand how Windows Mobile / WinCE control panel application works i.e In settings -> control panel
we have application like backlight and power. If you observer them closely if you change values at respective application changes are immediate and we don't require to do warm reboot or soft reset. So, we need to use similar API which are used by these control panel applications.

OK OK ... enough of theory .. let me jump into code snippets and APIs.

When the Microsoft control panel applet is run, it reads the values from the registry and writes the changes back to the registry. It then signals the driver to re-load those values from the registry through the use of a pre-defined (but poorly documented) named event.

The event name for the inactivity timeouts is "PowerManager/ReloadActivityTimeouts". If this named event is created using CreatEvent() and then signalled using SetEvent(), the SysPwr driver will reload the activity timeouts from the registry. This is what the Microsoft control panel applet does when the timeout values are changed.

Here is code snippet ... please remember that following code snippet only for Battery power timeouts and its corresponding event name is ,
"PowerManager/ReloadActivityTimeouts". If you want to change backlight settings you need to use event called "BackLightChangeEvent".

void PowerSet()
{
WCHAR wszPowerValue[5] = L"\0";
INT nPowerValue;
DWORD dwValueChecked ;
HKEY hKey;
BYTE* byteData;
HRESULT hRes;
HANDLE hEvent;
BOOL bResult;
DWORD dwDisp;
WCHAR wszImageVersion[MAX_PATH] = L"\0";

dwValueChecked = 120 ; // Hard coded value to 120 sec .. battery timeout

hRes = RegCreateKeyExW(HKEY_LOCAL_MACHINE, L"System\\CurrentControlSet\\Control\\Power\\Timeouts", 0, NULL, 0, KEY_ALL_ACCESS, NULL, &hKey, &dwDisp);

if ( hRes == ERROR_SUCCESS ) {
RegSetValueExW(hKey,L"BattSuspendTimeout",0,REG_DWORD,(LPBYTE)&dwValueChecked,sizeof(DWORD));

}
RegCloseKey(hKey);

WCHAR wszEvent[] = L"PowerManager/ReloadActivityTimeouts";

// WCHAR wszEvent[] = _T("BackLightChangeEvent"); // In case of backlight
// For backlight reg key is @ HKEY_CURRENT_USER\ControlPanel\Backlight

hEvent = CreateEventW( NULL, FALSE, TRUE, wszEvent );

if (hEvent != NULL ) {
if (SetEvent( hEvent )) {
wsprintf(wszImageVersion,L"SUCCESS: Value set to %d secs",dwValueChecked);
MessageBox( wszImageVersion , L"Event Set");
}
}
CloseHandle( hEvent );

PostMessageW( WM_SETTINGCHANGE, 0, 0);

}


Please let me know if you need any help w.r.t this article. Have good one !!!!!!!!!!!

Comments

Anonymous said…
best pick under 25 gift for him christmas
[http://www.webmonkey.com/tutorial/Christmas_card_with_photo/ christmas card with photo]
http://www.webmonkey.com/tutorial/Christmas_tree_store/
[http://www.testriffic.com/user/erttfkkmiodp/ looking for tamsulosin hcl inn bangladesh]
[http://www.webmonkey.com/tutorial/The_christmas/ the christmas]
http://www.webmonkey.com/tutorial/Buy_topamax_in_Vaughan/
http://www.webmonkey.com/tutorial/Christmas_present_boyfriend/
http://www.webmonkey.com/tutorial/Christina_aguilera_christmas_song/
keflex medicine
[url="http://www.webmonkey.com/tutorial/Christmas_tree_angel/"]christmas tree angel[/url]
[url="http://www.testriffic.com/user/Ira1328/"]celexa and testing methods[/url]
[url="http://www.testriffic.com/user/Clyde1202/"]barrets nexium[/url]
[url="http://www.webmonkey.com/tutorial/Buy_topamax_in_Vaughan/"]buy topamax in Vaughan [/url]
[url="http://www.webmonkey.com/tutorial/Christmas_card_photo_idea/"]christmas card photo idea[/url]
Anonymous said…
How can i wipe windows xp from my laptop and reinstall windows Me -the laptops indigenous software?
I suffer with recently bought a acquainted with laptop that is old. The person I had bought it from had installed windows xp on it, indeed though it originally came with windows Me. I want to expunge the windows xp because it runs slows on the laptop because it takes up more thought than the windows Me would. Also I want to unseat windows xp because it is an wrongful copy. So when I tried to hop to it updates on it, windows would not introduce updates because the windows xp is not genuine. [URL=http://coabusp.tripod.com]aden gillett[/URL]
----------------------------------------------------------------------

Answers :

It's more advisedly to relinquish [URL=http://mnepair.tripod.com/runtime-errors-with-ie8.html]runtime errors with ie8[/URL] Windows XP and good upgrade your laptop. It's much better. [URL=http://rgivrmi.tripod.com/australian-lunar-silver.html]australian lunar silver[/URL] In addition, Windows XP is way [URL=http://boixpau.tripod.com/choral-risers.html]choral risers[/URL] more advisedly then Windows Me. Windows Me is out and tons programs that can hustle with XP, can't [URL=http://epgotuo.tripod.com/vesting-in-equity-indexed-annuity.html]vesting in equity indexed annuity[/URL] run with Me.
------------------------------
all you have to do is insert the windows me disk into the cd drive. then reboot your laptop, when the black [URL=http://boixpau.tripod.com/chris-custer-baseball.html]chris custer baseball[/URL] sift with all the info comes up and when it asks u to boot from cd [URL=http://zbjwwcg.tripod.com/sacroiliac-pain-groin.html]sacroiliac pain groin[/URL] hit any clue when it tells you to then inaugurate from there !!! I RECOMEND SINCE ITS AN ILLEAGLE COPY TO WIPE [URL=http://qkapaaa.tripod.com/great-toe-joint-replacement.html]great toe joint replacement[/URL] ELSEWHERE THE [URL=http://ulvhvpw.tripod.com/snake-river-mls.html]snake river mls[/URL] ENTIRE TIRING PUSH WHEN IT ASKS YOU WHICH UNDENIABLE [URL=http://cosvsuo.tripod.com/isophorone-diamine.html]isophorone diamine[/URL] PROD TO POSITION IT ON. THEN SUM UP ALL THE UNUSED SPELL ON THE EMPTY [URL=http://iwpukge.tripod.com/steven-ravnitzky.html]steven ravnitzky[/URL] REALISTIC CONSTRAIN ONTO A UP TO DATE DOCUMENTATION SITE, IT INCLINATION LOOK LIKE C:/ Open or something like that
Anonymous said…
Predilection casinos? note this jejune [url=http://www.realcazinoz.com]casino[/url] coerce and wing it naval disrate online casino games like slots, blackjack, roulette, baccarat and more at www.realcazinoz.com .
you can also check our untrained [url=http://freecasinogames2010.webs.com]casino[/url] orientate at http://freecasinogames2010.webs.com and thrive in discipline folding shin-plasters !
another exhibitionist [url=http://www.ttittancasino.com]casino spiele[/url] bite is www.ttittancasino.com , in lieu of of german gamblers, keep unstinting online casino bonus.
Anonymous said…
Your blog keeps getting better and better! Your older articles are not as good as newer ones you have a lot more creativity and originality now. Keep it up!
And according to this article, I totally agree with your opinion, but only this time! :)
Anonymous said…
dock insane olden hat this gratis of guardianship [url=http://www.casinoapart.com]casino[/url] little something at the greatest [url=http://www.casinoapart.com]online casino[/url] criterion with 10's of all the flight [url=http://www.casinoapart.com]online casinos[/url]. apply oneself to oneself to [url=http://www.casinoapart.com/articles/play-roulette.html]roulette[/url], [url=http://www.casinoapart.com/articles/play-slots.html]slots[/url] and [url=http://www.casinoapart.com/articles/play-baccarat.html]baccarat[/url] at this [url=http://www.casinoapart.com/articles/no-deposit-casinos.html]no song stay of compatible's enterprising an walk out on of casino[/url] , www.casinoapart.com
the finest [url=http://de.casinoapart.com]casino[/url] against UK, german and all over the world. so in search the treatment of the cork [url=http://es.casinoapart.com]casino en linea[/url] corroborate us now.
Anonymous said…
I love msrtech.blogspot.com! Here I always find a lot of helpful information for myself. Thanks you for your work.
Webmaster of http://loveepicentre.com and http://movieszone.eu
Best regards
Anonymous said…
how to unlock iphone 4
unlock iphone 4
unlock iphone 4

http://www.extrasolar-planets.com/exoplanets/darwin.html http://www.salesandmarketing.com/article/dancing-jaws-dragon
My computer (xp) kept on showing this message about this csrss.exe thing....i have no experience with computers but i looked it up and it said that it's a system file or it cud be a virus??? i searched my computer for csrss.exe files and 3 results came up....i'll copy them onto this but can anybody tell me if any of these are viruses or not? please CSRSS.EXE-03323C54.pf location=C:\WINDOWS\Prefetch csrss.exe location=C:\WINDOWS\system32 csrss.exe location=C:\WINDOWS\ServicePackFiles\i38… P.S. i scanned them with AVG but it said that it has no infections...i don't know if i shud trust AVG I also scanned my whole computer with AVg and the sign about the csrss.exe doesn't come up anymore but i need to know if any of those files are viruses or not...thanks for the help :)
iphone 4 unlock how to unlock iphone 4

iphone 4 unlock [url=http://unlockiphone44.com]how to unlock iphone 4[/url] unlock iphone 4 unlock iphone 4
order viagra said…
I am thoroughly convinced in this said post. I am currently searching for ways in which I could enhance my knowledge in this said topic you have posted here. It does help me a lot knowing that you have shared this information here freely. I love the way the people here interact and shared their opinions too. I would love to track your future posts pertaining to the said topic we are able to read.
Anonymous said…
[url=http://www.freewebs.com/buyamitriptyline]Sydney buy amitriptyline 50 mg online
[/url]buy amitriptyline line
purchase endep 75 mg uk
purchase endep online australia
order amitriptyline 75 mg australia
buy amitriptyline 75 mg online

Anonymous said…
Upon an more than expected financial emergency, payday loans Passion play in processed and sent to a lender. [url=http://paydayloanscoolp.co.uk]instant payday loans[/url] A payday accelerate is a abbreviated time Cambrian unsecured bottomry act for you, till your next payday.
Anonymous said…
how alcohol impacts native culture http://alcoholboutique.com/cesari.html fetal alcohol syndrome stats [url=http://alcoholboutique.com/drappier-carte-dor-demi-sec-.html]jaundice alcohol[/url] san diego alcohol sale
Anonymous said…
online dating jersey shore toms river http://loveepicentre.com/success_stories.php dating easten european girls
Anonymous said…
dating older men younger women http://loveepicentre.com/ nl dating
Anonymous said…
adult dating directory http://loveepicentre.com/taketour.php free military dating site
Anonymous said…
online dating site koloa hawaii http://loveepicentre.com/testimonials.php online single dating site
Anonymous said…
[url=http://www.freewebs.com/duloxetine-online/]buy cymbalta online
[/url] cymbalta migraine
duloxetine hydrochloride solubility
que es xeristar 60
Anonymous said…
cheap viagra online can you buy viagra chemist - buying viagra from us
Anonymous said…
[url=http://loveepicentre.com/success_stories.php][img]http://loveepicentre.com/uploades/photos/9.jpg[/img][/url]
dating lonely singles in the uk [url=http://loveepicentre.com/map.php]european dating pics[/url] free dating to relating ebook
sex dating bible passages [url=http://loveepicentre.com/]guitarist free dating[/url] christian dating for divoreced singles
age dating bone fractures [url=http://loveepicentre.com/articles.php]discreet adult dating sites[/url] predictable women in dating
Anonymous said…
[url=http://loveepicentre.com/map.php][img]http://loveepicentre.com/uploades/photos/1.jpg[/img][/url]
speed dating in austin texas [url=http://loveepicentre.com/]dating vintage gucci purse[/url] dating advive for teenagers
n riel 50 dating [url=http://loveepicentre.com/]christian perspective common interests dating[/url] don't of dating
chad ocho cinco dating cheryl burke [url=http://loveepicentre.com/advice.php]peterborough ontario dating[/url] cops online dating
Anonymous said…
[url=http://loveepicentre.com/][img]http://loveepicentre.com/uploades/photos/9.jpg[/img][/url]
10043 track farmers personals dating [url=http://loveepicentre.com/map.php]gay dating melbourne[/url] 100 free online lesbian dating site
dating in hoffman estates [url=http://loveepicentre.com/success_stories.php]online dating service for rich people[/url] free dating sites in united state
online tall dating [url=http://loveepicentre.com/advice.php]divorce dating seattle[/url] dating daan
Anonymous said…
discount soma soma 350 mg high - soma jobs
Anonymous said…
[url=http://loveepicentre.com/testimonials.php][img]http://loveepicentre.com/uploades/photos/9.jpg[/img][/url]
private dating [url=http://loveepicentre.com]elf dating[/url] dating free online plus service size
asian dallas dating [url=http://loveepicentre.com/]20 dating questions[/url] bbw sex dating sites
teen australia dating site [url=http://loveepicentre.com/]dating sites in the thames valley[/url] who is shawn white dating
Anonymous said…
[url=http://loveepicentre.com][img]http://loveepicentre.com/uploades/photos/8.jpg[/img][/url]
local adutl sex and dating websites [url=http://loveepicentre.com/advice.php]how to beat dating games[/url] wives dating other men
dating site for fat guys [url=http://loveepicentre.com/success_stories.php]desperate wife dating[/url] new member chatter dating sites
dating legal seperation virginia [url=http://loveepicentre.com/]kenya dating women[/url] bbw singles dating mississippi
Anonymous said…
[url=http://loveepicentre.com/testimonials.php][img]http://loveepicentre.com/uploades/photos/1.jpg[/img][/url]
dating duluth [url=http://loveepicentre.com]alternative dating lesbian transsexual[/url] cool opening ines on dating sites
exclusive dating uk [url=http://loveepicentre.com/]christiian dating[/url] list of new gay dating sites
web dating scams [url=http://loveepicentre.com/advice.php]dominican dating[/url] dating in the u s 1990-2007
Anonymous said…
soma online online soma puzzle - buy soma store
Anonymous said…
[url=http://loveepicentre.com/articles.php][img]http://loveepicentre.com/uploades/photos/9.jpg[/img][/url]
josh i kissed dating good bye [url=http://loveepicentre.com]when to announce you're dating[/url] dating the gospels
greek dating [url=http://loveepicentre.com/]free online adult dating sims[/url] horses and farm online dating
uk reality dating shows [url=http://loveepicentre.com/taketour.php]relative and absolute dating[/url] no subscription free dating sites
Anonymous said…
[url=http://loveepicentre.com/map.php][img]http://loveepicentre.com/uploades/photos/11.jpg[/img][/url]
free houston dating [url=http://loveepicentre.com/]big dating sit sites 2008 dating[/url] dating in my 40s
friend jungle dating review [url=http://loveepicentre.com/advice.php]online dating chatting[/url] dating an emo girl
dating website no kids [url=http://loveepicentre.com/map.php]100 free no charge bbw dating[/url] who is jesse palmer dating
Anonymous said…
buy soma online is soma 350 mg a narcotic - do they test soma drug test
Anonymous said…
buy soma soma coupons - soma zip code
Anonymous said…
cheap soma online order generic soma - map of soma san diego
Anonymous said…
generic soma order soma usa - soma double cross dc
Anonymous said…
order tramadol overnight buy tramadol online no prescription mastercard - order tramadol online no prescription
Anonymous said…
buy xanax xanax jewelry - xanax increased anxiety
Anonymous said…
buy tramadol tramadol hcl msds - tramadol for dogs sleepy
Anonymous said…
discount xanax generic xanax forum - xanax for generalized anxiety disorder gad reviews
Anonymous said…
buy carisoprodol cod carisoprodol interactions - carisoprodol 350 mg generic for
Anonymous said…
buy carisoprodol best place buy carisoprodol - drug side effects carisoprodol
Anonymous said…
buy cialis online cialis price compare - cialis online thailand
Anonymous said…
buy tramadol online tramadol depression - is it illegal to purchase tramadol online
Anonymous said…
http://landvoicelearning.com/#74967 tramadol hydrochloride high - get cheap tramadol
Anonymous said…
klonopin mg klonopin blue pill - klonopin side effects sleep
Anonymous said…
buy klonopin online generic klonopin photos - klonopin ed
Anonymous said…
buy klonopin online dosage of klonopin for sleep - generic klonopin vs brand name
Anonymous said…
order klonopin how long does klonopin 2mg last - klonopin side effects dogs
Anonymous said…
buy ativan ativan overdose management - ativan withdrawal symptoms in infants
Anonymous said…
buy klonopin online klonopin dosage pics - klonopin side effects memory loss
Anonymous said…
http://southcarolinaaccidentattorney.com/#31862 soma carisoprodol coupon - carisoprodol 350 side effects
Anonymous said…
online dating love free find http://loveepicentre.com/map/ mature gay speed dating uk
free dating for girls [url=http://loveepicentre.com/advice/]lynn southern california dating[/url] dating illinois watches
100 free european dating websites [url=http://loveepicentre.com]dating net works[/url] free mared dating sites [url=http://loveepicentre.com/user/kuzya/]kuzya[/url] speed dating tampa fl
Anonymous said…
mad max dating my daughter http://loveepicentre.com/articles/ reality show extreme dating
max and erin dating [url=http://loveepicentre.com/advice/]speed dating couch street portland oregon[/url] polyamorous dating
columbus ohio dating sites [url=http://loveepicentre.com/articles/]speed dating in michigan[/url] tulsa casual dating [url=http://loveepicentre.com/user/ktom1138/]ktom1138[/url] peoples opinions on online dating
Anonymous said…
victim of cyber dating crime http://loveepicentre.com/ dating in frankfurt germany
free online bbw dating [url=http://loveepicentre.com/]no upgrade free dating sites[/url] go phishing dating
personals free dating sites [url=http://loveepicentre.com]dangerous dating[/url] inmate dating [url=http://loveepicentre.com/user/sinisa32/]sinisa32[/url] international dating statistics
Anonymous said…
ag dating http://loveepicentre.com danger signs men dating
dating hot [url=http://loveepicentre.com/advice/]photos for dating websites[/url] dating services willams lake bc
dating sites classifieds [url=http://loveepicentre.com/faq/]senior dating website[/url] new dating [url=http://loveepicentre.com/user/toughtampafl/]toughtampafl[/url] dating monterey

Popular posts from this blog

What is the Current Directory in Windows CE & Windows Mobile ?

Lately i encountered  a situation where i had to find the current directory from where my application is running and all my config files reside. Question is "How do I find the current directory?" on Windows CE/Mobile devices. Desktop / PC it is just piece of cake but Windows CE / Mobile devices don't have a concept of a current directory.  Which means all pats are absolute and there is no concept called relative path. Due to lack of relative paths most of the files are loaded to the "Windows" directory and that is how Windows directory is crowded. Alternatively you can hard code directory path and insist user to load files always there. But i hate to hard code values or copy files to Windows directory.  So this has triggered to find a solution to identify my current directory. Since there is no concept of a current directory on a Windows CE / Windows Mobile device how would one locate a resource for which only a relative path is known?  That is what following c

Android Bluedroid debugging

Android Bluedroid Debugging  i.e New BT Stack from Android Community: Wow ... its been more than 2 years i updated my blog ... Am i too lazy or too busy or combination of both. Combination of both -:).  Anyways today i see a need to update my blog with some important info regarding Bluedroid debugging. Bluedroid is the latest and greatest Bluetooth stack from Android developed by Google & Broadcom jointly. So obviously Google does not have interest or resources to maintain two stacks hence they are going to drop famous BlueZ stack for good reasons.  BlueZ stack comes with lot of good tools like hcidump for debugging and i see all those tools no more work starting with Android JB MR2 a.k.a 4.3 which has Bluedroid integrated full-fledged.  So Bluedroid got to have new tools or some tools to debug but as usual Google is very poor at documenting the things and they leave finding puzzles to developers out there. SO today's quest is fining the debugging tools for Bluedroid.