diff --git a/coolant_driver.lua b/coolant_driver.lua index 7cb8e85..4f2f561 100644 --- a/coolant_driver.lua +++ b/coolant_driver.lua @@ -1,15 +1,43 @@ -local function report(reactor) +local maxValue = 100 +local minValue = 0 + +local function configureReport(monitor) + local x,y = term.getCursorPos() + monitor.setCursorPos(x, y + 1) + monitor.clearLine() +end + +local function getValue(reactor) + return (reactor.getCoolantFilledPercentage() or 0) * 100 +end + +local function watch(reactor, monitor) + local coolantLevel = getValue(reactor) + print("Coolant: " .. coolantLevel) + sleep(1) +end + +local function report(reactor, monitor) if reactor then - return (reactor.getCoolantFilledPercentage() or 0) * 100 + local value = getValue(reactor) + local color = color(reactor) + configureReport(monitor) + monitor.setBackgroundColor(color) + monitor.write("Coolant: " .. value .. "%") else return "No reactor found" end end -local function watch(reactor, monitor) - local coolantLevel = - print("Coolant: " .. report(reactor)) - sleep(1) +local function configureReport(monitor) + local x,y = monitor.getCursorPos() + monitor.setCursorPos(x, y + 1) + monitor.clearLine() end -return { report = report, watch = watch } \ No newline at end of file +local function color(reactor) + local coolantLevel = getValue(reactor) + return colors.black +end + +return { report = report, watch = watch} \ No newline at end of file diff --git a/main.lua b/main.lua index c90e83e..29af3da 100644 --- a/main.lua +++ b/main.lua @@ -1,8 +1,7 @@ local kernel = require("kernel") local tempDriver = kernel.addDriver("temperature_driver") local coolantDriver = kernel.addDriver("coolant_driver") -local reactor = peripheral.find("fissionReactorLogicAdapter") -local monitor = peripheral.find("monitor") + local function runMonitors() while true do @@ -14,17 +13,15 @@ end local function runDisplay() while true do monitor.setCursorPos(1,1) - local data = { - { Label = "Temperature", value = tempDriver.report(reactor)}, - { Label = "Coolant", value = coolantDriver.report(reactor) }, - { Label = "Humidity", value = "45%" } + local drivers = { + { Label = "Temperature", driver = tempDriver }, + { Label = "Coolant", driver = coolantDriver }, } - for i, item in ipairs(data) do - monitor.clearLine(); - monitor.write(item.Label .. ": " .. item.value) - monitor.setCursorPos(1, i + 1) + for _, item in ipairs(drivers) do + item.driver.report(reactor, monitor) end + sleep(0.25) -- Update every quarter second end end diff --git a/temperature_driver.lua b/temperature_driver.lua index 54ec725..71b8f2a 100644 --- a/temperature_driver.lua +++ b/temperature_driver.lua @@ -1,14 +1,34 @@ -local function report(reactor) + +local function getValue(reactor) + return reactor.getTemperature() or 0 +end + +local function watch(reactor, monitor) + print("Temperature: " .. getValue(reactor)) + sleep(1) +end + +local function color(reactor) + local temperature = getValue(reactor) + return colors.black +end + +local function report(reactor, monitor) if reactor then - return reactor.getTemperature() + local value = getValue(reactor) + local color = color(reactor) + configureReport(monitor) + monitor.setBackgroundColor(color) + monitor.write("Coolant: " .. value .. "%") else return "No reactor found" end end -local function watch(reactor, monitor) - print("Temperature: " .. report(reactor)) - sleep(1) +local function configureReport(monitor) + local x,y = monitor.getCursorPos() + monitor.setCursorPos(x, y + 1) + monitor.clearLine() end -return { report = report, watch = watch } \ No newline at end of file +return { report = report, watch = watch} \ No newline at end of file