Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local gui = require("/apis/gui")
- local Reactor = require("Reactor")
- require("Instrumentation")
- require("Control")
- function main()
- local monitor_0, monitor_5 = getMonitors()
- local main_display = gui.initializeDisplay(monitor_0)
- local debug_display = gui.initializeDisplay(monitor_5)
- local active_element = makeActivityElement(main_display)
- local debug_log = makeDebugLog(debug_display)
- local reactor = Reactor.Reactor {
- battery = Reactor.Battery {
- capacity = 10000,
- },
- }
- while true do
- local status = CreateReactorStatus(reactor)
- ControlReactor(reactor, status)
- updateActivityElement(status, active_element)
- log(status, debug_log)
- main_display:render()
- debug_display:render()
- parallel.waitForAny(delta, gui.doEvents)
- end
- end
- function delta()
- sleep(1)
- end
- function getMonitors()
- local monitor_0 = peripheral.wrap("monitor_0")
- monitor_0.setTextScale(1)
- monitor_0.clear()
- monitor_0.setCursorPos(0, 0)
- local monitor_5 = peripheral.wrap("monitor_5")
- monitor_5.setTextScale(0.5)
- monitor_5.clear()
- monitor_5.setCursorPos(0, 0)
- return monitor_0, monitor_5
- end
- function makeActivityElement(display)
- local w, h = display.window:getSize()
- local active_element = gui.Text:new {
- x = w - 9,
- y = 1,
- width = 8,
- height = 1,
- bg_color = colors.red,
- text_color = colors.white,
- }
- display.window:addElement(active_element)
- return active_element
- end
- function makeDebugLog(display)
- local w, h = display.window:getSize()
- local debug_log = gui.Text:new {
- width = w,
- height = h,
- auto_scroll = true,
- }
- display.window:addElement(debug_log)
- return debug_log
- end
- function updateActivityElement(status, active_element)
- if status.activity then
- active_element:setText(" active ")
- active_element:setBGColor(colors.green)
- else
- active_element:setText("inactive")
- active_element:setBGColor(colors.red)
- end
- end
- function log(status, debug_log)
- debug_log:write("[" .. os.clock() .. "] "
- .. "Reactor Status: " .. (status.activity and "Active" or "Not Active")
- .. ", " .. status.fuel .. " mB"
- .. ", " .. status.waste .. " mB"
- .. ", " .. status.power_stored .. " RF"
- .. "\n")
- end
- main()
Advertisement
Add Comment
Please, Sign In to add comment