Download the free trial version
Basic4android Video
Features
Tutorials and manuals
Showcase
Screenshots

Go Back   Android Development Forum - Basic4android > Basic4ppc (Windows Mobile) > Code Samples & Tips > Additional Libraries
Documentation Wiki Register Members List B4P Search Today's Posts Mark Forums Read

Additional Libraries Users contributed libraries.
This sub-forum is only available to licensed users.

PowerNotify Beta

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 08-05-2009, 09:30 AM
Knows the basics
 
Join Date: Dec 2008
Posts: 77
Awards Showcase
Beta Tester 
Total Awards: 1
Default PowerNotify Beta (update) v0.2

Updated to Beta v0.2

PowerNotify allows Basic4PPC to receive Power Notifications from Power Management.
This is an early Beta release as I am still testing the Power Management functions of Windows Mobile and also for the lack of devices for debugging.

It is only for the Device and requires at least .Net Compact Framework v2.

The source will not be included until the final release.
An example is attached below with the Library.

BacklightOff is triggered in situations that the backlight is on, the example includes a workaround.

The backlight turning on does not seem to trigger a BackLightOn value.
Due to hardware limitations events will not be fired from a suspend or poweroff state until after resuming.

The two events, PowerStatus and PowerStatus2, are triggered in different ways.
PowerStatus sets PowerState while PowerStatus2 is only a triggered event.

Please post any comments and suggestions.

The following is included:

AcLineStatus Returns 1 when AC line is attached
BacklightOff Turns off the backlight
BacklightOn Turns on the backlight
BatteryPercent Returns the battery level as percentage
CurrentPowerState Returns the current power state as a string, is directly from the system and unchanged
Dispose Disposes the resources, handled by the Garbage Collector
New1 Initializes the PowerNotify Class
PowerOff Powers off the System
PowerOn Powers on the System, if this doesn't work use PowerOn2
PowerOn2 Powers on the System
PowerState Returns the current power state as a string, from a numerical value in a byte[] Array
ScreenOff Turns off the screen
Start Requests power notifications from Power Management
Stop Stops the power notifications
Suspend Suspends the system

Events:

Battery Fired when the battery level or AC status changes, sets AcLineStatus and BatteryPercent
PowerStatus Fired by the Power Manager, sets PowerState values
PowerStatus2 Fired by the Power Manager, use with CurrentPowerState

The following values are returned from PowerState:

UserIdle, On, ON, Unattended, Off, Resuming, ScreenOff, Suspend, BacklightOff, Critical, Boot, Reboot

Some values may not be returned by all devices.
There are two On values as both appear to be valid.
Attached Files
File Type: zip PowerNotifyBeta.v0.1.zip (4.5 KB, 43 views)
File Type: zip PowerNotifyBeta.v0.2.zip (4.7 KB, 144 views)

Last edited by eww245 : 08-06-2009 at 08:29 PM.
Reply With Quote
  #2 (permalink)  
Old 08-05-2009, 11:35 AM
ghale's Avatar
Basic4ppc Veteran
 
Join Date: Dec 2008
Location: Earth, Europe, Italy, Puglia, Lecce
Posts: 219
Default

Very good job!
Reply With Quote
  #3 (permalink)  
Old 08-05-2009, 02:13 PM
Knows the basics
 
Join Date: Apr 2007
Posts: 56
Default

Very nice library... thanks!
Reply With Quote
  #4 (permalink)  
Old 08-06-2009, 11:02 AM
CryoGenID's Avatar
Knows the basics
 
Join Date: Feb 2009
Location: Munich, Germany
Posts: 62
Default

Wow, great Library, thanks a lot!

Is there any change to let the application still react on events etc. when I have sent the "ScreenOff"-Command?
Background: I want to have my application save power if it is not used for a time X and switch off the display... But it should wake up again when I register a movement of the device (using the htc-sensor-library here with the event of the GSensors...)?

Any help is highly appreciated :-)

But anyway: Thanks for this great library!!

Best regards,

Chris
Reply With Quote
  #5 (permalink)  
Old 08-06-2009, 06:53 PM
Knows the basics
 
Join Date: Dec 2008
Posts: 77
Awards Showcase
Beta Tester 
Total Awards: 1
Default

Quote:
Originally Posted by CryoGenID View Post
Wow, great Library, thanks a lot!

Is there any change to let the application still react on events etc. when I have sent the "ScreenOff"-Command?
Background: I want to have my application save power if it is not used for a time X and switch off the display... But it should wake up again when I register a movement of the device (using the htc-sensor-library here with the event of the GSensors...)?

Any help is highly appreciated :-)

But anyway: Thanks for this great library!!

Best regards,

Chris

I'm assuming it doesn't turn it on after the screen has been turned off with ScreenOff method. If so then it's probably since entered into suspend or unattended state.

Does it normally wake with the sensor if it's off or suspended?

If I added this option it would actually use more power due to the device staying in a ScreenOff state, preventing a lower power state.

After turning the screen off try to immediately turn it back on with a keypress or with the sensor to see how it reacts. It should turn on as long as it is still in that state.

One option that might work is if I add a PowerOn method, then within the sensor event run PowerOn.

I am trying to add the BacklightOff value, unfortunately it appears once after every state, sliding out a keyboard, when the AC line is attached, and even when using a high amount of CPU.
There is a workaround but it will have to be done in the PowerStatus event with Basic4PPC.

I'm guessing this will probably not help you though.

I'll add an update later today.
Reply With Quote
  #6 (permalink)  
