Jump to content


Photo

Keep the backlight on :D

- - - - -

  • Please log in to reply
20 replies to this topic

#1
muff

muff

    Addict

  • MoDaCo Gold
  • PipPipPipPipPip
  • 938 posts
Hi all


A HUGE thanks to my contact at O for his help with this :P

This is one that people should find useful (I know I will).


(note : only appears to work on the SPV, E100 & E200 Smartphones - not the others)


As most of you will know, whilst an app is running if you don't press a key for a while the backlight timer kicks in and the screen dims, eventually dimming to off - or alternately the Home Page timeout kicks in and the phone returns to the home page.


If you want to keep the backlight completely on in an app AND stop the timeout to the homescreen altogether (very useful for games),

first include these 2 headers:-

#include "windows.h"

	#include "tpcshell.h"

then create a global variable :-

DWORD lastTimerReset;


and then in your main app/game loop add this code :-

// every 9 seconds 

if(GetTickCount() - lastTimerReset> 9000)

{

	// this keeps the backlight on, but only on spv, e100, e200

	#define   EVENT_DISPLAYOFF TEXT("TIMEOUTDISPLAYOFF") 



	HANDLE g_hDispEvent = CreateEvent(NULL, FALSE, FALSE, EVENT_DISPLAYOFF); 

	SetEvent(g_hDispEvent); //LCD frontlight on 



	::SHIdleTimerReset();

	lastTimerReset = GetTickCount();

}


Basically every 9 seconds the code is run to stop the timers kicking in - why 9 seconds? I hear you cry. Well the lowest standard setting on backlight or home page timers is 10 seconds, so resetting them every 9 will do :)



happy coding,

muff

  • 0

#2
PaulOBrien

PaulOBrien

    It's My Party

  • Founder
  • PipPipPipPipPipPip
  • 36,369 posts
  • Gender:Male
  • Location:Norwich, UK
  • Devices:All the Nexus!
  • Twitter:@paulobrien
Nice :)

P

  • 0

You can follow me on Twitter - http://twitter.com/paulobrien / Follow MoDaCo on Twitter - http://twitter.com/modaco

Want to donate? MoDaCo is raising money for the Multiple Sclerosis society.

Posted Image


#3
neilarmstrong

neilarmstrong

    Newbie

  • Members
  • Pip
  • 11 posts
Anyone know a solution that works on the C500 (Smartphone OS 2003 SE)?

I've been trying to use both:

SystemIdleTimerReset
SHIdleTimerReset

...but they don't work. They stop the home screen from kicking in...but they don't stop the backlight from dimming. Unfortunately a bug in GAPI causes games to freeze when the backlight dims :)

  • 0

#4
muff

muff

    Addict

  • MoDaCo Gold
  • PipPipPipPipPip
  • 938 posts
I'll be posting up a C500 version soon now, I'm just working on some other stuff, and then I'll be fully testing then C500 fix before a post

  • 0

#5
muff

muff

    Addict

  • MoDaCo Gold
  • PipPipPipPipPip
  • 938 posts
as promised, C500 code

header include at the top

#include "pm.h"

at the start of the winmain function

HANDLE hPower;  

	hPower = SetPowerRequirement(TEXT("BKL1:"), D0, POWER_NAME, NULL, 0);

