event_loop.lua

local logger = require("modules/logger")

otii.clear()

local debuglog = logger.get_logger()
debuglog.enable(false)

-- Open active project if exists,
-- otherwise create a new project.
local project = otii.get_active_project()
if not project then
    project = otii.create_project()
    assert(project, "cannot create project")
end

-- Open first available Otii device.
local devices = otii.get_devices("Arc")
assert(#devices > 0, "No available devices")
local box = otii.open_device(devices[1].id)
assert(box, "Cannot open device")
box:enable_channel("mc", true)

-- Create a local server, providing the event
-- handler as the 2nd argument.
local server = otii.create_local_server("com.qoitech.otiicli", function(data)
    otii.writeln(data)
    if data == "start" then
        project:start()
        debuglog.log("Started")
    elseif data == "stop" then
        project:stop()
        debuglog.log("Stopped")
    elseif data == "on" then
        project:enable_main_power(true)
        debuglog.log("Enable main power")
    elseif data == "off" then
        project:enable_main_power(false)
        debuglog.log("Disable main power")
    elseif data == "debug" then
        debuglog.enable(true)
    elseif data == "exit" then
        otii.stop(0)
    else
        otii.writeln("Unknown command!")
    end
end)

-- Create a timer that will stop the program
-- after 60 seconds.
local count = 60
local timer = otii.create_timer(1000, function()
    otii.writeln("Timer " .. tostring(count))
    count = count - 1
    if count == 0 then
        otii.stop(0)
    end
end)

-- Enter the event loop.
otii.run()

-- Clean up.
timer:delete()
server:close()
project:close()
generated by LDoc 1.4.6 Last updated 2021-10-13 21:46:39