diff --git a/burnrate_driver.lua b/burnrate_driver.lua index 9d5613d..fd49962 100644 --- a/burnrate_driver.lua +++ b/burnrate_driver.lua @@ -8,19 +8,6 @@ local function getValue() return reactor.getBurnRate() or init end -local function color() - local value = getValue() - return colors.black -end - - - -local function watch() - while true do - sleep(0.05) -- Update every tenth second - end -end - local function stepUp() local value = getValue() @@ -49,17 +36,22 @@ local function stepDown() reactor.setBurnRate(value - rateStep) end end +local function startUp() +end +local function shutdown() +end local function watch() print("Setting Default Burn Rate to: " .. init) reactor.setBurnRate(init) end local function report() - local color = color() + local color = colors.black monitor.setBackgroundColor(color) value = getValue() - monitor.clearLine() + + setNewLine() monitor.write("Burn Rate: " .. value) end -return { report = report, watch = watch, stepUp = stepUp, stepDown = stepDown, slowStepDown = slowStepDown, slowStepUp = slowStepUp } \ No newline at end of file +return { report = report, watch = watch, stepUp = stepUp, stepDown = stepDown, slowStepDown = slowStepDown, slowStepUp = slowStepUp, startUp = startUp, shutdown = shutdown } \ No newline at end of file diff --git a/coolant_driver.lua b/coolant_driver.lua index 3975f08..11fdbe9 100644 --- a/coolant_driver.lua +++ b/coolant_driver.lua @@ -30,17 +30,21 @@ local function watch() end end --- local function watch() --- checkCoolantLevel() --- end + +local function startUp() +end + +local function shutdown() +end local function report() local value = getValue() local color = colors.black monitor.setBackgroundColor(color) - monitor.clearLine() + + setNewLine() monitor.write("Coolant: " .. value .. "%") end -return { report = report, watch = watch} \ No newline at end of file +return { report = report, watch = watch, startUp = startUp, shutdown = shutdown } \ No newline at end of file diff --git a/environment_driver.lua b/environment_driver.lua new file mode 100644 index 0000000..a0e08a8 --- /dev/null +++ b/environment_driver.lua @@ -0,0 +1,26 @@ + +local function getValue() + return environment.getRadiationLevel().radiation +end + +local function watch() + while true do + sleep(0.05) -- Update every tenth second + end +end + +local function startUp() +end + +local function shutdown() +end + +local function report() + local value = getValue() + local color = colors.black + monitor.setBackgroundColor(color) + + setNewLine() + monitor.write("Radiation Level: " .. tostring(value)) +end +return { report = report, watch = watch, startUp = startUp, shutdown = shutdown } \ No newline at end of file diff --git a/environment_main.lua b/environment_main.lua deleted file mode 100644 index 9b71f72..0000000 --- a/environment_main.lua +++ /dev/null @@ -1,27 +0,0 @@ - -modem = peripheral.wrap("right") -environment = peripheral.wrap("left") - - -local function runMonitor() - while true do - local rads = environment.getRadiation(); - print("Radiation Level: " .. rads.radiation) - print("Radiation Unit: " .. rads.unit) - sleep(1) - end -end - -local function run() - while not modem do - print("Waiting for modem signal...") - sleep(1) - end - while not environment do - print("Waiting for environment signal...") - sleep(1) - end - parallel.waitForAll(runMonitor) -end - -return { run = run} \ No newline at end of file diff --git a/environment_startup.lua b/environment_startup.lua deleted file mode 100644 index 0e88508..0000000 --- a/environment_startup.lua +++ /dev/null @@ -1,4 +0,0 @@ -local kernel = require("kernel") -local main = kernel.addDriver("environment_main") -sleep(5) -main.run() \ No newline at end of file diff --git a/main.lua b/main.lua index b9bca51..ff8835f 100644 --- a/main.lua +++ b/main.lua @@ -3,48 +3,72 @@ reactor = peripheral.find("fissionReactorLogicAdapter") turbine = peripheral.find("turbineValve") turbineVent = peripheral.find("turbineVent") monitor = peripheral.find("monitor") +environment = peripheral.find("environmentDetector") 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") +environmentDriver = kernel.addDriver("environment_driver") +function setNewLine() + local x,y = monitor.getCursorPos() + monitor.setCursorPos(1, y + 1) + monitor.clearLine() +end + local function runMonitors() - parallel.waitForAll(tempDriver.watch, coolantDriver.watch, statusDriver.watch, turbineDriver.watch, burnRateDriver.watch) - -- while true do - -- tempDriver.watch() - -- coolantDriver.watch() - -- statusDriver.watch() - -- turbineDriver.watch() - -- burnRateDriver.watch() - -- sleep(0.05) - -- end + parallel.waitForAll( + tempDriver.watch, + coolantDriver.watch, + statusDriver.watch, + turbineDriver.watch, + burnRateDriver.watch, + environmentDriver.watch) end local function runDisplay() monitor.clear() monitor.setTextScale(1) while true do - monitor.setCursorPos(1, 1) + monitor.setCursorPos(1, 0) local drivers = { { Label = "Status", driver = statusDriver}, { Label = "Temperature", driver = tempDriver }, { Label = "Coolant", driver = coolantDriver }, { Label = "Turbine", driver = turbineDriver }, - { Label = "Burn Rate", driver = burnRateDriver } + { Label = "Burn Rate", driver = burnRateDriver }, + { Label = "Radiation Level", driver = burnRateDriver } } + for i, item in ipairs(drivers) do - monitor.setCursorPos(1, i) item.driver.report() - monitor.setCursorPos(1, i + 1) end sleep(0.05) -- Update every tenth second end end +local function startUp() + parallel.waitForAll(tempDriver.startUp, + coolantDriver.startUp, + statusDriver.startUp, + turbineDriver.startUp, + burnRateDriver.startUp, + environmentDriver.startUp) +end + +local function shutDown() + parallel.waitForAll(tempDriver.shutDown, + coolantDriver.shutDown, + statusDriver.shutDown, + turbineDriver.shutDown, + burnRateDriver.shutDown, + environmentDriver.shutDown) +end + local function run() while not reactor do print("Waiting for reactor signal...") @@ -59,13 +83,11 @@ local function run() sleep(1) end - -- Wait for all driver objects to be available - while not (tempDriver and coolantDriver and statusDriver and turbineDriver and burnRateDriver) do - print("Waiting for all drivers to be initialized...") - sleep(1) - end monitor.clear(); + startUp(); parallel.waitForAll(runMonitors, runDisplay) end -return { run = run} + + +return { run = run } diff --git a/status_driver.lua b/status_driver.lua index bee9616..fbff2de 100644 --- a/status_driver.lua +++ b/status_driver.lua @@ -4,41 +4,37 @@ local function getValue() end --- local function watch() --- while true do --- checkStatus() --- sleep(0.05) -- Update every tenth second --- end --- end - local function checkStatus() local value = getValue() end --- local function watch() --- checkStatus() --- end - local function watch() - reactor.setBurnRate(2) - local status = reactor.getStatus() - if(not status) then - reactor.activate() - return - end - while true do checkStatus() sleep(0.05) -- Update every tenth second end end +local function startUp() + reactor.setBurnRate(2) + local status = reactor.getStatus() + if(not status) then + reactor.activate() + return + end +end + +local function shutdown() + reactor.setBurnRate(0) + reactor.deactivate() +end local function report() local value = getValue() local color = colors.black monitor.setBackgroundColor(color) - monitor.clearLine() + + setNewLine() monitor.write("Reactor Status: " .. tostring(value)) end -return { report = report, watch = watch } \ No newline at end of file +return { report = report, watch = watch, startUp = startUp, shutdown = shutdown } \ No newline at end of file diff --git a/temperature_driver.lua b/temperature_driver.lua index f6f5ff9..f0bc83f 100644 --- a/temperature_driver.lua +++ b/temperature_driver.lua @@ -22,13 +22,8 @@ local function checkTemperature() end end --- local function color() --- local temperature = getValue() --- return colors.black --- end local function watch() - while true do print("Temperature: " .. getValue()) checkTemperature() @@ -37,18 +32,19 @@ local function watch() end +local function startUp() +end +local function shutdown() +end --- local function watch() --- checkTemperature() --- end - local function report() local value = getValue() local color = colors.black monitor.setBackgroundColor(color) - monitor.clearLine() + + setNewLine() monitor.write("Temperature: " .. value .. "F") end -return { report = report, watch = watch } \ No newline at end of file +return { report = report, watch = watch, startUp = startUp, shutdown = shutdown } \ No newline at end of file diff --git a/turbine_driver.lua b/turbine_driver.lua index bf9f36a..fff3225 100644 --- a/turbine_driver.lua +++ b/turbine_driver.lua @@ -35,9 +35,11 @@ local function checkSteamLevel() end end --- local function watch() --- checkSteamLevel() --- end +local function startUp() +end + +local function shutdown() +end local function watch() while true do @@ -50,9 +52,12 @@ local function report() local color = color() monitor.setBackgroundColor(color) value = getValue() - monitor.clearLine() + + setNewLine() monitor.write("Turbine Steam: " .. value .. "%") - --monitor.write("Turbine Vent: " .. turbine.getDumpingMode() .. "%") + + setNewLine() + monitor.write("Turbine Vent: " .. turbine.getDumpingMode()) end -return { report = report, watch = watch } \ No newline at end of file +return { report = report, watch = watch, startUp = startUp, shutdown = shutdown } \ No newline at end of file