Old 08-06-2009, 07:52 PM
Erel's Avatar
Administrator
 
Join Date: Apr 2007
Posts: 15,689
Awards Showcase
Basic4ppc Founder 
Total Awards: 1
Default

Great work. This library will help many users. Thank you for sharing.

I see that running it on the desktop crashes the IDE. You can read the cPPC value as described here: http://www.basic4ppc.com/forum/code-...arameters.html
If the program is running on the desktop (cPPC = false) just throw an exception saying that this library is not supported by the desktop.
Reply With Quote
  #7 (permalink)  
Old 08-06-2009, 08:05 PM
Knows the basics
 
Join Date: Dec 2008
Posts: 77
Awards Showcase
Beta Tester 
Total Awards: 1
Default

Updated to Beta 0.2

Added PowerOn and PowerOn2 methods, if PowerOn doesn't work use PowerOn2

PowerStatus now returns BacklightOff, Reboot, Boot and Critical.
BacklightOff is triggered in situations that the backlight is on, the example includes a workaround.

The method for returning AcLineStatus and BatteryPercent has changed.
Reply With Quote
  #8 (permalink)  
Old 08-06-2009, 10:50 PM
Knows the basics
 
Join Date: Dec 2008
Posts: 77
Awards Showcase
Beta Tester 
Total Awards: 1
Default

Quote:
Originally Posted by Erel View Post
Great work. This library will help many users. Thank you for sharing.

I see that running it on the desktop crashes the IDE. You can read the cPPC value as described here: http://www.basic4ppc.com/forum/code-...arameters.html
If the program is running on the desktop (cPPC = false) just throw an exception saying that this library is not supported by the desktop.
Hey Erel,

I tried to add the exception but I receive a DllNotFoundException.

It appears to be coredll for the DllImports is there any way around this?
I'm not sure why other libraries work fine with the imports.

I guessing I'll have to make a Dummy.

Thanks,
E

Code:
public PowerNotify()
{
 
if (!(bool)Thread.GetData(Thread.GetNamedDataSlot("cPPC")))
 {
  throw new 
Exception("Power Notifications are only available for the Device.");
 }
 
else
 {
  code.......
 }
}
Reply With Quote
  #9 (permalink)  
Old 08-11-2009, 12:40 PM
CryoGenID's Avatar
Knows the basics
 
Join Date: Feb 2009
Location: Munich, Germany
Posts: 62
Default

Quote:
Originally Posted by eww245 View Post
Updated to Beta 0.2

Added PowerOn and PowerOn2 methods, if PowerOn doesn't work use PowerOn2

PowerStatus now returns BacklightOff, Reboot, Boot and Critical.
BacklightOff is triggered in situations that the backlight is on, the example includes a workaround.

The method for returning AcLineStatus and BatteryPercent has changed.
Thanks a lot for your answer and your update!
Sorry that I didn't report back any sooner...
I am currently trying to figure out if "PowerOn" works...
(The problem is that my whole ppc sometimes freezes when I try to run/quit the proof-of-concept application)

Quote:
Does it normally wake with the sensor if it's off or suspended?
No if the device is off or suspended, no events seem to be able to trigger a wakeup :-(
But that's exactly what I need ;-)

In order to make at least the proof-of-concept work, I would already be happy if the screen turned itself off and back on if an event from the g-sensor comes in...

Best regards,

Chris
Reply With Quote
  #10 (permalink)  
Old 08-25-2009, 09:58 AM
Basic4ppc Expert
 
Join Date: May 2008
Location: Berkshire, UK
Posts: 810
Awards Showcase
Beta Tester 
Total Awards: 1
Default

I think that this library is going to do what I want (which is to be notified if the external power that I've set up for my PDA fails while it is in use).

But since it is "beta" I feel obliged to report any strange things that I see. It may illuminate behaviour with disparate devices.

First, nothing to do with the device, the sample SBP file in the zips (I assume it is the same in each) won't load in Basic4PPC; it says: "Error loading file./Input string was not in a correct format". I wondered if this were a UTF16 problem so tried opening with Notepad (which worked OK) and writing in ANSI and in Unicode rather than the UTF-8 that Notepad offered me. But none of these made any difference. Puzzling since I assume everyone else has used it OK!

Then when I use my simple application I get two notification PowerNotify_Battery events when I remove the power. The code merely displays as follows:
Msgbox("Battery = " & PowerNotify.BatteryPercent & "%" & CRLF & PowerNotify.PowerState)

The first notification displays "255" as the BatteryPercent which is not believable (;-). The second, extra, event shows a correct "100" (I haven't tried with a partially-discharged battery yet). Sometimes I have seen a string saying the backlight is off, but this is intermittent (as well as being incorrect!). But sometimes I get just the one event with "100%", so it is a bit mysterious.

Conclusion: it's useful for what I wanted, but maybe a bit variable on my hardware; if anyone would want my code (it may be a tiny part of the proffered sample for all I know) they would be welcome...

Regards, Mike.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Beta testers medal Erel Announcements 0 06-26-2009 02:02 PM
V6.80 released to beta testers Erel Beta Versions 3 06-07-2009 07:55 PM
Beta testers group Erel Announcements 14 04-26-2009 08:38 AM
Basic4ppc V6.80 - first beta is released Erel Announcements 0 04-24-2009 05:58 AM
Beta versions Erel Beta Versions 0 08-26-2008 09:32 PM


All times are GMT. The time now is 06:51 AM.


Powered by vBulletin® Version 3.6.12
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0