and on the way out of the winmain function (so it's called as the app closes)

ReleasePowerRequirement(hPower);

and that's about it really

I personally use it in conjunction with the previous code so that the backlight stays on, and neither 2k2 or 2k3 drop out to homescreens

of course the 2k3 code is partitioned to only be included in the 2k3 build - the PowerRequirement functions are only usable on 2k3 systems

one thing you should be aware of with using this code, is that if the app/game loses focus for any reason (incoming call for example) , the backlight will remain on until you close that app/game

I've tried doing the release and then restating it when losing / gaining focus, but that didn't appear to work for me

happy coding

muff

  • 0

#6
neilarmstrong

neilarmstrong

    Newbie

  • Members
  • Pip
  • 11 posts
I can confirm that the code posted by Muff works on C500!! Fantastic!
I'd tried it before Muff posted his solution but stupidly I forgot to put the TEXT macro around the "BKL1:". D'oh!!!

One thing I would suggest is for people who want to write code that works on both SP 2002 and SP 2003....use GetProcAddress instead of #include


// Copied from pm.h

typedef enum _CEDEVICE_POWER_STATE {

    PwrDeviceUnspecified = -1,

    D0 = 0, // Full On: full power,  full functionality

    D1,     // Low Power On: fully functional at low power/performance

    D2,     // Standby: partially powered with automatic wake

    D3,     // Sleep: partially powered with device initiated wake

    D4,     // Off: unpowered

    PwrDeviceMaximum

} CEDEVICE_POWER_STATE, *PCEDEVICE_POWER_STATE;



#define POWER_NAME (DWORD)(0x00000001)

#define POWER_FORCE (DWORD)(0x00001000)



typedef DWORD (*RELEASEPOWERREQUIREMENT)( 

   HANDLE hPowerReq );

typedef HANDLE (*SETPOWERREQUIREMENT)(

   PVOID pvDevice,

   CEDEVICE_POWER_STATE DeviceState,	

   ULONG DeviceFlags,

   PVOID pvSystemState,

   ULONG StateFlags );


At application startup...

HANDLE HdlPower = NULL;

HINSTANCE HdlCoreDll = LoadLibrary( TEXT("coredll.dll") );

if ( HdlCoreDll )

{

   SETPOWERREQUIREMENT PtrFunc = (SETPOWERREQUIREMENT)GetProcAddress( HdlCoreDll, TEXT("SetPowerRequirement") );

   if ( PtrFunc )

   {  

      HdlPower = (*PtrFunc)(TEXT("BKL1:"), D0, POWER_NAME, NULL, 0);

   }

   FreeLibrary( HdlCoreDll );

}

At application shutdown...

HINSTANCE HdlCoreDll = LoadLibrary( TEXT("coredll.dll") );

if ( HdlCoreDll )

{

   RELEASEPOWERREQUIREMENT PtrFunc = (RELEASEPOWERREQUIREMENT)GetProcAddress( HdlCoreDll, TEXT("ReleasePowerRequirement") );

   if ( PtrFunc )

   {  

      (*PtrFunc)( HdlPower );

   }

   FreeLibrary( HdlCoreDll );

}

  • 0

#7
neilarmstrong

neilarmstrong

    Newbie

  • Members
  • Pip
  • 11 posts
Does anyone know how to stop backlight dimming on PocketPC 2002?

I presume the SetPowerRequirement will work on PocketPC 2003....however, I haven't yet tested it.

  • 0

#8
muff

muff

    Addict

  • MoDaCo Gold
  • PipPipPipPipPip
  • 938 posts

Does anyone know how to stop backlight dimming on PocketPC 2002?

I presume the SetPowerRequirement will work on PocketPC 2003....however, I haven't yet tested it.


yup this does indeed work on the PPC :lol: (well it does on the m1000 anyway)

dont think it stops the actual power off timer of the device, but that's probably not too bad a thing, can't imagine just leaving something running in battery mode anyway


thanks for your variation on the c500 code above as well - now you can compile for 2k2 and still get the benefit of the power work around on 2k3 phones

2k2 compiled code tends to run slightly faster than a 2k3 compile of the code for some reason - so the fact that we can have 2k2 compile with the backlight code workaround is great news :lol:

(also nice to see someone else sharing code :))

  • 0

#9
PaulOBrien

PaulOBrien

    It's My Party

  • Founder
  • PipPipPipPipPipPip
  • 36,369 posts
  • Gender:Male
  • Location:Norwich, UK
  • Devices:All the Nexus!
  • Twitter:@paulobrien
ReleasePowerRequirement doesn't seem to work for me on the C500...

P

  • 0

You can follow me on Twitter - http://twitter.com/paulobrien / Follow MoDaCo on Twitter - http://twitter.com/modaco

Want to donate? MoDaCo is raising money for the Multiple Sclerosis society.

Posted Image


#10
muff

muff

    Addict

  • MoDaCo Gold
  • PipPipPipPipPip
  • 938 posts

"]ReleasePowerRequirement doesn't seem to work for me on the C500...

P


yeah, not really convinced that the command works properly on the C500

certainly in testing minimising an app, with a ReleasePowerRequirement on the WM_KILLFOCUS didn't appear to do anything :/

maybe this is to do with the way the C500 handles it's power functions?

  • 0

