Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local IECNET = true
- -- end of config
- local args = {...}
- --IECNET setup
- local gpsEnabled = false
- local net = "IECNET"
- local host = 0
- function iecnetSetup()
- if (IECNET) then
- if (peripheral.isPresent("back")) then
- if (peripheral.getType("back") == "modem") then
- --peripheral is present, starting IECNET
- rednet.open("back")
- host = rednet.lookup(net,"IEC-Host")
- if (host == nil) then
- term.write("IECNET does not have a Host or Host is Offline, broadcasts will go unheard.")
- IECNET = false
- end
- x,y,z = gps.locate()
- if (x == nil) then
- term.write("GPS not available, will not send Location Data")
- else
- gpsEnabled = true;
- end
- rednet.broadcast("Online",net)
- else
- term.write("IECNET was enabled, but no modem was found.")
- IECNET = false
- end
- else
- term.write("IECNET was enabled, but no modem was found.")
- IECNET = false
- end
- end
- end
- function getLocation()
- x,y,z = gps.locate()
- if (x == nil) then
- gpsEnabled = false
- return nil
- else
- if (not gpsEnabled) then
- gpsEnabled = true
- end
- x = floor(x+0.5)
- y = floor(y+0.5)
- z = floor(z+0.5)
- return tostring(x).." "..tostring(y).." "..tostring(z)
- end
- end
- function nextLine()
- x,y = term.getCursorPos()
- term.setCursorPos(1,y+1)
- end
- function head()
- term.setCursorPos(1,1)
- x,y = term.getSize()
- term.write("+")
- for i=1,(x-13)/2,1 do
- term.write("-")
- end
- term.write("[")
- term.setTextColor(colors.yellow)
- term.write("IEC-OS.aic")
- term.setTextColor(colors.white)
- term.write("]")
- for i=1,(x-13)/2,1 do
- term.write("-")
- end
- term.write("+")
- end
- function foot()
- x,y = term.getSize()
- term.setCursorPos(1,y)
- term.write("+")
- for i=1,1,1 do
- term.write("-")
- end
- term.write("[")
- term.setTextColor(colors.yellow)
- term.write("Home")
- term.setTextColor(colors.white)
- term.write("]")
- if (IECNET) then
- for i=1,x-(8+11),1 do
- term.write("-")
- end
- term.write("[")
- term.setTextColor(colors.green)
- term.write("Online")
- term.setTextColor(colors.white)
- term.write("]--+")
- else
- for i=1,x-(8+11),1 do
- term.write("-")
- end
- term.write("[")
- term.setTextColor(colors.red)
- term.write("Offline")
- term.setTextColor(colors.white)
- term.write("]-+")
- end
- end
- function functionals()
- term.clear()
- head()
- foot()
- term.setCursorPos(1,2)
- end
- function startAnimation()
- --TODO
- end
- function divider()
- x,y = term.getSize()
- term.write("+")
- for i=1,(x-2),1 do
- term.write("-")
- end
- term.write("+")
- end
- function screenHead(label)
- x,y = term.getSize()
- term.write("+-["..label.."]")
- length = 4+ string.len(label)+1
- for i=1,(x-length),1 do
- term.write("-")
- end
- term.write("+")
- nextLine()
- end
- local buttons = {}
- --creates and registers a button
- function button(label,text)
- screenHead(label)
- x,y = term.getSize()
- term.write("|")
- term.write(text)
- length = 2+ string.len(text)
- for i=1, (x-length),1 do
- term.write(" ")
- end
- term.write("|")
- x,y = term.getCursorPos()
- buttons[y] = label
- nextLine()
- end
- local SCREEN = "Home"
- --touch handeling
- function touchHandeling(button,x,y)
- xMax,yMax = term.getSize()
- if ((y == yMax) and (x > 2) and (x < 8)) then
- --Home button was pressed
- SCREEN = "Home"
- return
- end
- if (SCREEN == "Home") then
- if (x > 1 and x < xMax) then
- change = buttons[y]
- if (not (change == nil)) then
- SCREEN = change
- if (change == "Turtles") then
- functionals()
- screenHead(SCREEN)
- end
- end
- end
- end
- end
- --rednet handeling
- local ticksSinceLastPing = 0
- function rednetHandeling(sender,message,prot)
- if (message == "pong" and prot == net) then --online checker
- ticksSinceLastPing = 0
- return
- end
- if (SCREEN == "Turtles") then
- if (type(message) == "table" and prot == net) then
- functionals()
- screenHead(SCREEN)
- --what has been sent is a table
- for i,line in pairs(message) do
- screenHead("Turtle: "..i)
- term.write(line)
- nextLine()
- end
- end
- divider()
- end
- end
- function routine()
- functionals()
- if (SCREEN == "Home") then
- button("Turtles","View Turtle Status")
- elseif (SCREEN == "Turtles") then
- rednet.broadcast("Turtlenet querry",net)
- else
- functionals()
- screenHead("No SCREEN")
- end
- if (ticksSinceLastPing > 5) then
- IECNET = false
- else
- IECNET = true
- end
- rednet.broadcast("ping",net) --ping the network to see if it is online
- end
- --actual code
- iecnetSetup()
- functionals()
- local timer = os.startTimer(1)
- while true do
- event,a1,a2,a3 = os.pullEvent()
- if (event == "timer" and a1 == timer) then
- ticksSinceLastPing = ticksSinceLastPing +1
- routine()
- timer = os.startTimer(1)
- elseif (event == "mouse_click") then
- touchHandeling(a1,a2,a3)
- elseif (event == "rednet_message") then
- rednetHandeling(a1,a2,a3)
- end
- end
Add Comment
Please, Sign In to add comment