You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

62 lines
1.7 KiB

dofile("list.lua")
info = {r=0, g=170, b=255, iterations=3, effect='chase'}
warn = {r=255, g=128, b=0, iterations=5, effect='round'}
err = {r=255, g=0, b=50, iterations=5, effect='strobe'}
misc = {r=0, g=128, b=50,iterations=3, effect='strobe'}
stby = {r=0, g=0, b=0, iterations=1, effect='rainbow'}
rotation = 0
percentage = 0
messages = List.new()
function csplit(str,sep)
local ret={}
local n=1
for w in str:gmatch("([^"..sep.."]*)") do
ret[n] = ret[n] or w -- only set once (so the blank after a string is ignored)
if w=="" then
n = n + 1
end -- step forwards on a blank but not a string
end
return ret
end
function recieveC3VOC(data)
local j = sjson.decode(data)
print(j['msg'])
print(string.match(j['msg'], "Overall Progress"))
if (string.match(j['msg'], "Overall Progress") ) then
local s = csplit(j['msg'], ' ')
print(s[1])
percentage = math.floor(s[#s]:sub(1, -2))
print(percentage)
stby['iterations'] = percentage
end
if not string.match(j['component'], "encoder42") and not string.match(j['component'], "tallycom") and not string.match(j['component'], "fusion") then
if ((j['level'] == 'info') or (j['level'] == 'INFO')) then
List.pushright(messages, info)
elseif ((j['level'] == 'warn') or (j['level'] == 'WARN')) then
List.pushright(messages, warn)
elseif ((j['level'] == 'error') or (j['level'] == 'ERROR')) then
List.pushright(messages, err)
end
end
end
function recieveDirect(data)
List.pushright(messages, data)
end
local t = tmr.create()
t:register(2000, tmr.ALARM_AUTO, function()
rotation = rotation + 1
if pcall(function() data = List.popleft(messages) end) then
activateLight(data)
print("activate event fired")
else
stby['r']=rotation
activateLight(stby)
end
end)
t:start()