#11
0Namal0

0Namal0

    Newbie

  • Members
  • Pip
  • 4 posts
  • Location:South of France
Any update on that issue on c500 ???

I have implemented the first part (SPV 1G) with success, thx muff, but I am awaiting a new device ^_^ and would like to find a way on c500 ..

thanks guys,

Phil.

  • 0

#12
muff

muff

    Addict

  • MoDaCo Gold
  • PipPipPipPipPip
  • 938 posts

Any update on that issue on c500 ???

I have implemented the first part (SPV 1G) with success, thx muff, but I am awaiting a new device ^_^ and would like to find a way on c500 ..

thanks guys,

Phil.


erm, the c500 code is also above :D

  • 0

#13
0Namal0

0Namal0

    Newbie

  • Members
  • Pip
  • 4 posts
  • Location:South of France
Hi Muff,

Sorry if I misunderstood the posts (being french, that helps ^_^), but I thought Paul and yourself were saying the code you posted for C500 didn't actually work ...

Anyway I'll try it myself, better than wasting others' time ...

Thanks a bunch,
Phil

  • 0

#14
AllanHvass

AllanHvass

    Newbie

  • Members
  • Pip
  • 17 posts
Not being a developer myself, does anyone have an actual app containing the code that they can post? It would be great to use when driving in car to keep the backlight on.

It doesn't have to have any user interface, just run it, at it keeps backlight on. And if possible, some mechanism for terminating the app as well, without using a task manager.

THANKS A GAZILLION!!!

Allan Hvass

  • 0

#15
gazzaw

gazzaw

    Newbie

  • Members
  • Pip
  • 11 posts
I have an application that I have put in the startup folder and it changes the backlight timeout to never when the SPV is charging, however when you disconnect the charging it goes back to the original setting.

There is no credits on the app and I do not remember where I got it from.

Hope it helps.

Attached Files


  • 0

#16
rikwebb

rikwebb

    Call this Job Satisfaction !

  • MoDaCo Silver
  • PipPipPipPip
  • 337 posts
  • Location:Derby, UK
  • Devices:Diamond, HD, Pro, HTC HD2
mmmmm,

Wonder if you could use the code above as a wrapper for your apps??

call your wrapper - this calls the app you want to run, and when you quit it - runs the final part to turn it off again

I will see if I get some time to have a play..

Rik

  • 0

#17
AllanHvass

AllanHvass

    Newbie

  • Members
  • Pip
  • 17 posts
To Gazzaw: Yeah, I've already tried that app (and several others, incl. the Orneta ones), and they work as advertise, i.e. they DO change the backlight timeout setting to Never while running, problem is, that on models prior to the SPVe200, the phone simply doesn't respect that, it turns off backlight still (sometimes it works correctly when using a charger, but not consistently, and never when running off battery or in a car kit).

Since several in this thread have tested the code, they must have some kind of prototype, that could easily be adjusted to a selfcontained app.

The wrapper thing that rikwebb suggests would be ideal for the application I have in mind (Mapopolis), since that's exactly what I want to achieve. A wrapper where you could parameterize (even just through a registry setting) the app to call would make it very generic. Except if you just want your phone to stay lit e.g. while in a car kit, withour running any particular app.

I would be hugely thankful for such an app. Bow in the dust, etc. - you get the picture :wink:

  • 0

#18
boffey

boffey

    Newbie

  • Members
  • Pip
  • 2 posts
I've no idea how but my backlight has decided to stay permanently on. I've not input any codes or anything, how do I turn it off?

  • 0

#19
Hawko

Hawko

    Newbie

  • Members
  • Pip
  • 48 posts
  • Devices:SPV C500
if i sound simple all appologise, but im new to this. only had my C500 3 weeks. so where exactly do you put this code in the phone and what do you write it in to be able to put it in the phone?


hawko [-o<

  • 0
Hope Is My Weapon

#20
dieter98

dieter98

    Newbie

  • Members
  • Pip
  • 33 posts

if i sound simple all appologise, but im new to this. only had my C500 3 weeks. so where exactly do you put this code in the phone and what do you write it in to be able to put it in the phone?
hawko [-o<

<{POST_SNAPBACK}>


http://www.modaco.co...howtopic=199025

  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users