From 904309aa0fff9d1dc981cf4ecdd2e29cc408c3e4 Mon Sep 17 00:00:00 2001 From: itzmarkoni Date: Sat, 14 Jun 2025 17:02:44 -0400 Subject: [PATCH] updated --- burnrate_driver.lua | 43 ++++++++++++++++++++++++++++++++++++++++++ coolant_driver.lua | 8 ++++++-- main.lua | 32 +++++++++++++------------------ status_driver.lua | 8 ++++++-- temperature_driver.lua | 22 +++++++++++++++++++-- turbine_driver.lua | 14 +++++++++++--- 6 files changed, 99 insertions(+), 28 deletions(-) create mode 100644 burnrate_driver.lua diff --git a/burnrate_driver.lua b/burnrate_driver.lua new file mode 100644 index 0000000..d80a0c3 --- /dev/null +++ b/burnrate_driver.lua @@ -0,0 +1,43 @@ +local max = 15 +local init = 5 +local rateStep = 0.10 +local min = 1 + +local function getValue() + return reactor.getBurnRate() +end + +local function color() + local value = getValue() + return colors.black +end + + + +local function watch() + while true do + end +end + +local function stepUp() + local value = getValue() + if value < max then + reactor.setBurnRate(value + rateStep) + end +end + +local function stepDown() + local value = getValue() + if value > min then + reactor.setBurnRate(value - rateStep) + end +end + +local function report() + local color = color() + monitor.setBackgroundColor(color) + value = getValue() + monitor.clearLine() + monitor.write("Burn Rate: " .. value) +end +return { report = report, watch = watch } \ No newline at end of file diff --git a/coolant_driver.lua b/coolant_driver.lua index d06b38d..db42ac3 100644 --- a/coolant_driver.lua +++ b/coolant_driver.lua @@ -12,9 +12,13 @@ end local function watch() + while true do + checkCoolantLevel() + end +end + +local function checkCoolantLevel() local coolantLevel = getValue() - print("Coolant: " .. coolantLevel) - sleep(1) end local function report() diff --git a/main.lua b/main.lua index 47e15b0..da353d7 100644 --- a/main.lua +++ b/main.lua @@ -5,21 +5,22 @@ turbine = peripheral.find("turbineValve") turbineVent = peripheral.find("turbineVent") 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") +tempDriver = kernel.addDriver("temperature_driver") +coolantDriver = kernel.addDriver("coolant_driver") +statusDriver = kernel.addDriver("status_driver") +turbineDriver = kernel.addDriver("turbine_driver") +burnRateDriver = kernel.addDriver("burnrate_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) + parallel.waitForAll( + tempDriver.watch, + coolantDriver.watch, + statusDriver.watch, + turbineDriver.watch, + burnRateDriver.watch + ) end end @@ -27,20 +28,13 @@ 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}, { Label = "Temperature", driver = tempDriver }, { Label = "Coolant", driver = coolantDriver }, { Label = "Turbine", driver = turbineDriver } + { Label = "Burn Rate", driver = burnRateDriver } } for i, item in ipairs(drivers) do diff --git a/status_driver.lua b/status_driver.lua index 8015132..74297af 100644 --- a/status_driver.lua +++ b/status_driver.lua @@ -9,9 +9,13 @@ local function color() end local function watch() + while true do + checkStatus() + end +end + +local function checkStatus() local value = getValue() - print("Status: " .. tostring(value)) - sleep(1) end local function report() diff --git a/temperature_driver.lua b/temperature_driver.lua index c1baa6d..43f11f5 100644 --- a/temperature_driver.lua +++ b/temperature_driver.lua @@ -1,3 +1,6 @@ +local max = 250 +local min = 212 + local function getValue() local kelvin = reactor.getTemperature() or 0 @@ -11,8 +14,23 @@ local function color() end local function watch() - print("Temperature: " .. getValue()) - sleep(1) + while true do + print("Temperature: " .. getValue()) + checkTemperature() + end +end +local function checkTemperature() + local temperature = getValue() + local upperThreshold = max - 20 + local lowerThreshold = min + 20 + + if temperature >= upperThreshold then + print("Warning: Temperature approaching upper limit! Taking action.") + burnRateDriver.stepDown() + elseif temperature <= lowerThreshold then + print("Warning: Temperature approaching lower limit! Taking action.") + burnRateDriver.stepUp() + end end local function report() diff --git a/turbine_driver.lua b/turbine_driver.lua index f299e08..1b1ee53 100644 --- a/turbine_driver.lua +++ b/turbine_driver.lua @@ -13,18 +13,26 @@ local function color() end local function watch() - print("Turbine Steam Filled: " .. getValue()) + while true do + checkSteamLevel() + end +end + +local function checkSteamLevel() local value = getValue() if value > max then print("Warning: Steam above maximum! Taking action.") - --reactor.scram(); + reactor.scram(); turbine.setDumpingMode("DUMPING") + burnRateDriver.stepDown() elseif value >= minVent and value <= maxVent then print("Steam within vent range. Adjusting vents.") turbine.setDumpingMode("DUMPING") + burnRateDriver.stepDown() elseif value >= min and value < minVent then print("Steam within normal operation range.") - turbine.setDumpingMode("DUMPING_EXCESS") + turbine.setDumpingMode("DUMPING") + burnRateDriver.stepDown() elseif value < min then print("Warning: Steam below minimum! Taking action.") turbine.setDumpingMode("IDLE")