Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function Settings()
- term.clear()
- term.setCursorPos(1,1)
- print("Setup-Modus für Fachtechniker")
- local pin = "----"
- repeat
- print("Bitte Fachtechniker-PIN eingeben:")
- print("(zum Verlassen ENTER drücken)")
- pin = io.read()
- if pin == "" then
- return false
- elseif pin ~= "0000" then
- term.setCursorPos(1,4)
- term.clearLine()
- term.setCursorPos(1,1)
- term.clearLine()
- print("FALSCHER PIN")
- end
- until (pin == "0000")
- local Setup = {}
- local okKey = "n"
- -- Anzahl Stockwerke
- repeat
- term.clear()
- term.setCursorPos(1,1)
- print("Anzahl Stockwerke eingeben:")
- Setup["anzahl"] = tonumber(io.read())
- print("Stockwerke: " .. Setup["anzahl"])
- print("Auswahl OK ? (j/n)")
- okKey = io.read()
- until(okKey == "j")
- okKey = "n"
- -- Stockwerke Namen
- repeat
- for i = 1, Setup["anzahl"] do
- term.clear()
- term.setCursorPos(1,1)
- print("Name Stockwerk " .. i .. " eingeben:")
- Setup["name" .. i] = io.read()
- end
- term.clear()
- term.setCursorPos(1,1)
- for i = 1, Setup["anzahl"] do
- print(Setup["name"..i])
- end
- print("Auswahl OK ? (j/n)")
- okKey = io.read()
- until(okKey == "j")
- okKey = "n"
- -- Seiten für Redstone
- repeat
- id, seite = selectionMenu.selectionMenu("Seite für Steuerung", "left", "right", "top", "bottom", "front", "back")
- Setup["seiteMain"] = seite
- id, seite = selectionMenu.selectionMenu("Seite für Rufknöpfe", "left", "right", "top", "bottom", "front", "back")
- Setup["seiteKnopf"] = seite
- id, seite = selectionMenu.selectionMenu("Seite für Sensoren", "left", "right", "top", "bottom", "front", "back")
- Setup["seiteSensor"] = seite
- id, seite = selectionMenu.selectionMenu("Seite für Modem", "left", "right", "top", "bottom", "front", "back")
- Setup["seiteModem"] = seite
- term.clear()
- term.setCursorPos(1,1)
- print("Seite Steuerung: " .. Setup["seiteMain"])
- print("Seite Rufknöpfe: " .. Setup["seiteKnopf"])
- print("Seite Sensoren: " .. Setup["seiteSensor"])
- print("Seite Modem: " .. Setup["seiteModem"])
- print("Auswahl OK ? (j/n)")
- okKey = io.read()
- until(okKey == "j")
- okKey = "n"
- local Connectors = {}
- -- Anschluss Seilwinde
- repeat
- id, color = selectionMenu.selectionMenu("Farbe für Seilwinde", {1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768},{"Weiß","Orange","Magenta","Hellblau","Gelb","Hellgrün","Rosa","Grau","Hellgrau","Türkis","Violett","Blau","Braun","Grün","Rot","Schwarz"})
- Connectors["windeMotor"] = color
- id, color = selectionMenu.selectionMenu("Farbe für Seilwinde - Kupplung", {1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768},{"Weiß","Orange","Magenta","Hellblau","Gelb","Hellgrün","Rosa","Grau","Hellgrau","Türkis","Violett","Blau","Braun","Grün","Rot","Schwarz"})
- Connectors["windeStop"] = color
- term.clear()
- term.setCursorPos(1,1)
- term.setTextColor(Connectors["windeMotor"])
- print("Seilwinde - Richtung")
- term.setTextColor(Connectors["windeStop"])
- print("Seilwinde - Kupplung")
- term.setTextColor(colors.white)
- print("Auswahl OK ? (j/n)")
- okKey = io.read()
- until(okKey == "j")
- okKey = "n"
- -- Anschlüsse Türsteuerung
- repeat
- for i = 1, Setup["anzahl"] do
- id, color = selectionMenu.selectionMenu("Farbe für Tür - ".. Setup["name"..i], {1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768},{"Weiß","Orange","Magenta","Hellblau","Gelb","Hellgrün","Rosa","Grau","Hellgrau","Türkis","Violett","Blau","Braun","Grün","Rot","Schwarz"})
- Connectors["tuer"..i] = color
- end
- term.clear()
- term.setCursorPos(1,1)
- for i = 1, Setup["anzahl"] do
- term.setTextColor(Connectors["tuer"..i])
- print("Tür - "..Setup["name"..i])
- end
- term.setTextColor(colors.white)
- print("Auswahl OK ? (j/n)")
- okKey = io.read()
- until(okKey == "j")
- okKey = "n"
- -- Anschlüsse Stopper
- repeat
- for i = 2, Setup["anzahl"]-1 do
- id, color = selectionMenu.selectionMenu("Farbe für Stopper unten - ".. Setup["name"..i], {1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768},{"Weiß","Orange","Magenta","Hellblau","Gelb","Hellgrün","Rosa","Grau","Hellgrau","Türkis","Violett","Blau","Braun","Grün","Rot","Schwarz"})
- Connectors["unten"..i] = color
- id, color = selectionMenu.selectionMenu("Farbe für Stopper oben - ".. Setup["name"..i], {1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768},{"Weiß","Orange","Magenta","Hellblau","Gelb","Hellgrün","Rosa","Grau","Hellgrau","Türkis","Violett","Blau","Braun","Grün","Rot","Schwarz"})
- Connectors["oben"..i] = color
- end
- term.clear()
- term.setCursorPos(1,1)
- for i = 2, Setup["anzahl"]-1 do
- term.setTextColor(Connectors["unten"..i])
- print("Stopper unten - "..Setup["name"..i])
- term.setTextColor(Connectors["oben"..i])
- print("Stopper oben - "..Setup["name"..i])
- end
- term.setTextColor(colors.white)
- print("Auswahl OK ? (j/n)")
- okKey = io.read()
- until(okKey == "j")
- okKey = "n"
- -- Anschlüsse Rufknöpfe
- repeat
- for i = 1, Setup["anzahl"] do
- id, color = selectionMenu.selectionMenu("Farbe für Knopf - ".. Setup["name"..i], {1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768},{"Weiß","Orange","Magenta","Hellblau","Gelb","Hellgrün","Rosa","Grau","Hellgrau","Türkis","Violett","Blau","Braun","Grün","Rot","Schwarz"})
- Connectors["knopf"..i] = color
- end
- term.clear()
- term.setCursorPos(1,1)
- for i = 1, Setup["anzahl"] do
- term.setTextColor(Connectors["knopf"..i])
- print("Knopf - "..Setup["name"..i])
- end
- term.setTextColor(colors.white)
- print("Auswahl OK ? (j/n)")
- okKey = io.read()
- until(okKey == "j")
- okKey = "n"
- -- Anschlüsse Sensoren
- repeat
- for i = 1, Setup["anzahl"] do
- id, color = selectionMenu.selectionMenu("Farbe für Sensor offen - ".. Setup["name"..i], {1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768},{"Weiß","Orange","Magenta","Hellblau","Gelb","Hellgrün","Rosa","Grau","Hellgrau","Türkis","Violett","Blau","Braun","Grün","Rot","Schwarz"})
- Connectors["auf"..i] = color
- id, color = selectionMenu.selectionMenu("Farbe für Sensor geschlossen - ".. Setup["name"..i], {1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768},{"Weiß","Orange","Magenta","Hellblau","Gelb","Hellgrün","Rosa","Grau","Hellgrau","Türkis","Violett","Blau","Braun","Grün","Rot","Schwarz"})
- Connectors["zu"..i] = color
- end
- term.clear()
- term.setCursorPos(1,1)
- for i = 1, Setup["anzahl"] do
- term.setTextColor(Connectors["auf"..i])
- print("Sensor offen - "..Setup["name"..i])
- term.setTextColor(Connectors["zu"..i])
- print("Sensor geschlossen - "..Setup["name"..i])
- end
- term.setTextColor(colors.white)
- print("Auswahl OK ? (j/n)")
- okKey = io.read()
- until(okKey == "j")
- okKey = "n"
- -- Stockwerk-Computer
- repeat
- term.clear()
- term.setCursorPos(1,1)
- for i = 1, Setup["anzahl"] do
- print("ID für PC - "..Setup["name"..i].. " eingeben:")
- Setup["pc"..i] = tonumber(io.read())
- end
- term.clear()
- term.setCursorPos(1,1)
- for i = 1, Setup["anzahl"] do
- print("PC - "..Setup["name"..i].. " : ".. Setup["pc"..i])
- end
- print("Auswahl OK ? (j/n)")
- okKey = io.read()
- until(okKey == "j")
- okKey = "n"
- local file = fs.open("/aufzug-steuerung/setup","w")
- file.write(textutils.serialize(Setup))
- file.close()
- file = fs.open("/aufzug-steuerung/connectors","w")
- file.write(textutils.serialize(Connectors))
- file.close()
- term.clear()
- term.setCursorPos(1,1)
- return true
- end
- function Startup()
- term.clear()
- term.setCursorPos(1,1)
- print("-- Aufzug Steuerung startet --")
- print("Prüfe Kabinen Standort ...")
- if redstone.getBundledInput(Steuerung["seiteSensor"]) == 0 then
- print("Standort der Kabine nicht überprüfbar.")
- Kalibrierungsfahrt()
- end
- Stockwerk = GetStockwerk()
- print("Kabine in Stockwerk ".. Steuerung["name"..Stockwerk])
- os.sleep(1)
- Senden(Stockwerk, "startup")
- end
- function Kalibrierungsfahrt()
- print("Führe Kalibrieungsfahrt durch ...")
- sleep(5)
- redstone.setBundledOutput(Steuerung["seiteMain"],Verbinder["windeStop"])
- local timer = os.startTimer(40)
- repeat
- local event = {os.pullEvent()}
- if event[1] == "timer" and event[2] == timer then
- print("Fehler bei der Kalibrierung. Bitte Technik überprüfen.")
- os.sleep(30)
- os.reboot()
- return
- elseif event[1] == "redstone" and redstone.getBundledInput(Steuerung["seiteSensor"]) ~= 0 then
- redstone.setBundledOutput(Steuerung["seiteMain"],0)
- return
- end
- until( false )
- end
- function GetStockwerk()
- for i=1, Steuerung["anzahl"] do
- if redstone.testBundledInput(Steuerung["seiteSensor"], Verbinder["auf"..i]) or redstone.testBundledInput(Steuerung["seiteSensor"], Verbinder["zu"..i]) then
- return i
- end
- end
- return -1
- end
- function Queue(value)
- if Liste.first <= Liste.last then
- for i=Liste.first, Liste.last do
- if Liste[i] == value then
- return
- end
- end
- end
- local newLast = Liste.last + 1
- Liste.last = newLast
- Liste[newLast] = value
- os.queueEvent("wartet")
- print("Stockwerk ".. value .. " zur Liste hinzugefügt")
- end
- function Peak()
- if Liste.first > Liste.last then
- return -1
- end
- return Liste[Liste.first]
- end
- function Dequeue()
- if Liste.first > Liste.last then
- return -1
- end
- local value = Liste[Liste.first]
- Liste[Liste.first] = nil
- Liste.first = Liste.first + 1
- return value
- end
- function Senden(ziel, msg)
- rednet.open(Steuerung["seiteModem"])
- for i=1, Steuerung["anzahl"] do
- local protocol
- if i == ziel and msg == "ankunft" then
- protocol = msg
- elseif i == ziel and msg == "abfahrt" then
- protocol = msg
- elseif i == ziel and msg == "ooo" then
- protocol = msg
- elseif msg == "ankunft" then
- protocol = "stop"
- elseif msg == "abfahrt" or msg == "ooo" then
- protocol = "ignore"
- else
- protocol = msg
- end
- rednet.send(Steuerung["pc"..i], ziel, protocol)
- end
- end
- function Fahren(ziel)
- local output = 0
- if ziel == Stockwerk then
- redstone.setBundledOutput(Steuerung["seiteMain"], 0)
- return
- end
- -- Kolben bei Zielstockwerk ausfahren
- if ziel > 1 and ziel < Stockwerk then
- output = Verbinder["unten"..ziel]
- elseif ziel < Steuerung["anzahl"] and ziel > Stockwerk then
- output = Verbinder["oben"..ziel]
- end
- redstone.setBundledOutput(Steuerung["seiteMain"], output)
- -- Tuer schliessen
- print("Türe schließt")
- Senden(Stockwerk, "abfahrt")
- sleep(0.8)
- output = output + Verbinder["tuer"..Stockwerk]
- repeat
- redstone.setBundledOutput(Steuerung["seiteMain"], output)
- os.pullEvent("stockwerk")
- until(Tuer_auf == false)
- sleep(0.8)
- -- Fahren
- print("Fahre zu Stockwerk "..Steuerung["name"..ziel])
- output = output + Verbinder["windeStop"]
- if ziel < Stockwerk then
- output = output + Verbinder["windeMotor"]
- Senden(Stockwerk, "runter")
- else
- Senden(Stockwerk, "hoch")
- end
- local play = true
- repeat
- redstone.setBundledOutput(Steuerung["seiteMain"], output)
- os.pullEvent("stockwerk")
- Senden(Stockwerk, "status")
- if Stockwerk == ziel and play then
- Senden(ziel, "ankunft")
- play = false
- end
- until(Stockwerk == ziel and Tuer_auf)
- print("Angekommen")
- redstone.setBundledOutput(Steuerung["seiteMain"], 0)
- end
- function Monitor()
- repeat
- os.pullEvent("redstone")
- for i=1, Steuerung["anzahl"] do
- if redstone.testBundledInput(Steuerung["seiteSensor"], Verbinder["zu"..i]) then
- print("Aufzug befindet sich bei Stockwerk "..Steuerung["name"..i])
- if Stockwerk ~= i or (Stockwerk == i and Tuer_auf) then
- Stockwerk = i
- Tuer_auf = false
- os.queueEvent("stockwerk")
- end
- elseif redstone.testBundledInput(Steuerung["seiteSensor"], Verbinder["auf"..i]) then
- print("Aufzug befindet sich bei Stockwerk "..Steuerung["name"..i])
- if Stockwerk ~= i or (Stockwerk == i and Tuer_auf == false) then
- Stockwerk = i
- Tuer_auf = true
- os.queueEvent("stockwerk")
- end
- end
- if redstone.testBundledInput(Steuerung["seiteKnopf"], Verbinder["knopf"..i]) then
- print("Anfrage zu Stockwerk "..i)
- if Wartung then
- Senden(i, "ooo")
- else
- Queue(i)
- end
- break
- end
- end
- until ( false )
- end
- function Control()
- repeat
- if Peak() == -1 then
- os.pullEvent("wartet")
- end
- local ziel = Peak()
- if ziel ~= -1 and Wartung == false then
- Fahren(ziel)
- Dequeue()
- sleep(6)
- end
- until ( false )
- end
- function Maintain()
- repeat
- local id, key = os.pullEvent("key")
- if key == 96 then
- if Wartung then
- print("Wartungsmodus deaktiviert")
- Wartung = false
- Senden(Stockwerk, "startup")
- redstone.setBundledOutput(Steuerung["seiteMain"], 0)
- else
- print("Wartungsmodus aktiviert")
- Wartung = true
- Senden(-1, "techniker")
- redstone.setBundledOutput(Steuerung["seiteMain"], Verbinder["tuer"..Stockwerk])
- end
- end
- until ( false )
- end
- os.loadAPI("selectionMenu")
- if (not fs.exists("/aufzug-steuerung/setup")) or (not fs.exists("/aufzug-steuerung/connectors")) then
- if not Settings() then
- term.clear()
- return
- end
- end
- local file = fs.open("/aufzug-steuerung/setup","r")
- Steuerung = textutils.unserialize(file.readAll())
- file.close()
- file = fs.open("/aufzug-steuerung/connectors","r")
- Verbinder = textutils.unserialize(file.readAll())
- file.close()
- Stockwerk = -1
- Tuer_auf = true
- Wartung = false
- Liste = {first = 0, last = -1}
- Startup()
- parallel.waitForAny(Monitor, Control, Maintain)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement