143
-- set channel count
self.dm:setcount(self.params.channels)
-- number of transaction ticks
self.ticks = math.max(1, self.params.transition * self.params.resolution)
-- calculate sleep time
self.sleep = 1 / self.params.resolution
-- reset channel map
self.channels = {}
-- fill channel map
for chan = 1, self.params.channels do
self.channels[ chan ] = { current = 0, target = 0, ticks = 0 }
-- turn off by default
storage.set(self.params.skey .. chan, 0)
self.dm:setchannel(chan, 0)
end
end
-- get new values
function DMX:getvalues()
local chan, val
-- check for new values for each channel
for chan = 1, self.params.channels do
val = storage.get(self.params.skey .. chan)
-- target value differs, set transcation
if val ~= self.channels[ chan ].target then
self.channels[ chan ].target = val
self.channels[ chan ].delta = (self.channels[ chan ].target - self.channels[ chan ].current) / self.ticks
self.channels[ chan ].ticks = self.ticks
end
end
end
-- main loop handler
function DMX:run()
local i, bs, bm, as, am, delta
local res = self.params.resolution
if not self.calibrated then
bs, bm = os.microtime()
end
self:getvalues()
-- transition loop
for i = 1, res do
self:step()
self.dm:send()
-- wait until next step
os.sleep(self.sleep)
end
-- calibrate delay loop to match 1 second
if not self.calibrated then
as, am = os.microtime()
delta = (as - bs) + (am - bm) / 1000000
if delta > 1.05 then
self.sleep = self.sleep - math.max(10, self.sleep / res)
else
self.calibrated = true
end
end
end
-- single transition step
function DMX:step()
local chan, t
-- transition for each channel
for chan = 1, self.params.channels do
t = self.channels[ chan ].ticks
-- transition is active
if t > 0 then
t = t - 1
self.channels[ chan ].current = self.channels[ chan ].target - self.channels[ chan ].delta * t
self.channels[ chan ].ticks = t
self.dm:setchannel(chan, self.channels[ chan ].current)
end
end
end
DMX handler programs
DMX handler should be placed inside a resident script. Sleep time interval must be set to 0.
Содержание LogicMachine3 Re:actor
Страница 10: ...10 Terminal connection schemes KNX TP...
Страница 12: ...12 24V power supply...
Страница 13: ...13 Analog inputs e g reed contact...
Страница 14: ...14 Analog inputs 0 10V...
Страница 15: ...15 Digital output...
Страница 16: ...16 Resistive sensor input...
Страница 17: ...17 Analog output...
Страница 26: ...26 Make sure that bus status is Online press button in ETS...
Страница 35: ...35 o Then minimize side bar by pressing on left arrow icon to make the map more visible...
Страница 83: ...83 66 if err then 67 alert FTP upload failed s err 68 end...
Страница 107: ...107...
Страница 108: ...108 1 14 Help Documentation for scripting syntaxes is displayed in Help tab...
Страница 122: ...122 4 16 Running processes System running processes can be seen in Status Running processes window...
Страница 126: ...126 Datapoints can be shown also in a way of table which can be later exported as CSV file...
Страница 141: ...141...