14.03.2016, 12:34
Here is the script (predefined-scene) for operating DMX objects on 3 x RS-485 interfaces of LogicMachine4. Add resident script, sleep time = 0.
Big steps are defined as VALUES. RESOLUTION is a count of small steps between big steps - defines how smooth one color transits into other. STEPDELAY defines what is delay between each small step.
Approximate time:
BIG STEP TIME = RESOLUTION * (STEPDELAY + 0.1)
Big steps are defined as VALUES. RESOLUTION is a count of small steps between big steps - defines how smooth one color transits into other. STEPDELAY defines what is delay between each small step.
Approximate time:
BIG STEP TIME = RESOLUTION * (STEPDELAY + 0.1)
Code:
if not values then
luadmx = require('luadmx')
-- channel values for each second for each output port
values = {
-- second 1
{
-- port 1
{ 0, 127, 255 },
-- port 2
{ 255, 255, 0 },
-- port 3
{ 255, 0, 0 },
},
-- second 2
{
-- port 1
{ 255, 255, 0 },
-- port 2
{ 0, 127, 255 },
-- port 3
{ 255, 0, 255 },
},
-- second 3
{
-- port 1
{ 0, 127, 255 },
-- port 2
{ 255, 0, 0 },
-- port 3
{ 255, 255, 127 },
},
}
-- number of step, must be tuned manually
resolution = 10
-- sleep between steps, must be tuned manually
stepdelay = 0.05
-- list of ports to use
ports = {
'/dev/RS485-1',
'/dev/RS485-2',
'/dev/RS485-3',
}
function init(port, count)
local ctx, err = {}
-- init dmx
ctx.dm, err = luadmx.open(port)
if not ctx.dm then
error('Port ' .. tostring(port) .. ' error: ' .. tostring(err))
end
-- channel count
ctx.count = count
ctx.dm:setcount(count)
-- reset channel map
ctx.values = {}
ctx.deltas = {}
-- fill channel map
for chan = 1, count do
ctx.values[ chan ] = 0
ctx.dm:setchannel(chan, 0)
end
ctx.dm:send()
return ctx
end
function set(ctx, values, resolution)
local value, delta
-- check for new values for each channel
for chan = 1, ctx.count do
value = values[ chan ] or 0
ctx.deltas[ chan ] = (value - ctx.values[ chan ]) / resolution
ctx.values[ chan ] = value
end
ctx.ticks = resolution
end
function step(ctx)
local ticks = ctx.ticks - 1
-- transition for each channel
for chan = 1, ctx.count do
local delta = ctx.deltas[ chan ]
if delta ~= 0 then
local value = ctx.values[ chan ] - ctx.deltas[ chan ] * ticks
ctx.dm:setchannel(chan, value)
end
end
ctx.dm:send()
ctx.ticks = ticks
end
ctxlist = {}
for i, port in ipairs(ports) do
ctxlist[ i ] = init(port, #values[ 1 ][ i ])
end
end
for sec, secvalues in ipairs(values) do
for id, ctx in ipairs(ctxlist) do
set(ctx, secvalues[ id ] or {}, resolution)
end
for i = 1, resolution do
for id, ctx in ipairs(ctxlist) do
step(ctx)
end
os.sleep(stepdelay)
end
end