71 lines
2.1 KiB
Lua
71 lines
2.1 KiB
Lua
local kernel = require("kernel")
|
|
local reactor = peripheral.find("fissionReactorLogicAdapter")
|
|
local turbine = peripheral.find("turbineValve")
|
|
local monitor = peripheral.find("monitor")
|
|
local tempDriver = kernel.addDriver("temperature_driver")
|
|
local coolantDriver = kernel.addDriver("coolant_driver")
|
|
local statusDriver = kernel.addDriver("status_driver")
|
|
local turbineDriver = kernel.addDriver("turbine_driver")
|
|
|
|
isWarningState = false
|
|
isCriticalState = false
|
|
isShutdownState = false
|
|
|
|
local function runMonitors()
|
|
while true do
|
|
tempDriver.watch(reactor, monitor)
|
|
coolantDriver.watch(reactor, monitor)
|
|
statusDriver.watch(reactor, monitor)
|
|
turbineDriver.watch(turbine, monitor)
|
|
end
|
|
end
|
|
|
|
local function runDisplay()
|
|
monitor.clear()
|
|
monitor.setTextScale(1)
|
|
while true do
|
|
if(isWarningState or isCriticalState or isShutdownState) then
|
|
monitor.setBackgroundColor(colors.red)
|
|
monitor.clear()
|
|
monitor.setCursorPos(1, 1)
|
|
monitor.write("Reactor in critical state!")
|
|
sleep(2)
|
|
monitor.clear()
|
|
end
|
|
monitor.setCursorPos(1, 1)
|
|
local drivers = {
|
|
{ Label = "Status", driver = statusDriver, peripheral = reactor },
|
|
{ Label = "Temperature", driver = tempDriver, peripheral = reactor },
|
|
{ Label = "Coolant", driver = coolantDriver, peripheral = reactor },
|
|
{ Label = "Turbine", driver = turbineDriver, peripheral = turbine }
|
|
}
|
|
|
|
for i, item in ipairs(drivers) do
|
|
monitor.setCursorPos(1, i)
|
|
item.driver.report(item.peripheral, monitor)
|
|
monitor.setCursorPos(1, i + 1)
|
|
end
|
|
|
|
sleep(0.25) -- Update every quarter second
|
|
end
|
|
end
|
|
|
|
local function run()
|
|
while not reactor do
|
|
print("Waiting for reactor signal...")
|
|
sleep(1)
|
|
end
|
|
while not turbine do
|
|
print("Waiting for turbine signal...")
|
|
sleep(1)
|
|
end
|
|
while not monitor do
|
|
print("Waiting for monitor signal...")
|
|
sleep(1)
|
|
end
|
|
|
|
parallel.waitForAll(runMonitors, runDisplay)
|
|
end
|
|
|
|
return { run = run}
|