SHOW:
|
|
- or go back to the newest paste.
| 1 | - | trainWaitTime = 10 |
| 1 | + | os.loadAPI("ocs/apis/sensor")
|
| 2 | prox = sensor.wrap("top")
| |
| 3 | trainWaitTime = 60 | |
| 4 | lastTargets = nil | |
| 5 | ||
| 6 | - | rednet.open("back")
|
| 6 | + | function getTargets() |
| 7 | lastTargets = prox.getTargets() | |
| 8 | return lastTargets | |
| 9 | end | |
| 10 | ||
| 11 | function getTimeout() | |
| 12 | - | monitors = {peripheral.wrap( "monitor_3" ),peripheral.wrap( "monitor_4" ),peripheral.wrap( "monitor_7" ),peripheral.wrap( "monitor_8" )}
|
| 12 | + | sleep(2) |
| 13 | return nil | |
| 14 | end | |
| 15 | ||
| 16 | --Prints Texts on monitors and sets trains free | |
| 17 | function monitorPainting() | |
| 18 | print("Monitorpainting wird gestartet....")
| |
| 19 | ||
| 20 | local monitors = nil | |
| 21 | - | local senderId, message, protocol = rednet.receive() |
| 21 | + | |
| 22 | - | local targets = textutils.unserialize(message) |
| 22 | + | |
| 23 | elseif os.getComputerLabel() == "Bahnhof2" then | |
| 24 | monitors = {peripheral.wrap( "monitor_10" ), peripheral.wrap( "monitor_3" ),peripheral.wrap( "monitor_4" ),peripheral.wrap( "monitor_7" ),peripheral.wrap( "monitor_8" )}
| |
| 25 | end | |
| 26 | ||
| 27 | - | myApi.executeTableFunction(monitors, "write", "Zug Gleis Ziel ETA Abfahrt") |
| 27 | + | |
| 28 | myApi.executeTableFunction(monitors, "setTextScale",0.7) | |
| 29 | ||
| 30 | while true do | |
| 31 | while lastTargets == nil do | |
| 32 | parallel.waitForAny(getTargets, getTimeout) | |
| 33 | end | |
| 34 | ||
| 35 | local targets = lastTargets | |
| 36 | ||
| 37 | count = 0 | |
| 38 | for k, v in pairs( targets ) do | |
| 39 | count = count + 1 | |
| 40 | end | |
| 41 | print(os.clock() .. ": " .. count .. " targets") | |
| 42 | ||
| 43 | myApi.executeTableFunction(monitors, "clear") | |
| 44 | myApi.executeTableFunction(monitors, "setTextColor", colors.white) | |
| 45 | myApi.executeTableFunction(monitors, "setCursorPos", 1, 1) | |
| 46 | myApi.executeTableFunction(monitors, "write", "Zug Gleis Ziel ETA Abfahrt") | |
| 47 | ||
| 48 | local zeile = 2 | |
| 49 | local nextZug = "" | |
| 50 | for k, v in pairs( targets ) do | |
| 51 | print(os.clock() .. ": Got target: " .. k ) | |
| 52 | ||
| 53 | - | myApi.executeTableFunction(monitors, "write", myApi.fillMyString(v["RouteDestination"],5) .. " " .. gleis .. " Ölplattform 0min ".. math.floor(ankunft) .."sek" ) |
| 53 | + | |
| 54 | if string.find(k, "Locomotive") and (gleis ~= "?") then | |
| 55 | if zugPlan[k] == nil then | |
| 56 | zugPlan[k] = os.clock() | |
| 57 | end | |
| 58 | ||
| 59 | if os.clock()-zugPlan[k] > trainWaitTime then | |
| 60 | if nextZug == "" or (os.clock()-zugPlan[nextZug]) < (os.clock()-zugPlan[k]) then | |
| 61 | nextZug = k | |
| 62 | end | |
| 63 | end | |
| 64 | ||
| 65 | local ankunft = 0 | |
| 66 | ||
| 67 | if zugPlan[k] ~= nil then | |
| 68 | ankunft = (trainWaitTime - (os.clock()-zugPlan[k])) | |
| 69 | if ankunft < 0 then | |
| 70 | ankunft = 0 | |
| 71 | end | |
| 72 | end | |
| 73 | ||
| 74 | myApi.executeTableFunction(monitors, "setCursorPos", 1, zeile) | |
| 75 | local destination = myApi.fillMyString(v["RouteDestination"],6) | |
| 76 | ankunft = math.floor(ankunft) | |
| 77 | ||
| 78 | myApi.executeTableFunction(monitors, "write", destination .. " " .. gleis .. " Ölplattform 0min ".. ankunft .."sek" ) | |
| 79 | ||
| 80 | if (trainWaitTime - (os.clock()-zugPlan[k])) < -1 then | |
| 81 | myApi.executeTableFunction(monitors, "setTextColor", colors.red) | |
| 82 | myApi.executeTableFunction(monitors, "write", " +" .. math.floor(math.abs(trainWaitTime - (os.clock()-zugPlan[k])) ) ) | |
| 83 | myApi.executeTableFunction(monitors, "setTextColor", colors.white) | |
| 84 | end | |
| 85 | zeile = zeile + 1 | |
| 86 | ||
| 87 | end | |
| 88 | end | |
| 89 | ||
| 90 | if nextZug ~= "" and colors.test(redstone.getBundledInput("bottom"), colors.lightGray) and (not colors.test(redstone.getBundledInput("bottom"), colors.red) ) then
| |
| 91 | if myApi.getGleisFromPosX( targets[nextZug]["Position"] ) == 1 then | |
| 92 | redstone.setBundledOutput("bottom", colors.white)
| |
| 93 | elseif myApi.getGleisFromPosX( targets[nextZug]["Position"] ) == 2 then | |
| 94 | redstone.setBundledOutput("bottom", colors.yellow)
| |
| 95 | elseif myApi.getGleisFromPosX( targets[nextZug]["Position"] ) == 3 then | |
| 96 | redstone.setBundledOutput("bottom", colors.lime)
| |
| 97 | elseif myApi.getGleisFromPosX( targets[nextZug]["Position"]) == 4 then | |
| 98 | redstone.setBundledOutput("bottom", colors.pink)
| |
| 99 | elseif myApi.getGleisFromPosX( targets[nextZug]["Position"] ) == 5 then | |
| 100 | redstone.setBundledOutput("bottom", colors.cyan)
| |
| 101 | end | |
| 102 | ||
| 103 | --myPrinter = peripheral.wrap( "printer_0" ) | |
| 104 | --myPrinter.endPage() | |
| 105 | --ready = myPrinter.newPage() | |
| 106 | --myPrinter.setPageTitle("ZugLog Hauptbahnhof")
| |
| 107 | --printerZeile = 1 | |
| 108 | ||
| 109 | --printerZeile = printerZeile + 1 | |
| 110 | --if printerZeile == 20 then | |
| 111 | --printerZeile = 1 | |
| 112 | --myPrinter.setPageTitle("ZugLog Hauptbahnhof")
| |
| 113 | --myPrinter.endPage() | |
| 114 | --ready = myPrinter.newPage() | |
| 115 | -- end | |
| 116 | ||
| 117 | ||
| 118 | local h = fs.open("disk/logfile", fs.exists("disk/logfile") and "a" or "w")
| |
| 119 | uhrzeit = http.get("http://tankguru.me/extern/time.php?format=H:i:s")
| |
| 120 | h.writeLine("Bye ".. targets[nextZug]["RouteDestination"] .." um ".. uhrzeit.readAll().. "Uhr" );
| |
| 121 | h.flush(); | |
| 122 | ||
| 123 | ||
| 124 | zugPlan[nextZug] = nil | |
| 125 | nextZug = "" | |
| 126 | ||
| 127 | sleep(3) | |
| 128 | redstone.setBundledOutput("bottom", 0)
| |
| 129 | else | |
| 130 | sleep(0.5) | |
| 131 | redstone.setBundledOutput("bottom", 0)
| |
| 132 | end | |
| 133 | lastTargets = nil | |
| 134 | end | |
| 135 | ||
| 136 | end |