This repository has been archived by the owner on Apr 21, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
XboxControllerBatteryWatcher.au3
192 lines (141 loc) · 5.24 KB
/
XboxControllerBatteryWatcher.au3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
#NoTrayIcon
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=icon.ico
#AutoIt3Wrapper_Res_Description=Xbox Controller Battery Watcher
#AutoIt3Wrapper_Res_Fileversion=1.0.1.0
#AutoIt3Wrapper_Res_File_Add=iconController\iconControllerFullSmall.jpg, rt_rcdata, iconFull
#AutoIt3Wrapper_Res_File_Add=iconController\iconControllerMediumSmall.jpg, rt_rcdata, iconMedium
#AutoIt3Wrapper_Res_File_Add=iconController\iconControllerLowSmall.jpg, rt_rcdata, iconLow
#AutoIt3Wrapper_Res_File_Add=iconController\iconControllerEmptySmall.jpg, rt_rcdata, iconEmpty
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <Array.au3>
#include <TrayConstants.au3>
#include <String.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Timers.au3>
#include <parameters.au3>
#include <resources.au3>
#include <helper.au3>
#include <battery.au3>
#include <hotkeys.au3>
#include <autostart.au3>
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
if OtherInstanceExists() then
Exit( 0 )
endif
; tray settings
Opt( "TrayIconHide", 0 )
Opt( "TrayMenuMode", 3 )
Opt( "TrayOnEventMode", 1 )
TraySetToolTip( "Xbox Controller Battery Watcher" )
; version
TrayCreateItem( "Xbox Controller Battery Watcher " & GetVersion() )
TrayItemSetState( -1, $TRAY_DISABLE )
; hotkey status
$hotkeysStatusTrayItem = TrayCreateItem( " " )
TrayItemSetState( -1, $TRAY_DISABLE )
; spacer
TrayCreateItem( "" )
; battery levels
TrayCreateItem( "Controller Battery Level:" )
TrayItemSetState( -1, $TRAY_DISABLE )
dim $statusTrayItem[$MAX_CONTROLLERS]
for $i = 0 to $MAX_CONTROLLERS - 1
$statusTrayItem[$i] = TrayCreateItem( " " )
TrayItemSetState( -1, $TRAY_DISABLE )
next
; spacer
TrayCreateItem( "" )
; autostart checkbox
$autostartTrayItem = TrayCreateItem( "Autostart" )
TrayItemSetOnEvent( -1, "AutostartClicked" )
if GetAutostart() then
TrayItemSetState( -1, $TRAY_CHECKED )
endif
; reload hotkey settings file
TrayCreateItem( "Reload Hotkey Settings" )
TrayItemSetOnEvent( -1, "ReadHotkeysIni" )
; spacer
TrayCreateItem( "" )
; exit
TrayCreateItem( "Exit" )
TrayItemSetOnEvent( -1, "ExitScript" )
local $hotkeyTimerStart = 0
local $batteryTimerStart = 0
;HotKeySet( "{ESC}", "ExitScript" )
ReadHotkeysIni()
while 1
if $currentWinTrans <> 0 then
Sleep( 100 )
else
Sleep( 1000 )
endif
if TimerDiff( $hotkeyTimerStart ) >= $HOTKEY_POLLING_DELAY then
CheckHotkey()
$hotkeyTimerStart = TimerInit()
endif
if TimerDiff( $batteryTimerStart ) >= $BATTERY_POLLING_DELAY then
; get battery info
local $batteryInfos = GetXboxGetBatteryLevel()
for $controllerIndex = 0 to $MAX_CONTROLLERS - 1
local $controllerNumber = $controllerIndex + 1
local $batteryInfo = $batteryInfos[$controllerIndex]
if $batteryInfo[0] == $XBOX_CONTROLLER_TYPE_DISCONNECTED or $batteryInfo[0] == $XBOX_CONTROLLER_TYPE_WIRED then
; controller is disconnected or wired
if $controllerIsConnected[$controllerIndex] then
ShowInfo( $controllerIndex, "Controller " & $controllerNumber & " disconnected - Battery Level", $controllerLastBatteryLevel[$controllerIndex] )
endif
$controllerIsConnected[$controllerIndex] = false
$controllerWarnedLow[$controllerIndex] = false
$controllerWarnedEmpty[$controllerIndex] = false
TrayItemSetText( $statusTrayItem[$controllerIndex], " " & $controllerNumber & ". -" )
else
; controller is connected wireless
local $showInfo = false
if $SHOW_INFO_ON_FULLSCREEN_EXIT and not IsFullscreen() and $wasFullscreen then
$showInfo = true
endif
if $batteryInfo[1] == $XBOX_CONTROLLER_LEVEL_LOW and not $controllerWarnedLow[$controllerIndex] then
$showInfo = true
$controllerWarnedLow[$controllerIndex] = true
elseif $batteryInfo[1] == $XBOX_CONTROLLER_LEVEL_EMPTY and not $controllerWarnedEmpty[$controllerIndex] then
$showInfo = true
$controllerWarnedEmpty[$controllerIndex] = true
elseif not $controllerIsConnected[$controllerIndex] then
$showInfo = true
endif
if $showInfo then
$newText = "Controller " & $controllerNumber & " - Battery Level"
if not $controllerIsConnected[$controllerIndex] then
$newText = "Controller " & $controllerNumber & " connected - Battery Level"
endif
ShowInfo( $controllerIndex, $newText, $batteryInfo[1] )
endif
$controllerIsConnected[$controllerIndex] = true
$controllerLastBatteryLevel[$controllerIndex] = $batteryInfo[1]
$wasFullscreen = false
TrayItemSetText( $statusTrayItem[$controllerIndex], " " & $controllerNumber & ". " & Level2Text( $batteryInfo[1] ) )
endif
next
; check if fullscreen is shown currently
if $SHOW_INFO_ON_FULLSCREEN_EXIT and IsFullscreen() then
$wasFullscreen = true
endif
$batteryTimerStart = TimerInit()
endif
; check if window is transparent and we are waiting for a mouse over
if $waitingForMouseOver then
local $mousePos = MouseGetPos()
local $guiPos = WinGetPos( $gui )
if $mousePos[0] >= $guiPos[0] and $mousePos[0] <= $guiPos[0] + $guiPos[2] and $mousePos[1] >= $guiPos[1] and $mousePos[1] <= $guiPos[1] + $guiPos[3] then
$waitingForMouseOver = false
ShowInfo( Null, Null, Null )
endif
endif
if $fadingStatus <> "" then
GuiFade()
endif
wend
Exit( 0 )