Akkustand herausfinden

  • Moin Moin,

    ich wollte mir ein kleines Warnsystem für mein Laptop schreiben, da letzens der Akku in einer ungünstigen Situation "den Geist aufgegeben" hat und die normale Warnung nicht auf sich aufmerksam gemacht hat.
    Im Forum habe ich folgenden Thread gefunden, der beinhaltet, was ich brauche (den Akkustand in %):
    [ offen ] Laufzeit des Akkus herausfinden
    Leider bin ich nicht dahintergekommen, wie er ausgegeben wird und meine Versuche dahinterzukommen verliefen immer ins leere.
    Kann mir einer sagen wie das geht? Das scheint ja über Dll's zu laufen.
    Hier ist auch noch einmal das Script:

    Spoiler anzeigen
    [autoit]

    #include <GUIConstants.au3>

    [/autoit] [autoit][/autoit] [autoit]

    Global $Label[5]
    local $sek, $min, $std
    $sek = 0
    $min = 0
    $std = 0

    [/autoit] [autoit][/autoit] [autoit]

    ; GUI
    GUICreate("Form1", 300, 140, 100, 100)
    For $i = 0 To 4
    $Label[$i] = GUICtrlCreateLabel("1", 20, 20+$i*20, 200, 20)
    Next
    $Level = GUICtrlCreateProgress(20,20+$i*20,260,10)
    $zeit3 = GUICtrlCreateLabel("1", 230, 40, 100, 20)
    $zeit2 = GUICtrlCreateLabel("1", 230, 60, 100, 20)
    $zeit1 = GUICtrlCreateLabel("1", 230, 80, 100, 20)
    GUICtrlCreateLabel("Läuft seit:", 230, 20, 100, 20)

    [/autoit] [autoit][/autoit] [autoit]

    GUISetState(@SW_SHOW)
    ;===============================================================================
    _Update()
    ;sek()
    AdlibRegister("_Update",1000); alle Sekunden Daten Abfragen und die Anzeige aktualisieren
    ;AdlibEnable("sek",1000)

    [/autoit] [autoit][/autoit] [autoit]

    HotKeySet("{ESC}","_Exit") ; Programm beenden

    [/autoit] [autoit][/autoit] [autoit]

    While 1
    If GuiGetMsg() = $GUI_EVENT_CLOSE Then _Exit()
    Sleep(50) ; Um die CPU zu entlasten
    WEnd

    [/autoit] [autoit][/autoit] [autoit]

    Exit
    ;===============================================================================
    Func _Update()
    Local $battery = _BatteryQuery()
    Local $sLabel
    GUICtrlSetData($Label[0], "Dauer noch: " & Round($battery[3] / 3600,2) & " Stunde(n)")
    GUICtrlSetData($Label[1], "Dauer noch: " & Round($battery[3] / 60) & " Minuten")
    GUICtrlSetData($Label[2], "Dauer noch: " & Round($battery[3]) & " Sekunden")
    Select
    Case BitAND($battery[1], 4)
    $sLabel = "Kritisch"
    Case BitAND($battery[1], 2)
    $sLabel = "Niedrig"
    Case BitAND($battery[1], 1)
    $sLabel = "Hoch"
    EndSelect
    GUICtrlSetData($Label[3], $sLabel & "(" & $battery[2] & "%)")
    GUICtrlSetData($Level,$battery[2])

    [/autoit] [autoit][/autoit] [autoit]

    Switch $battery[0]
    Case 0
    $sLabel = "Offline"
    Case 1
    $sLabel = "Online"
    Case Else
    $sLabel = "Unknown status "
    EndSwitch
    GUICtrlSetData($Label[4], "AC Status: " & $sLabel)
    if $sLabel = "online" then
    GUICtrlSetData($Label[0], "Dauer noch: Netzteil angeschlossen")
    GUICtrlSetData($Label[1], "Dauer noch: Netzteil angeschlossen")
    GUICtrlSetData($Label[2], "Dauer noch: Netzteil angeschlossen")
    GUICtrlSetData($Label[3], $sLabel & " (" & $battery[2] & "%) LADEND")
    EndIf

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    $sek = $sek +1
    if $sek = 60 Then
    $sek = 0
    $min = $min +1
    if $min = 60 Then
    $min = 0
    $std = $std + 1
    EndIf
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    GUICtrlSetData($zeit1, $sek & " Sekunden")
    GUICtrlSetData($zeit2, $min & " Minuten")
    GUICtrlSetData($zeit3, $std & " Stunden")
    ;sleep(1000)
    FileOpen("c:\test.txt",2)
    Filewrite("c:\test.txt", $std & " Stunden " & $min & " Minuten " & $sek & " Sekunden")
    fileclose("c:\test.txt")

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func _BatteryQuery()
    Local $SystemPower, $ret, $array[4]
    $SystemPower = DllStructCreate("ubyte;ubyte;ubyte;ubyte;ulong;ulong")
    If @error Then
    SetError(-1)
    Return $array
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    ; make the DllCall
    $ret = DllCall("kernel32.dll", "int", "GetSystemPowerStatus", "ptr", DllStructGetPtr($SystemPower))
    If @error Then;DllCall Failed
    SetError(-2)
    $SystemPower = 0
    Return $array
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    If Not $ret[0] Then; GetSystemPowerStatus Failed
    SetError(-3)
    $SystemPower = 0
    Return $array
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    ; Fill the array
    $array[0] = DllStructGetData($SystemPower, 1);AC
    $array[1] = DllStructGetData($SystemPower, 2);Battery Charge
    $array[2] = DllStructGetData($SystemPower, 3);Battery Charge %
    $array[3] = DllStructGetData($SystemPower, 5);Sec Battery Left

    [/autoit] [autoit][/autoit] [autoit]

    ; free the struct
    $SystemPower = 0

    [/autoit] [autoit][/autoit] [autoit]

    Return $array

    [/autoit] [autoit][/autoit] [autoit]

    Func _Exit()
    Exit
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    func sek()

    [/autoit] [autoit][/autoit] [autoit]

    $sek = $sek +1
    if $sek = 60 Then
    $sek = 0
    $min = $min +1
    if $min = 60 Then
    $min = 0
    $std = $std + 1
    EndIf
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    GUICtrlSetData($zeit1, $sek & " Sekunden")
    GUICtrlSetData($zeit2, $min & " Minuten")
    GUICtrlSetData($zeit3, $std & " Stunden")
    sleep(1000)
    FileOpen("c:\test.txt",2)
    Filewrite("c:\test.txt", $std & " Stunden " & $min & " Minuten " & $sek & " Sekunden")
    fileclose("c:\test.txt")
    EndFunc

    [/autoit]

    Vielen Dank
    Aquaplant

    Einmal editiert, zuletzt von Aquaplant (31. Mai 2010 um 13:18)