Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local args = { ... }
- os.loadAPI("vislib")
- if #args < 1 then error("expected at least one argument") end
- local screenName = args[1]
- local monitors = {}
- local xMax = 0
- local yMax = 0
- local xPixMax = 0
- local yPixMax = 0
- function rearangeMonitors()
- local rows = {}
- local cols = {}
- for i, m in ipairs(monitors) do
- if rows[m.cX] == nil or m.w > rows[m.cX] then
- rows[m.cX] = m.w
- end
- if cols[m.cY] == nil or m.h > cols[m.cY] then
- cols[m.cY] = m.h
- end
- end
- local w = 0
- local h = 0
- local xCords = {}
- local yCords = {}
- for x = 1, xMax do
- xCords[x] = w
- if rows[x] ~= nil then
- w = w + rows[x] + 4
- end
- end
- for y = 1, yMax do
- yCords[y] = h
- if cols[y] ~= nil then
- h = h + cols[y] + 4
- end
- end
- xPixMax = w - 4
- yPixMax = h - 4
- for i, m in ipairs(monitors) do
- vislib.sendRednet(m.id, "@mon:" .. screenName .. ",setPos," .. xCords[m.cX] .. "," .. yCords[m.cY])
- end
- end
- rednet.open("top")
- vislib.broadcast("@mon:" .. screenName .. ",sendData")
- while true do
- local id, msg = vislib.receiveRednet()
- local tag, pts = vislib.getMsgData(msg)
- if tag == "@monman" and pts[1] == screenName then
- if pts[2] == "init" then
- monitors = {}
- xMax = 0
- yMax = 0
- print("init")
- vislib.broadcast("@mon:" .. screenName .. ",sendData")
- elseif pts[2] == "monData" then
- print("monData:", msg)
- local label = pts[3]
- local screenCX = tonumber(pts[4])
- local screenCY = tonumber(pts[5])
- local w = tonumber(pts[6])
- local h = tonumber(pts[7])
- if screenCX > xMax then xMax = screenCX end
- if screenCY > yMax then yMax = screenCY end
- table.insert(monitors, {
- id = id,
- label = label,
- cX = screenCX,
- cY = screenCY,
- w = w,
- h = h
- })
- rearangeMonitors()
- elseif pts[2] == "reboot" then
- print("reboot")
- vislib.broadcast("@mon:" .. screenName .. ",reboot")
- sleep(3)
- os.reboot()
- elseif pts[2] == "get" then
- if pts[3] == "ping" then
- vislib.sendRednet(id, "@monAnsw:pong")
- elseif pts[3] == "size" then
- vislib.sendRednet(id, "@monAnsw:" .. xPixMax .. "," .. yPixMax)
- end
- else print("unknown message: " .. msg)
- end
- end
- end
- --pastebin run 0YB9PsQV startup={files={vislib=<pb:GYvMFCY5>,monman=<pb:R7pDQu5D>},cmds={{'monman',<input:'name'>}}} label=<input:'Label'> reboot=true
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement