G19 Wetteranzeige

  • Hi,

    hier habe ich nun ein weiteres Applet für die G19. Es zeigt das aktuelle Wetter sowie die Prognose für die nächsten drei Tage an. Mit einem druck auf die "Menu"-Taste der G19 erscheint ein Input indem man den Ort angeben kann der angezeigt werden soll.

    Die folgenden Komponenten werden benötigt

    Zum einen natürliche die UDF von Carsten 8: AdvanceLcd

    Dann noch die entsprechende DLL aus AdvanceLcd. Im herruntergladenen Archiv unter Binary und dann entsprechend dem Betriebsystem x64 oder x86 zu finden.

    Und hier nun das eigentliche Script (die vier Funktionen oben sind drin weil diese in der UDF fehlen) mit der bitte um Feadback:

    Spoiler anzeigen
    [autoit]

    #include <String.au3>
    #include <AdvanceLCD.au3>
    #include <Array.au3>
    OnAutoItExitRegister("killfunc")
    Global $count

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

    Func LcdSetPriority($hApplet, $nPriority = "LCD_PRIORITY_NORMAL", $bForeground = 0)
    Local $ret = DllCall($dll, "int", "LcdSetPriority", "ptr", $hApplet, "int", $nPriority, "int", $bForeground)
    If @error Then Return SetError(1, @error, 0)
    Return $ret[0]
    EndFunc ;==>LcdSetPriority

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

    Func LcdDrawText($hApplet, $pString, $iX = 0, $iY = 0)
    Local $ret = DllCall($dll, "int", "LcdDrawTextA", "ptr", $hApplet, "str", $pString, "int", $iX, "int", $iY)
    If @error Then Return SetError(1, @error, 0)
    Return $ret[0]
    EndFunc ;==>LcdDrawText

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

    Func LcdSetFont($hApplet, $hFont)
    Local $ret = DllCall($dll, "int", "LcdSetFont", "ptr", $hApplet, "ptr", $hFont)
    If @error Then Return SetError(1, @error, 0)
    Return $ret[0]
    EndFunc ;==>LcdSetFont

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

    Func LcdLoadFont($sFamily, $iHeight, $iFlags, $sFile)
    Local $ret = DllCall($dll, "ptr", "LcdLoadFontW", "wstr", $sFamily, "int", $iHeight, "int", $iFlags, "wstr", $sFile)
    If @error Then Return SetError(1, @error, 0)
    Return $ret[0]
    EndFunc ;==>LcdLoadFont

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

    LcdInitialize()
    $hApplet = LcdCreateApplet("Wetteranzeige", 2, 1, 1)
    LcdSetTarget($hApplet, 0)
    LcdWaitActivation($hApplet)
    LcdSetPriority($hApplet, $LCD_PRIORITY_NORMAL, 1)

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

    _wetter()

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

    Func _wetter()
    $count = 0

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

    $ort = IniRead(@ScriptDir & "/config.ini", "Wetter", "Ort", "Frankfurt")

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

    LcdClear($hApplet, 0x000000)

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

    $wetter = BinaryToString(InetRead("http://www.google.com/ig/api?weather=" & $ort & "&hl=de", 16))
    $currentdate = _StringBetween($wetter, "<current_conditions>", "</current_conditions>")

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

    $Font = LcdLoadFont("Arial", 30, $LCD_FONT_DEFAULT, "arial.ttf")
    LcdSetFont($hApplet, $Font)
    LcdDrawText($hApplet, $ort, 0, 0)

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

    $currentcondition = _StringBetween($currentdate[0], '<condition data="', '"/>')
    LcdDrawText($hApplet, $currentcondition[0], 0, 30)

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

    $currenttempc = _StringBetween($currentdate[0], '<temp_c data="', '"/>')
    LcdDrawText($hApplet, $currenttempc[0] & "°", 0, 60)

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

    $currenthumidity = _StringBetween($currentdate[0], '<humidity data="', '"/>')
    LcdDrawText($hApplet, $currenthumidity[0], 0, 90)

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

    $currenticon = _StringBetween($currentdate[0], '<icon data="', '"/>')
    $curreniconname = StringSplit($currenticon[0], "/")
    If $curreniconname[0] = 5 Then
    InetGet("http://www.google.com" & $currenticon[0], @TempDir & "/" & $curreniconname[5], 16)
    $currentimage = LcdLoadPixmap(@TempDir & "/" & $curreniconname[5])
    LcdDrawPixmap($hApplet, $currentimage, 250, 15)
    EndIf

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

    $forecastdate = _StringBetween($wetter, "<forecast_conditions>", "</forecast_conditions>")

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

    $dayonename = _StringBetween($forecastdate[0], '<day_of_week data="', '"/>')
    $daytwoname = _StringBetween($forecastdate[1], '<day_of_week data="', '"/>')
    $daythreename = _StringBetween($forecastdate[2], '<day_of_week data="', '"/>')
    $dayfourname = _StringBetween($forecastdate[3], '<day_of_week data="', '"/>')

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

    $Font = LcdLoadFont("Arial", 15, $LCD_FONT_DEFAULT, "arial.ttf")
    LcdSetFont($hApplet, $Font)
    LcdDrawText($hApplet, $dayonename[0], 15, 175)
    LcdDrawText($hApplet, $daytwoname[0], 95, 175)
    LcdDrawText($hApplet, $daythreename[0], 175, 175)
    LcdDrawText($hApplet, $dayfourname[0], 255, 175)

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

    $dayoneicon = _StringBetween($forecastdate[0], '<icon data="', '"/>')
    $daytwoicon = _StringBetween($forecastdate[1], '<icon data="', '"/>')
    $daythreeicon = _StringBetween($forecastdate[2], '<icon data="', '"/>')
    $dayfouricon = _StringBetween($forecastdate[3], '<icon data="', '"/>')

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

    $dayoneiconname = StringSplit($dayoneicon[0], "/")
    $daytwoiconname = StringSplit($daytwoicon[0], "/")
    $daythreeiconname = StringSplit($daythreeicon[0], "/")
    $dayfouriconname = StringSplit($dayfouricon[0], "/")

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

    InetGet("http://www.google.com" & $dayoneicon[0], @TempDir & "/" & $dayoneiconname[5], 16)
    InetGet("http://www.google.com" & $daytwoicon[0], @TempDir & "/" & $daytwoiconname[5], 16)
    InetGet("http://www.google.com" & $daythreeicon[0], @TempDir & "/" & $daythreeiconname[5], 16)
    InetGet("http://www.google.com" & $dayfouricon[0], @TempDir & "/" & $dayfouriconname[5], 16)

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

    $dayoneimage = LcdLoadPixmap(@TempDir & "/" & $dayoneiconname[5])
    LcdDrawPixmap($hApplet, $dayoneimage, 15, 195)
    $daytwoimage = LcdLoadPixmap(@TempDir & "/" & $daytwoiconname[5])
    LcdDrawPixmap($hApplet, $daytwoimage, 95, 195)
    $daythreeimage = LcdLoadPixmap(@TempDir & "/" & $daythreeiconname[5])
    LcdDrawPixmap($hApplet, $daythreeimage, 175, 195)
    $dayfourimage = LcdLoadPixmap(@TempDir & "/" & $dayfouriconname[5])
    LcdDrawPixmap($hApplet, $dayfourimage, 255, 195)

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

    $dayonelow = _StringBetween($forecastdate[0], '<low data="', '"/>')
    $daytwolow = _StringBetween($forecastdate[1], '<low data="', '"/>')
    $daythreelow = _StringBetween($forecastdate[2], '<low data="', '"/>')
    $dayfourlow = _StringBetween($forecastdate[3], '<low data="', '"/>')

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

    LcdDrawText($hApplet, $dayonelow[0] & "°", 56, 220)
    LcdDrawText($hApplet, $daytwolow[0] & "°", 136, 220)
    LcdDrawText($hApplet, $daythreelow[0] & "°", 216, 220)
    LcdDrawText($hApplet, $dayfourlow[0] & "°", 296, 220)

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

    $dayonehigh = _StringBetween($forecastdate[0], '<high data="', '"/>')
    $daytwohigh = _StringBetween($forecastdate[1], '<high data="', '"/>')
    $daythreehigh = _StringBetween($forecastdate[2], '<high data="', '"/>')
    $dayfourhigh = _StringBetween($forecastdate[3], '<high data="', '"/>')

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

    LcdDrawText($hApplet, $dayonehigh[0] & "°", 56, 195)
    LcdDrawText($hApplet, $daytwohigh[0] & "°", 136, 195)
    LcdDrawText($hApplet, $daythreehigh[0] & "°", 215, 195)
    LcdDrawText($hApplet, $dayfourhigh[0] & "°", 296, 195)

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

    LcdUpdate($hApplet, 0)
    EndFunc ;==>_wetter

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

    While 1
    Sleep(100)
    If LcdButtonState($hApplet, $LCD_BUTTON_MENU) = True Then
    $ort = InputBox("Ort eingeben", "Bitte den Ort angeben, dessen Wetter angezeigt werden soll.")
    $ort = StringReplace($ort, "ä", "ae")
    $ort = StringReplace($ort, "ö", "oe")
    $ort = StringReplace($ort, "ü", "ue")
    IniWrite(@ScriptDir & "/config.ini", "Wetter", "Ort", $ort)
    _wetter()
    EndIf

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

    If $count > 36000 Then
    _wetter()
    Else
    $count = $count + 1
    EndIf
    WEnd

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

    Func killfunc()
    LcdDeleteApplet($hApplet)
    LcdDeInitialize()
    EndFunc ;==>killfunc

    [/autoit]

    Bilder

    Andy hat mir ein Schnitzel gebacken aber da war ein Raupi drauf und bevor Oscar das Bugfixen konnte kam Alina und gab mir ein AspirinJunkie.