This repository has been archived by the owner on Dec 11, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
0.lua
executable file
·64 lines (62 loc) · 2.09 KB
/
0.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
60
61
62
63
64
-- Set Command
ledconvtmr = ledconvtmr and ledconvtmr or tmr.create()
setValue = function(index, value)
if index >= 40 then
print("Cannot modify value "..tostring(index).."(immutable)")
return false
end
if (index == 0) then
-- LED
assert(#value % 3 == 0, "Cannot set LED Value. Data Length is not a multiple of 3")
local i = 1
local ledval = ""
ledconvtmr:alarm(5, tmr.ALARM_AUTO, function ()
if i < #value then
local h, s, v = extract_hsv(value:sub(i, i+2))
ledval = ledval..convertToLedString(h, s, v)
i = i + 3
else
ledstate.led = ledval
ledstate.ledhsv = value
ledconvtmr:stop()
end
end)
elseif index == 1 then
-- Power
local firstbyte = string.byte(value)
if firstbyte == 0 then
ledstate.power = false
elseif firstbyte == 1 then
ledstate.power = true
elseif firstbyte == 0xFF then
ledstate.power = not ledstate.power
end
print("Setting power to "..tostring(ledstate.power))
elseif index == 2 then
--Mode
ledstate.mode = string.byte(value)
print("Setting mode to "..ledstate.mode)
elseif index == 3 then
--Speed
local speed = 0
--Add each bit so numbers about 255 are possible
for i = 1, #value do
speed = bit.lshift(speed, 8)
speed = bit.bor(speed, value:sub(i,i))
end
--Cap at timer maximum(1:54:30)
ledstate.speed = speed <= 13741 and speed or 13741
print("Setting speed to "..ledstate.speed)
elseif index == 39 then
--state, ignore lednum
setValue(1, value:sub(2,2))
setValue(2, value:sub(3,3))
setValue(3, value:sub(4, 5))
setValue(0, value:sub(6, -1))
end
end
return function(args, data)
setValue(args, data)
ledstate() --Save and Apply
return true --Indicate that we wish to notify config.net.notifyIP of the changes that were made
end