Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- os.loadAPI("ocs/apis/sensor")
- prox = sensor.wrap("top")
- trainWaitTime = 60
- lastTargets = nil
- function getTargets()
- lastTargets = prox.getTargets()
- return lastTargets
- end
- function getTimeout()
- sleep(2)
- return nil
- end
- --Prints Texts on monitors and sets trains free
- function monitorPainting()
- print("Monitorpainting wird gestartet....")
- local monitors = nil
- if os.getComputerLabel() == "Bahnhof1" then
- monitors = {peripheral.wrap( "monitor_0" ),peripheral.wrap( "monitor_1" ),peripheral.wrap( "monitor_2" ),peripheral.wrap( "monitor_6" )}
- elseif os.getComputerLabel() == "Bahnhof2" then
- monitors = {peripheral.wrap( "monitor_10" ), peripheral.wrap( "monitor_3" ),peripheral.wrap( "monitor_4" ),peripheral.wrap( "monitor_7" ),peripheral.wrap( "monitor_8" )}
- end
- local zugPlan = {}
- myApi.executeTableFunction(monitors, "setTextScale",0.7)
- while true do
- while lastTargets == nil do
- parallel.waitForAny(getTargets, getTimeout)
- end
- local targets = lastTargets
- count = 0
- for k, v in pairs( targets ) do
- count = count + 1
- end
- print(os.clock() .. ": " .. count .. " targets")
- myApi.executeTableFunction(monitors, "clear")
- myApi.executeTableFunction(monitors, "setTextColor", colors.white)
- myApi.executeTableFunction(monitors, "setCursorPos", 1, 1)
- myApi.executeTableFunction(monitors, "write", "Zug Gleis Ziel ETA Abfahrt")
- local zeile = 2
- local nextZug = ""
- for k, v in pairs( targets ) do
- print(os.clock() .. ": Got target: " .. k )
- local gleis = myApi.getGleisFromPosX(v["Position"])
- if string.find(k, "Locomotive") and (gleis ~= "?") then
- if zugPlan[k] == nil then
- zugPlan[k] = os.clock()
- end
- if os.clock()-zugPlan[k] > trainWaitTime then
- if nextZug == "" or (os.clock()-zugPlan[nextZug]) < (os.clock()-zugPlan[k]) then
- nextZug = k
- end
- end
- local ankunft = 0
- if zugPlan[k] ~= nil then
- ankunft = (trainWaitTime - (os.clock()-zugPlan[k]))
- if ankunft < 0 then
- ankunft = 0
- end
- end
- myApi.executeTableFunction(monitors, "setCursorPos", 1, zeile)
- local destination = myApi.fillMyString(v["RouteDestination"],6)
- ankunft = math.floor(ankunft)
- myApi.executeTableFunction(monitors, "write", destination .. " " .. gleis .. " Ölplattform 0min ".. ankunft .."sek" )
- if (trainWaitTime - (os.clock()-zugPlan[k])) < -1 then
- myApi.executeTableFunction(monitors, "setTextColor", colors.red)
- myApi.executeTableFunction(monitors, "write", " +" .. math.floor(math.abs(trainWaitTime - (os.clock()-zugPlan[k])) ) )
- myApi.executeTableFunction(monitors, "setTextColor", colors.white)
- end
- zeile = zeile + 1
- end
- end
- if nextZug ~= "" and colors.test(redstone.getBundledInput("bottom"), colors.lightGray) and (not colors.test(redstone.getBundledInput("bottom"), colors.red) ) then
- if myApi.getGleisFromPosX( targets[nextZug]["Position"] ) == 1 then
- redstone.setBundledOutput("bottom", colors.white)
- elseif myApi.getGleisFromPosX( targets[nextZug]["Position"] ) == 2 then
- redstone.setBundledOutput("bottom", colors.yellow)
- elseif myApi.getGleisFromPosX( targets[nextZug]["Position"] ) == 3 then
- redstone.setBundledOutput("bottom", colors.lime)
- elseif myApi.getGleisFromPosX( targets[nextZug]["Position"]) == 4 then
- redstone.setBundledOutput("bottom", colors.pink)
- elseif myApi.getGleisFromPosX( targets[nextZug]["Position"] ) == 5 then
- redstone.setBundledOutput("bottom", colors.cyan)
- end
- --myPrinter = peripheral.wrap( "printer_0" )
- --myPrinter.endPage()
- --ready = myPrinter.newPage()
- --myPrinter.setPageTitle("ZugLog Hauptbahnhof")
- --printerZeile = 1
- --printerZeile = printerZeile + 1
- --if printerZeile == 20 then
- --printerZeile = 1
- --myPrinter.setPageTitle("ZugLog Hauptbahnhof")
- --myPrinter.endPage()
- --ready = myPrinter.newPage()
- -- end
- local h = fs.open("disk/logfile", fs.exists("disk/logfile") and "a" or "w")
- uhrzeit = http.get("http://tankguru.me/extern/time.php?format=H:i:s")
- h.writeLine("Bye ".. targets[nextZug]["RouteDestination"] .." um ".. uhrzeit.readAll().. "Uhr" );
- h.flush();
- zugPlan[nextZug] = nil
- nextZug = ""
- sleep(3)
- redstone.setBundledOutput("bottom", 0)
- else
- sleep(0.5)
- redstone.setBundledOutput("bottom", 0)
- end
- lastTargets = nil
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment