Files
nova-corp/main.lua
2025-06-14 15:02:31 -04:00

77 lines
2.2 KiB
Lua

local kernel = require("kernel")
local reactor = peripheral.find("fissionReactorLogicAdapter")
local turbine = peripheral.find("turbineValve_4")
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 reactorDrivers = {
{ Label = "Status", driver = statusDriver },
{ Label = "Temperature", driver = tempDriver },
{ Label = "Coolant", driver = coolantDriver },
}
for i, item in ipairs(reactorDrivers) do
monitor.setCursorPos(1, i)
item.driver.report(reactor, monitor)
monitor.setCursorPos(1, i + 1)
end
local turbineDrivers = {
{ Label = "Turbine", driver = turbineDriver }
}
for i, item in ipairs(turbineDrivers) do
monitor.setCursorPos(1, i)
item.driver.report(turbine, 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 monitor do
print("Waiting for monitor signal...")
sleep(1)
end
parallel.waitForAll(runMonitors, runDisplay)
end
return { run = run}