2024-01-12 21:15:52 +03:00
|
|
|
local wlan = peripheral.find("modem", function(addr, modem)
|
|
|
|
return modem.isWireless()
|
|
|
|
end)
|
|
|
|
|
|
|
|
if not wlan then error("no wireless interface") end
|
|
|
|
|
2024-01-12 22:04:57 +03:00
|
|
|
wlan.open(9998)
|
2024-01-12 21:15:52 +03:00
|
|
|
|
|
|
|
local respondedTurtles = {}
|
|
|
|
local keyStates = {}
|
|
|
|
|
|
|
|
parallel.waitForAny(
|
|
|
|
function()
|
|
|
|
while true do
|
|
|
|
local ev, keycode, repeating = os.pullEvent()
|
|
|
|
if ev == "key" then keyStates[keycode] = true
|
|
|
|
elseif ev == "key_up" then keyStates[keycode] = false
|
|
|
|
end
|
|
|
|
|
2024-01-12 22:04:57 +03:00
|
|
|
if ev == "key" and not repeating then
|
2024-01-12 21:20:28 +03:00
|
|
|
if keycode == keys.up then
|
2024-01-12 22:04:57 +03:00
|
|
|
wlan.transmit(9999, 9998, { _ = "move", dir = "fwd", dig = keyStates[keys.leftShift] })
|
2024-01-12 21:20:28 +03:00
|
|
|
elseif keycode == keys.down then
|
2024-01-12 22:04:57 +03:00
|
|
|
wlan.transmit(9999, 9998, { _ = "move", dir = "bck" })
|
2024-01-12 21:20:28 +03:00
|
|
|
elseif keycode == keys.left then
|
2024-01-12 22:04:57 +03:00
|
|
|
wlan.transmit(9999, 9998, { _ = "move", dir = "rotl" })
|
2024-01-12 21:20:28 +03:00
|
|
|
elseif keycode == keys.right then
|
2024-01-12 22:04:57 +03:00
|
|
|
wlan.transmit(9999, 9998, { _ = "move", dir = "rotr" })
|
2024-01-12 21:20:28 +03:00
|
|
|
elseif keycode == keys.pageUp then
|
2024-01-12 22:04:57 +03:00
|
|
|
wlan.transmit(9999, 9998, { _ = "move", dir = "up", dig = keyStates[keys.leftShift] })
|
2024-01-12 21:20:28 +03:00
|
|
|
elseif keycode == keys.pageDown then
|
2024-01-12 22:04:57 +03:00
|
|
|
wlan.transmit(9999, 9998, { _ = "move", dir = "down", dig = keyStates[keys.leftShift] })
|
2024-01-12 21:20:28 +03:00
|
|
|
end
|
2024-01-12 21:15:52 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
|
|
|
|
function()
|
|
|
|
while true do
|
|
|
|
local _, side, chan, rchan, data, dist = os.pullEvent("modem_message")
|
2024-01-12 22:04:57 +03:00
|
|
|
if chan == 9998 and rchan == 9999 then
|
2024-01-12 21:15:52 +03:00
|
|
|
if data._ == "WakeUp" then
|
|
|
|
respondedTurtles[data.from] = { true, "Hello!" }
|
|
|
|
elseif data._ == "Ack" then
|
|
|
|
respondedTurtles[data.from] = { true, "Got it" }
|
|
|
|
elseif data._ == "Error" then
|
|
|
|
respondedTurtles[data.from] = { false, data.error }
|
|
|
|
elseif data._ == "Result" then
|
|
|
|
respondedTurtles[data.from] = { true, data.out}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
|
|
|
|
function()
|
|
|
|
while true do
|
|
|
|
os.pullEvent()
|
2024-01-12 21:20:57 +03:00
|
|
|
term.clear()
|
2024-01-12 21:22:37 +03:00
|
|
|
local i = 1
|
2024-01-12 21:15:52 +03:00
|
|
|
for id, res in pairs(respondedTurtles) do
|
2024-01-12 21:22:37 +03:00
|
|
|
term.setCursorPos(1, i)
|
2024-01-12 21:15:52 +03:00
|
|
|
term.write(string.format("%5d => ", id))
|
|
|
|
term.setTextColor(res[1] and colors.green or colors.red)
|
2024-01-12 21:22:37 +03:00
|
|
|
term.write(res[1] and "OK " or "ER ")
|
2024-01-12 21:15:52 +03:00
|
|
|
term.write(tostring(res[2]))
|
|
|
|
term.setTextColor(colors.white)
|
2024-01-12 21:22:37 +03:00
|
|
|
i = i + 1
|
2024-01-12 21:15:52 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
)
|