Click to See Complete Forum and Search --> : [RESOLVED] Windows CE 5.0 - Battery Strenght via registry
manny_gt
July 24th, 2009, 05:10 AM
Hello,
I'm back again :D
In the
HKEY_LOCAL_MACHINE\System\State\Battery
I have all I need to know about the battery status. I need to know what are possible values for battery strenght.
Can you help me?
Thanks to all!
:)
TT(n)
July 24th, 2009, 05:57 AM
Looks like there are a couple ways to go about it here:
http://msdn.microsoft.com/en-us/library/aa456240.aspx
Is this what you're looking for:
BATTERYLEVEL_VERYLOW 0
BATTERYLEVEL_LOW 21
BATTERYLEVEL_MEDIUM 41
BATTERYLEVEL_HIGH 61
BATTERYLEVEL_VERYHIGH 81
BATTERYSTATE_NORMAL 0
BATTERYSTATE_NOTPRESENT 1
BATTERYSTATE_CHARGING 2
BATTERYSTATE_LOW 4
BATTERYSTATE_CRITICAL 8
HanneSThEGreaT
July 24th, 2009, 06:24 AM
I think this is the only way to go about this :)
Looks complicated ( at least for me :lol: ! ), but it would be very very interesting to get this working, I think we all would like to have a sample on this :)
manny_gt
July 24th, 2009, 07:53 AM
Thanks TT(n) :)
@HanneSThEGreaT: I'm working on a virtual desktop for my GPS Windows CE 5.0 core base witha a 400 MHz samsung CPU.
A image for you below :)
http://i30.tinypic.com/2meoawz.jpg
This Virtual Desktop would be fully customizable for:
- Background
- Buttons (normal and hitting status)
- Multipages
- Every buttons can launch several applications or commands. Useful to fix the TomTom issue (My Documents folder)
What is working now:
- Buttons
- GPS Status
- Volume control by the wheel of the GPS
What I have to do:
- Reading a .ini file that have these options:
_ StartUp command
_ Buttons images and commands
_ Exiting command
- ... Any idea for the future :D
Reading the file has been done! I've only to personalize my Virtual Desktop
manny_gt
July 24th, 2009, 12:42 PM
Hello TT(n)
the link is for Windows Mobile instead of Windows CE... I've found no references on my VB2005, no keys in the registry on my GPS... :(
Also i've not found the HKLM\System\State\Battery
:( :(
TT(n)
July 25th, 2009, 06:29 AM
CE is loosely based on mobile,... as I remember... lol
The values should be the same.
I'm not really familiar with the registry in WinCE, but here is a way to get power status in vb.net using the API.
Private Structure SYSTEM_POWER_STATUS
Public ACLineStatus As Byte
Public BatteryFlag As Byte
Public BatteryLifePercent As Byte
Public Reserved1 As Byte
Public BatteryLifeTime As Int32
Public BatteryFullLifeTime As Int32
End Structure
Private Declare Function apiGetSystemPowerStatus Lib "kernel32" Alias "GetSystemPowerStatus" (ByRef lpSystemPowerStatus As SYSTEM_POWER_STATUS) As Int32
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim acdc As Int32 = GetPowerStatus.ACLineStatus
Dim bStrength As Int32 = GetPowerStatus.BatteryFlag
If acdc = 0 Then
MessageBox.Show("AC power status: Offline")
ElseIf acdc = 1 Then
MessageBox.Show("AC power status: OnLine")
ElseIf acdc = 2 Then
MessageBox.Show("AC power status: Unknown")
End If
If bStrength = 1 Then
MessageBox.Show("Battery charge status: High")
ElseIf bStrength = 2 Then
MessageBox.Show("Battery charge status: Low")
ElseIf bStrength = 4 Then
MessageBox.Show("Battery charge status: Critical")
ElseIf bStrength = 8 Then
MessageBox.Show("Battery charge status: Charging")
ElseIf bStrength = 128 Then
MessageBox.Show("Battery charge status: No system battery")
ElseIf bStrength = 255 Then
MessageBox.Show("Battery charge status: Unknown Status")
End If
End Sub
Private Function GetPowerStatus() As SYSTEM_POWER_STATUS
Dim SPS As New SYSTEM_POWER_STATUS
If apiGetSystemPowerStatus(SPS) = 0 Then Return Nothing 'get the battery powerstatus and return nothing if fails
Return SPS
End Function
If this api is included in the coredll, then you can also get BatteryLifePercent above.
http://msdn.microsoft.com/en-us/library/aa373232(VS.85).aspx
___
DataMiser
July 25th, 2009, 10:07 AM
There is an interesting article on MSDN.
http://msdn.microsoft.com/en-us/library/aa446564.aspx
I have not tried this myself yet but it looks like it may be what you are looking for assuming that using the registry is not a requirement.
Related code and comments from the link above ...
Declare Function GetSystemPowerStatusEx Lib "coredll" _
Alias "GetSystemPowerStatusEx" _
(<[In](), Out()> ByVal lpSystemPowerStatus As SYSTEM_POWER_STATUS_EX, _
ByVal fUpdate As Boolean) As Long
The first thing to notice in the declaration is the specification of the parameter types. They can be used to specify which parameters are being passed out and which parameters will be returned containing the desired information. Since "In" is also a Visual Basic keyword, it is necessary to enclose it in square brackets. The "In" and "Out" types are actually defined by InteropServices and it is necessary to import this namespace:
Imports System.Runtime.InteropServices
The next thing you will note is the SYSTEM_POWER_STATUS_EX structure that is returned by the function. This can be handled using a Structure or by placing the structure definition in a class and by specifying that the members are arranged sequentially:
<StructLayout(LayoutKind.Sequential)> _
Public Class SYSTEM_POWER_STATUS_EX
Public ACLineStatus As Byte
Public BatteryFlag As Byte
Public BatteryLifePercent As Byte
Public Reserved1 As Byte
Public BatteryLifeTime As Int16
Public BatteryFullLifeTime As Int16
Public Reserved2 As Byte
Public BatteryBackupFlag As Byte
Public BackupBatteryLifeTime As Byte ' DocBug
Public Reserved3 As Byte
Public BackupBatteryLifePercent As Byte 'DocBug
Public BackupBatteryFullLifeTime As Byte
End Class
Note that two of the members—BackupBatteryLifeTime and BackupBatteryLifePercent—are actually reversed from what is documented.
Now calling this function is also straightforward:
Dim sps As New SYSTEM_POWER_STATUS_EX()
ret = GetSystemPowerStatusEx(sps, False)
manny_gt
July 25th, 2009, 10:41 AM
Hello Datamiser, your method did not works... Also your I've tryed your method yesterday.
Works only the second post of TT(n) but modifying the declaration with
Public Declare Function apiGetSystemPowerStatus Lib "Coredll.dll" Alias "GetSystemPowerStatusEx" (ByRef lpSystemPowerStatus As SYSTEM_POWER_STATUS) As Int32
Batterylifepercent now returns 50
BatteryFullLifeTime and BatteryLifeTime are returning -1
Any ideas?
manny_gt
July 25th, 2009, 10:51 AM
The percentage is now 40. I'll track this now :)
See you next hours..
TT(n)
July 25th, 2009, 03:24 PM
Ah, Data, so that's why in is in brackets.
Cool, that makes sense now.
Manny,
BatteryFullLifeTime and BatteryLifeTime are returning -1
Perhaps try using Byte instead of Int32, or some other type.
I translated that code from the API guide, which used longs.
Those are the only two that were different.
I really don't know, but I suspect the type.
Looks like you have a percentage though!
TT(n)
July 25th, 2009, 03:41 PM
Hey just a wild guess, but the method Datamiser found may not work anymore, but once did.
The struture is being passed in/out ByVal, but typically we'd use ByRef for that. Right?
Declare Function GetSystemPowerStatusEx Lib "coredll" _
Alias "GetSystemPowerStatusEx" _
(<[In](), Out()> ByVal lpSystemPowerStatus As SYSTEM_POWER_STATUS_EX, _
ByVal fUpdate As Boolean) As Long
I bet that would work, if it were normal with ByRef, without in/out.
Ehh?
_______
DataMiser
July 25th, 2009, 07:05 PM
I found another method in my local samples. This came with my symbol SDK. I have not used it yet but I did a quick look see and I do not see any references to symbol specific libs so this may work on other devices as well. I am attaching it here if you want to give it a try.
manny_gt
July 26th, 2009, 04:09 AM
Good Morning! :)
@TT(n) Using byte instead of int32 give me an exception error
@DataMiser: Tryed your sampe. The Main Percentage returns same percentage of my BatteryLifePercent :D. Enable and disable backlight did not work. Suspend works fine!
I'm going to try the byref / byval suggested by TT(n) but I think that the BatteryLifePercent is the solution. Next hour my GPS will shutdown for low energy, so I'll go to recharge it. Once charged I'll see the percentage battery if is 90% - 100%
Thanks to all :D
manny_gt
July 26th, 2009, 09:00 AM
Hello!
After full recharging my GPS the BatteryLifePercent returns 100 now... So works fine
The ACLineStatus works too.
:)
DataMiser
July 26th, 2009, 09:31 AM
Which method did you end up using?
manny_gt
July 26th, 2009, 09:34 AM
it's explained at post #6 but using declare function explained at #8. It's ok for me.
mbg_is_doing_VB
August 13th, 2009, 09:51 AM
Even though this has been resolved, there is another way, using .Net classes.
Have a look at the SystemState class.
http://msdn.microsoft.com/en-us/library/microsoft.windowsmobile.status.systemstate.aspx
It is a goldmine of information.
(Don't forget to first add the assembly "Microsoft.WindowsMobile.Status" (in microsoft.windowsmobile.status.dll))
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.