Re: Windows CE 5.0 - Battery Strenght via registry
I think this is the only way to go about this
Looks complicated ( at least for me ! ), but it would be very very interesting to get this working, I think we all would like to have a sample on this
Re: Windows CE 5.0 - Battery Strenght via registry
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
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
Re: Windows CE 5.0 - Battery Strenght via registry
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.
Code:
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
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 ...
Code:
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:
Code:
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:
Code:
<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:
Code:
Dim sps As New SYSTEM_POWER_STATUS_EX()
ret = GetSystemPowerStatusEx(sps, False)
Re: Windows CE 5.0 - Battery Strenght via registry
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
Code:
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
Re: Windows CE 5.0 - Battery Strenght via registry
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?
Code:
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?
Re: Windows CE 5.0 - Battery Strenght via registry
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.
Last edited by DataMiser; July 25th, 2009 at 07:10 PM.
Re: Windows CE 5.0 - Battery Strenght via registry
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 . 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%
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.