Massively improve functionality
flag now runs off a RasPi with its own API. Response time is faster than the windows desktop app
This commit is contained in:
parent
dd4b8fd4df
commit
2047191848
185
flag.ahk
185
flag.ahk
@ -1,179 +1,10 @@
|
||||
#SingleInstance force ; Only one instance at a time
|
||||
FileEncoding, UTF-8 ; Makes sure special characters dont break stuff
|
||||
|
||||
|
||||
global userID := "user ID from control software"
|
||||
|
||||
|
||||
If (A_Args.Length() < 3)
|
||||
If !(A_Args[1])
|
||||
{
|
||||
If (A_Args[1] = "off")
|
||||
{
|
||||
off()
|
||||
} Else {
|
||||
MsgBox,, Flag, Not enough parameters passed to script
|
||||
}
|
||||
ExitApp
|
||||
Exit
|
||||
}
|
||||
|
||||
Switch A_Args[3]
|
||||
{
|
||||
Case A_Args[3] is number:
|
||||
length := A_Args[3]
|
||||
Case "hold":
|
||||
length := 100000
|
||||
Default:
|
||||
length := 0
|
||||
}
|
||||
|
||||
Switch A_Args[1]
|
||||
{
|
||||
Case "s":
|
||||
solid(A_Args[2], length)
|
||||
Case "b":
|
||||
blink(A_Args[2], length)
|
||||
Case "p":
|
||||
patt(A_Args[2], length)
|
||||
Default:
|
||||
MsgBox,, Flag, % "Incorrect parameters passed to script: " A_Args[1] ", " A_Args[2] ", " length
|
||||
}
|
||||
|
||||
|
||||
solid(input, length)
|
||||
{
|
||||
Switch input
|
||||
{
|
||||
Case "red", "green", "yellow", "blue", "white", "cyan", "magenta":
|
||||
json_str =
|
||||
(
|
||||
{
|
||||
"userId": "%userID%",
|
||||
"actionFields":{
|
||||
"color": "%input%"
|
||||
}
|
||||
}
|
||||
)
|
||||
Default:
|
||||
json_str =
|
||||
(
|
||||
{
|
||||
"userId": "%userID%",
|
||||
"actionFields":{
|
||||
"color": "custom",
|
||||
"custom_color": "%input%"
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
translate("https://api.luxafor.com/webhook/v1/actions/solid_color", json_str, length)
|
||||
}
|
||||
|
||||
blink(input, length)
|
||||
{
|
||||
Switch input
|
||||
{
|
||||
Case "red", "green", "yellow", "blue", "white", "cyan", "magenta":
|
||||
color := input
|
||||
Default:
|
||||
MsgBox % input " is not an accepted input"
|
||||
ExitApp
|
||||
}
|
||||
json_str =
|
||||
(
|
||||
{
|
||||
"userId": "%userID%",
|
||||
"actionFields":{
|
||||
"color": "%color%"
|
||||
}
|
||||
}
|
||||
)
|
||||
translate("https://api.luxafor.com/webhook/v1/actions/blink", json_str, length)
|
||||
}
|
||||
|
||||
patt(input, length)
|
||||
{
|
||||
Switch input
|
||||
{
|
||||
Case "police", "rainbow", "sea", "synthetic":
|
||||
pattern := input
|
||||
Case "traffic_lights":
|
||||
pattern := "traffic lights"
|
||||
Case "white_wave":
|
||||
pattern := "white wave"
|
||||
Case "random":
|
||||
Random, rando, 1, 5
|
||||
pattern := "random %rando%"
|
||||
Case "random1":
|
||||
pattern := "random 1"
|
||||
Case "random2":
|
||||
pattern := "random 2"
|
||||
Case "random3":
|
||||
pattern := "random 3"
|
||||
Case "random4":
|
||||
pattern := "random 4"
|
||||
Case "random5":
|
||||
pattern := "random 5"
|
||||
Default:
|
||||
MsgBox % input " is not an accepted input"
|
||||
ExitApp
|
||||
}
|
||||
json_str =
|
||||
(
|
||||
{
|
||||
"userId": "%userID%",
|
||||
"actionFields":{
|
||||
"pattern": "%pattern%"
|
||||
}
|
||||
}
|
||||
)
|
||||
translate("https://api.luxafor.com/webhook/v1/actions/pattern", json_str, length)
|
||||
}
|
||||
|
||||
translate(url, data, length)
|
||||
{
|
||||
If (length = 0)
|
||||
{
|
||||
req(url, data)
|
||||
} Else {
|
||||
start_time := A_TickCount
|
||||
time_to_run := length * 1000
|
||||
end_time := start_time + time_to_run
|
||||
while (A_tickcount < end_time) {
|
||||
req(url, data)
|
||||
}
|
||||
}
|
||||
|
||||
If (InStr(url, "solid"))
|
||||
{
|
||||
Sleep, (length * 1000)
|
||||
off()
|
||||
}
|
||||
}
|
||||
|
||||
off()
|
||||
{
|
||||
data =
|
||||
(
|
||||
{
|
||||
"userId": "%userID%",
|
||||
"actionFields":{
|
||||
"color": "custom",
|
||||
"custom_color": "000000"
|
||||
}
|
||||
}
|
||||
)
|
||||
url := "https://api.luxafor.com/webhook/v1/actions/solid_color"
|
||||
req(url, data)
|
||||
}
|
||||
|
||||
req(url, data)
|
||||
{
|
||||
whr := ComObjCreate("WinHttp.WinHttpRequest.5.1")
|
||||
whr.Open("POST", url, false)
|
||||
whr.SetRequestHeader("Content-Type", "application/json")
|
||||
whr.Send(data)
|
||||
whr.WaitForResponse()
|
||||
}
|
||||
|
||||
|
||||
ExitApp
|
||||
msg := "http://RasPi.daily:8888/lights/" . A_Args[1]
|
||||
req := ComObjCreate("WinHttp.WinHttpRequest.5.1")
|
||||
req.Open("GET", msg, True)
|
||||
req.Send()
|
||||
Sleep, 50 ; make sure the request actually gets sent before we exit
|
||||
Exit
|
Loading…
Reference in New Issue
Block a user