Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Copyright 2012 John Paul Alcala
- --
- -- Licensed under the Apache License, Version 2.0 (the "License");
- -- you may not use this file except in compliance with the License.
- -- You may obtain a copy of the License at
- --
- -- http://www.apache.org/licenses/LICENSE-2.0
- --
- -- Unless required by applicable law or agreed to in writing, software
- -- distributed under the License is distributed on an "AS IS" BASIS,
- -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- -- See the License for the specific language governing permissions and
- -- limitations under the License.
- local doorControlScript = "/cc/doorcontrol"
- local pumpControlScript = "/cc/pumpcontrol"
- local entranceHatchOpen = function()
- return redstone.testBundledInput("top", colors.red) ~= true
- end
- local exitHatchOpen = function()
- return redstone.testBundledInput("top", colors.yellow) ~= true
- end
- local openAirlockCommand = function()
- return redstone.testBundledInput("top", colors.cyan)
- end
- local closeAirlockCommand = function()
- return redstone.testBundledInput("top", colors.lime)
- end
- local openAirlock = function()
- if exitHatchOpen() then
- shell.run(doorControlScript, "close", "exit")
- shell.run(pumpControlScript, "drain")
- shell.run(doorControlScript, "open", "entrance")
- end
- end
- local closeAirlock = function()
- if entranceHatchOpen() then
- shell.run(doorControlScript, "close", "entrance")
- shell.run(pumpControlScript, "fill")
- shell.run(doorControlScript, "open", "exit")
- end
- end
- local sendOkSignal = function()
- redstone.setBundledOutput("top", colors.cyan+colors.lime)
- sleep(0.5)
- redstone.setBundledOutput("top", 0)
- end
- local testAirlockState = function()
- if entranceHatchOpen() == exitHatchOpen() then
- print("WARNING! Airlock state has been compromised.")
- print("Correcting state...")
- print("")
- shell.run(doorControlScript, "close", "entrance")
- shell.run(doorControlScript, "close", "exit")
- shell.run(pumpControlScript, "drain")
- shell.run(doorControlScript, "open", "entrance")
- print("Finished correcting Airlock state.")
- end
- end
- -- Run the airlock server
- term.clear()
- term.setCursorPos(1,1)
- print("Starting Airlock Control...")
- sleep(2)
- print("Checking Airlock state...")
- sleep(2)
- testAirlockState()
- print("Airlock Control is now running.")
- while true do
- testAirlockState()
- local event = os.pullEvent("redstone")
- if openAirlockCommand() then
- openAirlock()
- sendOkSignal()
- elseif closeAirlockCommand() then
- closeAirlock()
- sendOkSignal()
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment