Skip to content

Instantly share code, notes, and snippets.

@Forecaster
Created June 12, 2016 17:21
local c = require("component")
local event = require("event")
local args = {...}
local command = args[1]
local function printResponse(e, _, _, _, _, header, command, ...)
print("Captured event " .. e .. " header " .. header)
if header == "nanomachines" then
for _, v in ipairs({...}) do
print(v)
end
end
-- else
-- print("Caught event " .. e)
-- end
return
end
c.modem.open(1)
event.listen("modem_message", printResponse)
if args[2] ~= nil then
local arg1 = args[1]
if args[3] ~= nil then
local arg2 = args[2]
end
end
--c.modem.broadcast(1,"nanomachines","setResponsePort", 2)
if arg1 and arg2 then
c.modem.broadcast(1,"nanomachines", command, arg1, arg2)
print("Send command " .. command .. " with 2 args")
else
if arg1 then
c.modem.broadcast(1,"nanomachines", command, arg1)
print("Send command " .. command .. " with 1 arg")
else
c.modem.broadcast(1,"nanomachines", command)
print("Send command " .. command)
end
end
local run = true
while run do
local evnt = event.pull(1, "interrupted")
if evnt then
print("Program was interrupted")
return
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment