Guest dh Posted October 11, 2004 Report Posted October 11, 2004 Had written an app that was notified of power transistions, which then set the backlight on if the device was on AC power, since the arrival of the SPV C500 these notifications don't seem to work, it always apears to be on battery, and the transistion notifications not seem to be generated. Code snipits below Power transistion.. ... if ( WaitForSingleObject(powerNotificationReadQueue, 100) == WAIT_OBJECT_0 ) { POWER_BROADCAST pb = new POWER_BROADCAST(1024); int nRead, Flags; ReadMsgQueue(powerNotificationReadQueue, pb.Data, pb.Data.Length, out nRead, 0, out Flags); // Is this an event we wanted? Log (pb.Message.ToString() + " " + PowerEventType.PBT_TRANSITION.ToString()); if ( (pb.Message & PowerEventType.PBT_TRANSITION) == PowerEventType.PBT_TRANSITION) { //Notify parent - launch power change code this.Invoke(new EventHandler(stateChanged)); ... AC power check called after transistion event... ... SYSTEM_POWER_STATUS_EX status = new SYSTEM_POWER_STATUS_EX(); if (GetSystemPowerStatusEx(status, false) == 1) { if (status.ACLineStatus == 1) ... Any sugestions
Guest nickwaring Posted October 12, 2004 Report Posted October 12, 2004 Just a thought... would BatteryFlag work instead of ACLineStatus? The following values are returned: 1 = High 2 = Low 4 = Critical 8 = Charging 128 = No system battery 255 = Unknown status This way you could look for the 'Charging' Indicator Just a thought
Guest dh Posted October 12, 2004 Report Posted October 12, 2004 Had a look at that as well, when the phone is charging the flag is 8, when the phone is fully charged is stops charging and the flag is 1, which then means there's now way of determining if the phone if fully charged and on mains, or got a good charge and is running on battery. Nice!
Guest nickwaring Posted October 12, 2004 Report Posted October 12, 2004 The only thing this doesn't sort out is the notification of a change in status I haven't had any ideas on that yet!
Guest dh Posted October 12, 2004 Report Posted October 12, 2004 Indeed, no idea what they have changed since the release of mobile 2003 second edition, or what HTC have done with the power stuff on the C500
Guest nickwaring Posted October 13, 2004 Report Posted October 13, 2004 You could always look for 2 conditions: 1. When the battery is charging 2. When the batterylife % drops below a threshold (98%) It's not as elegant as ACLineStatus but may still do the same thing Is there any chance of sending me a copy of your app?
Guest dh Posted October 13, 2004 Report Posted October 13, 2004 After doing more tests it seems AC power is detected, the issue now is getting the app to be told that the power state has changed, the only notification that seems to work is PBT_POWERSTATUSCHANGE, but this event only gets raised when the charge changes, from the documentation it should be raised when the power changes from AC/DC (from what I can tell).
Guest nickwaring Posted October 13, 2004 Report Posted October 13, 2004 mmm... what about PBT_POWERINFOCHANGE? (MSDN says... This is a broadcast specifying that a battery power status field has changed. This notification has an associated POWER_BROADCAST_POWER_INFO structure).... this may generate too many notifications
Guest dh Posted October 13, 2004 Report Posted October 13, 2004 I've now set the app to receive all notifications (POWER_NOTIFY_ALL), I do get POWERINFOCHANGE, but it only seems to send changes every now and again, not as frequently as is useful. I'm going to have to find another way of checking for the status without consuming processor and battery. This is very annoying Any thoughts?
Guest nickwaring Posted October 13, 2004 Report Posted October 13, 2004 I'm a bit limited by my lack of experience with Visual Studio so am finding it a bit difficult (impossible) to get even the simplest of apps developed and deployed onto my smartphone... I know what I want to do but lack the skills!.. Does POWER_BROADCAST_POWER_INFO hold any clues?.. I'm not sure if this issues notification on the various flags etc It feels like you might be getting closer!
Guest dh Posted October 13, 2004 Report Posted October 13, 2004 More testing, seems the events for POWERINFOCHANGE and POWERSTATUSCHANGE are sent every 10 minutes by the OS, and not when a change occurs, very strange As far as POWER_BROADCAST_POWER_INFO, i think that is included as data in the event POWERINFOCHANGE, which is only sent every 10 mins.?
Guest dh Posted October 13, 2004 Report Posted October 13, 2004 nickwaring As requested here's a copy of my app, at the moment it will put the backlight on for the specified amount of time when the 10 min interval has passed. The app is in 2 parts, firstly the background app which deals with checking for power notifications etc and a config app which sets the ac timeout value and enables / disables logging etc. A shortcut is added to the startup folder for the backlight app and shortcuts are added to the accessories folder for the config and backlight app When installing select Phone as location as using the Storage Card seems to drain the battery more, that my just be me using the phone for testing more than the app but not sure. As I said earlier the app worked fine on SPV E200 but now you have to wait for this 10 min interval Also on SPV C500 when plugged into USB cable to PC it doesn't seem to think that it is connected to AC power! Still more work required but I will post more if I make progress Page 3 for application
Guest dh Posted October 13, 2004 Report Posted October 13, 2004 My final note of the evening is... There must be a way of getting this event notification to work, the power light changes straight way as does the symbol in the top bar of the screen.
Guest dh Posted October 14, 2004 Report Posted October 14, 2004 May have found the reason for the 10 min notification, in the reg HKEY_LOCAL_MACHINESYSTEMCurrentControlSetControlPowerTimeouts there is a entry BatteryPoll set to 600000 ms (10mins). On the E200 the value is 10000 ms. Can't seem to change the value to test.
Guest nickwaring Posted October 14, 2004 Report Posted October 14, 2004 Dan, Wow... you had a busy night! I've posted a question on another forum (http://www.smartphonedn.com) - I have copy and pasted some of your findings (hope you don't mind!) Thanks for the app... I'll install it and give it a go but haven't got my AC charger with me at the moment I'll have see what I can find out today! Nick
Guest nickwaring Posted October 14, 2004 Report Posted October 14, 2004 Oh... and have you ever thought we are alone! If it wasn't for the person next to me being on the internet too I'd think we were the only ones out there!
Guest nickwaring Posted October 14, 2004 Report Posted October 14, 2004 A suggestion from another forum... riki 10/14/2004 2:52 AM PST Re: Smartphone 2003 SE Power Notifications In: microsoft.public.smartphone.developer Nickwaring wrote: > I am developing an application to run on a C500 (Which runs 2003 SE). > > I'm looking for a bit of help... I trying to write an app which will switch > on the C500 Backlight when it is connected to a power source > > Getting the backlight to switch on is relativly easy but I'm having problems > with getting notification of a change in power source. > > I'm using the events for POWERINFOCHANGE and POWERSTATUSCHANGE which appear > to be sent every 10 minutes by the OS, and not when a change occurs... the > HKEY_LOCAL_MACHINESYSTEMCurrentControlSetControlPowerTimeouts key seems > to define the polling interval and is currently set to 600000 ms (10mins) > > There must be a way of getting this event notification to work immediatly as > the power light changes straight way, as does the symbol in the icon bar of > the screen. > > Any advice welcome "hmm the first thing that comes to mind, which is a bit klunge, is to use CeRunAppAtEvent(); with NOTIFICATION_EVENT_RS232_DETECTED, which will fire when the device is attached vair USB. another way is to poll for activesync starting up. again icky, and won't work if you just plug into power. my next idea, which would work better would be to poll CeGetSystemPowerStatusEx(), now this is highly OEM dependant on the values it returns. I think i ended up using (BatteryFlag == 8) (Dell PocketPC's broke for (BatteryFlag & 8)) note: these are native functions" Neither of these get me too excited.. but the Connection of a cable may be something to think about
Guest nickwaring Posted October 14, 2004 Report Posted October 14, 2004 Have you looked at the 'System Events Database' ... it appears to contain (amongst others..) - NOTIFICATION_EVENT_ON_AC_POWER - NOTIFICATION_EVENT_OFF_AC_POWER
Guest dh Posted October 14, 2004 Report Posted October 14, 2004 Just implemented this, from the available values ... OTIFICATION_EVENT_NONE = 0, NOTIFICATION_EVENT_TIME_CHANGE = 1, NOTIFICATION_EVENT_SYNC_END = 2, NOTIFICATION_EVENT_ON_AC_POWER = 3, NOTIFICATION_EVENT_OFF_AC_POWER = 4, NOTIFICATION_EVENT_NET_CONNECT = 5, NOTIFICATION_EVENT_NET_DISCONNECT = 6, NOTIFICATION_EVENT_DEVICE_CHANGE = 7, NOTIFICATION_EVENT_IR_DISCOVERED = 8, NOTIFICATION_EVENT_RS232_DETECTED = 9, NOTIFICATION_EVENT_RESTORE_END = 10, NOTIFICATION_EVENT_WAKEUP = 11, NOTIFICATION_EVENT_TZ_CHANGE = 12, NOTIFICATION_EVENT_MACHINE_NAME_CHANGE = 13 The power on / off events do not get raised, I've tested time change RS232 connect etc and they all raise an event, but not the power :!: It would be interesting to know if it would be possible to change the battery poll interval, and what impact that would have on performance etc. Seems this would be the only way.
Guest dh Posted October 14, 2004 Report Posted October 14, 2004 Update, it seems the power on event does get raised when connect to the USB, but not when connected to an ac adapter. Getting nowhere it seems
Guest dh Posted October 14, 2004 Report Posted October 14, 2004 Have changed the BatteryPoll reg key to check every 30 seconds, all works well when using AC adapter now, just not sure what impact this may have
Guest nickwaring Posted October 14, 2004 Report Posted October 14, 2004 Sorry for the silence... I've just returned home after 3 days away.. it wouldn't go down well if I dissapeared onto the PC straight away! How did you change the battery poll setting?... I tried to update it but got an error saying I wasn't allowed.. did you have to import a reg key with the new value?
Guest dh Posted October 14, 2004 Report Posted October 14, 2004 I had to create a cab file that changed the registry, I've set the poll to 30 seconds. Take a look at http://smartphone.modaco.com/viewtopic.php...tected+registry I've tried to get the app to set the reg but that doesn't seem to work, so the only way is with the cab, another thing I've learnt, how to make cabs to change the reg! I've attached the cab to make the change if you want to try, I've also make a few changes to the main apps, also attached. Give them a try and let me know. Not been able to get the NOTIFICATION_EVENT_ON_AC_POWER to work consistantly So I'm sort of back to where I was a week or so ago, but know a bit more! Page 3 for main applicationaddreg.ARMV4.CAB
Guest nickwaring Posted October 15, 2004 Report Posted October 15, 2004 Hi, Nice work.... I've done a bit of testing and have found the following (It'll be interesting to see if this is what should happen!): 1. Configuration Utility: - Nice to see details of the current status... i can see it change the Battery Flag (when I plug in the USB Cable which is attached to my PC)... I haven't seen it change the AC Line On yet (although this may be because I don't have the AC adaptor with me) - If I adjust the timeout value the registry value HKCUControlPanelBacklightACTimeout gets adjusted... all values seem to work except that I think 'Never' should update the key to FFFFFFFF (hex) or 4294967295 (dec). 1. Backlight Utility: - This doesn't seem to keep the backlight on when the USB cable from my PC is connected... I was expecting that the HKCUControlPanelBacklightBatteryTimeout key would have been ammended (as this is the one that seems to make a difference) On an additional point... does the utility set the key HKCUControlPanelPowerDisplay at the same time... what would happen when the backlight is on and the Display timeout expires? Would the Backlight timeout override the Display timeout
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now