-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapicontroller.lua
59 lines (46 loc) · 1.21 KB
/
apicontroller.lua
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
lights = require("lights")
local apicontroller = {}
apicontroller.on = function (res)
lights.SetColor(255, 0, 244, 0)
res:finish("OK")
end
apicontroller.effect = function(res, effect)
lights.Effect(effect)
res:finish("OK")
end
apicontroller.off = function (res)
lights.SetColor(0, 0, 0, 0)
res:finish("OK")
end
apicontroller.set = function(res, color)
print(color)
-- split the color in its components
if(color:len() ~= 8) then
res:finish("invalid color. format: 0xRRGGBBWW", 400)
return
end
if(not pcall(function()tonumber(color, 16)end)) then
res:finish("invalid color. format: 0xRRGGBBWW", 400)
return
end
r = tonumber(color:sub(1,2), 16)
g = tonumber(color:sub(2,4), 16)
b = tonumber(color:sub(4,6), 16)
w = tonumber(color:sub(6,8), 16)
lights.SetColor(r,g,b,w)
res:finish("OK")
end
apicontroller.whiteness = function(res, whiteness)
if(not pcall(function()tonumber(whiteness)end)) then
res:finish("invalid whiteness. number 0-100", 400)
return
end
w = math.floor(255 * whiteness / 100)
if(w > 255 or w < 0)then
res:finish("invalid whiteness. number 0-100", 400)
return
end
lights.SetWhiteness(w)
res:finish("OK")
end
return apicontroller