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
|
|
|
|
|
|
|
|
wlan.open(9999)
|
|
|
|
|
|
|
|
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 21:20:28 +03:00
|
|
|
if not repeating then
|
|
|
|
if keycode == keys.up then
|
|
|
|
wlan.transmit(9999, 9999, { _ = "move", dir = "fwd", dig = keyStates[keys.leftShift] })
|
|
|
|
elseif keycode == keys.down then
|
|
|
|
wlan.transmit(9999, 9999, { _ = "move", dir = "bck" })
|
|
|
|
elseif keycode == keys.left then
|
|
|
|
wlan.transmit(9999, 9999, { _ = "move", dir = "rotl" })
|
|
|
|
elseif keycode == keys.right then
|
|
|
|
wlan.transmit(9999, 9999, { _ = "move", dir = "rotr" })
|
|
|
|
elseif keycode == keys.pageUp then
|
|
|
|
wlan.transmit(9999, 9999, { _ = "move", dir = "up", dig = keyStates[keys.leftShift] })
|
|
|
|
elseif keycode == keys.pageDown then
|
|
|
|
wlan.transmit(9999, 9999, { _ = "move", dir = "down", dig = keyStates[keys.leftShift] })
|
|
|
|
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")
|
|
|
|
if chan == 9999 and rchan == chan then
|
|
|
|
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
|
|
|
|
)
|