-- -- lua function to turn off/on SF SD Logs -- -- -- variables for demo -- local lastActive = 0 -- for demo: toggles SD Logs on/off every 5s local interval = 500 local enable = 0 -- -- internal variables for SF SD Logs enable/disable function -- local nSF = 64 -- 64 SFs to consider local logsSFIndex = nil -- index of SF SD Logs local logsTable = nil -- copy of SF SD Logs data local period = 10 -- default log period 10*100ms = 1.0s -- init function local function init() -- init fuction for SD Logs enable/disable function local function initSDLogEnable() -- initializes the SF SD Logs enable/disable function local createSF = false for i = 0, nSF-1 do -- go through all SFs local cf = model.getCustomFunction(i) -- get SF at index i if cf ~= nil then if cf.func == FUNC_LOGS then -- check if SF is SF SD Logs logsTable = cf -- copy entry logsSFIndex = i -- memorize index createSF = false -- no need to create SF break -- exit search loop end if logsSFIndex == nil and -- search for first free index cf.switch == 0 then logsSFIndex = i -- memorize index createSF = true -- need to create the SF end end end if createSF == true then logsTable = { ["switch"] = getSwitchIndex('ON'), -- trigger permanently ON ["func"] = FUNC_LOGS, -- SD Logs ["value"] = period, -- 1.0s ["active"] = 0 -- disabled } end end -- main init function initSDLogEnable() -- Initialize the SF SD Logs enable/disable function end -- run function local function run() local function SDLogsEnable(enable) -- function to enable/disable SD Logs if logsTable ~= nil then logsTable.active = enable -- enable/disable SD Logs SF model.setCustomFunction(logsSFIndex, logsTable) end end -- demo function to toggle disabled/enabled status local function demoSDLogsOnOff() local now = getTime() if now >= (lastActive + interval) then lastActive = now if enable == 0 then enable = 1 else enable = 0 end SDLogsEnable(enable) end end -- main run function demoSDLogsOnOff() end return { init = init, run = run }