Update LedKeyboardShortcuts.ahk

updated to handle server errors
This commit is contained in:
flagstone78 2018-04-15 16:37:10 -06:00 committed by GitHub
parent 441d61aa4e
commit 12d6abee63
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -4,6 +4,7 @@ SetBatchLines, -1
socket := new Example("ws://192.168.1.33:81") ; replace with the ip address of the mclighting controller socket := new Example("ws://192.168.1.33:81") ; replace with the ip address of the mclighting controller
connected := 0 ; state variable for server connection
incrementAmount := 10 ; how finely you adjust the color, speed, and brightness per keypress incrementAmount := 10 ; how finely you adjust the color, speed, and brightness per keypress
maxColor := 255 maxColor := 255
@ -24,7 +25,7 @@ mode := 1
mode := maxMode mode := maxMode
cmd = /%mode% ; / is the set effect mode command cmd = /%mode% ; / is the set effect mode command
TrayTip, , Mode: %mode% TrayTip, , Mode: %mode%
socket.Send(cmd) sendCmd(cmd)
; MsgBox %cmd% ; MsgBox %cmd%
return return
@ -35,19 +36,19 @@ mode := 1
mode := 0 mode := 0
TrayTip, , Mode: %mode% TrayTip, , Mode: %mode%
cmd = /%mode% cmd = /%mode%
socket.Send(cmd) sendCmd(cmd)
; MsgBox %cmd% ; MsgBox %cmd%
return return
^#Numpad5:: ; turn off ^#Numpad5:: ; turn off
TrayTip, , Leds are off TrayTip, , Leds are off
socket.Send("=off") ; = is the set control command sendCmd("=off") ; = is the set control command
return return
^#Numpad0:: ; turn on to static color ^#Numpad0:: ; turn on to static color
TrayTip, , Leds are on TrayTip, , Leds are on
cmd := "*"+toHexColor(red,green,blue) ; * is the set all command cmd := "*"+toHexColor(red,green,blue) ; * is the set all command
socket.Send(cmd) ; = is the set control command sendCmd(cmd) ; = is the set control command
return return
@ -57,7 +58,7 @@ mode := 1
brightness := 0 brightness := 0
cmd = `%%brightness% ; % is the set brightness mode command. ` is the escape character cmd = `%%brightness% ; % is the set brightness mode command. ` is the escape character
TrayTip, , Brightness: %brightness% TrayTip, , Brightness: %brightness%
socket.Send(cmd) sendCmd(cmd)
; MsgBox %cmd% ; MsgBox %cmd%
return return
@ -67,7 +68,7 @@ mode := 1
brightness := maxColor brightness := maxColor
cmd = `%%brightness% ; % is the set brightness mode command cmd = `%%brightness% ; % is the set brightness mode command
TrayTip, , Brightness: %brightness% TrayTip, , Brightness: %brightness%
socket.Send(cmd) sendCmd(cmd)
; MsgBox %cmd% ; MsgBox %cmd%
return return
@ -77,7 +78,7 @@ mode := 1
speed := 0 speed := 0
cmd = ?%speed% ; ? is the set brightness mode command cmd = ?%speed% ; ? is the set brightness mode command
TrayTip, , Speed: %speed% TrayTip, , Speed: %speed%
socket.Send(cmd) sendCmd(cmd)
; MsgBox %cmd% ; MsgBox %cmd%
return return
@ -87,7 +88,7 @@ mode := 1
speed := maxColor speed := maxColor
cmd = ?%speed% ; ? is the set brightness mode command cmd = ?%speed% ; ? is the set brightness mode command
TrayTip, , Speed: %speed% TrayTip, , Speed: %speed%
socket.Send(cmd) sendCmd(cmd)
; MsgBox %cmd% ; MsgBox %cmd%
return return
@ -100,7 +101,7 @@ mode := 1
cmd := "#"+toHexColor(red,green,blue) ; # is the set main color command cmd := "#"+toHexColor(red,green,blue) ; # is the set main color command
; MsgBox %cmd% ; MsgBox %cmd%
TrayTip, , Red: %red% TrayTip, , Red: %red%
socket.Send(cmd) sendCmd(cmd)
return return
@ -112,7 +113,7 @@ mode := 1
cmd := "#"+toHexColor(red,green,blue) ; # is the set main color command cmd := "#"+toHexColor(red,green,blue) ; # is the set main color command
; MsgBox %cmd% ; MsgBox %cmd%
TrayTip, , Red: %red% TrayTip, , Red: %red%
socket.Send(cmd) sendCmd(cmd)
return return
@ -124,7 +125,7 @@ mode := 1
cmd := "#"+toHexColor(red,green,blue) ; # is the set main color command cmd := "#"+toHexColor(red,green,blue) ; # is the set main color command
; MsgBox %cmd% ; MsgBox %cmd%
TrayTip, , Green: %green% TrayTip, , Green: %green%
socket.Send(cmd) sendCmd(cmd)
return return
@ -136,7 +137,7 @@ mode := 1
cmd := "#"+toHexColor(red,green,blue) ; # is the set main color command cmd := "#"+toHexColor(red,green,blue) ; # is the set main color command
; MsgBox %cmd% ; MsgBox %cmd%
TrayTip, , Green: %green% TrayTip, , Green: %green%
socket.Send(cmd) sendCmd(cmd)
return return
@ -148,7 +149,7 @@ mode := 1
cmd := "#"+toHexColor(red,green,blue) ; # is the set main color command cmd := "#"+toHexColor(red,green,blue) ; # is the set main color command
; MsgBox %cmd% ; MsgBox %cmd%
TrayTip, , Blue: %blue% TrayTip, , Blue: %blue%
socket.Send(cmd) sendCmd(cmd)
return return
@ -160,10 +161,24 @@ mode := 1
cmd := "#"+toHexColor(red,green,blue) ; # is the set main color command cmd := "#"+toHexColor(red,green,blue) ; # is the set main color command
; MsgBox %cmd% ; MsgBox %cmd%
TrayTip, , Blue: %blue% TrayTip, , Blue: %blue%
socket.Send(cmd) sendCmd(cmd)
return return
sendCmd(cmd)
{
global connected
global socket
; MsgBox %connected%
if( connected )
{
socket.Send(cmd)
; MsgBox %cmd%
}
else
TrayTip, , Not connected to server!
}
toHexColor(r, g, b) toHexColor(r, g, b)
{ {
SetFormat, IntegerFast, hex ; To print values as hexadecimal SetFormat, IntegerFast, hex ; To print values as hexadecimal
@ -183,6 +198,7 @@ class Example extends WebSocket
TrayTip, ,Connection established to led controller! TrayTip, ,Connection established to led controller!
; InputBox, Data, WebSocket, Enter some text to send through the websocket. ; InputBox, Data, WebSocket, Enter some text to send through the websocket.
; this.Send(Data) ; this.Send(Data)
global connected := 1
} }
OnMessage(Event) OnMessage(Event)
@ -194,6 +210,7 @@ class Example extends WebSocket
OnClose(Event) OnClose(Event)
{ {
TrayTip, , Websocket Closed TrayTip, , Websocket Closed
global connected := 0
this.Disconnect() this.Disconnect()
ExitApp ExitApp
} }
@ -201,6 +218,7 @@ class Example extends WebSocket
OnError(Event) OnError(Event)
{ {
TrayTip, , Websocket Error TrayTip, , Websocket Error
global connected := 0
this.Close() this.Close()
} }