Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- settings.load()
- -- #region Setup
- local me_system = peripheral.wrap(settings.get("akw.meSystem"))
- local fuel_type = settings.get("akw.fuelType")
- local monitor = peripheral.wrap(settings.get("akw.monitor"))
- local reactors = {}
- for _, id in ipairs({"A", "B", "C", "D"}) do
- reactors[id] = {
- active = settings.get("akw.reactor" .. id .. ".active"),
- rods = {},
- x_offset = 0,
- y_offset = 0,
- }
- if reactors[id].active then
- for j = 1, 4 do
- reactors[id].rods[j] = {
- deactivated = false,
- boiler = peripheral.wrap(settings.get("akw.reactor" .. id .. ".rod" .. j .. ".boiler")),
- battery = peripheral.wrap(settings.get("akw.reactor" .. id .. ".rod" .. j .. ".battery")),
- }
- end
- end
- end
- local power_lines = {}
- for i = 1, 6 do
- power_lines[i] = peripheral.wrap(settings.get("akw.powerLine" .. i))
- end
- -- #endregion
- -- #region Functions
- local function init_reactor_display(reactor_id, x_offset, y_offset)
- print("Initializing reactor display for block " .. reactor_id)
- monitor.setCursorPos(1 + x_offset, 1 + y_offset)
- monitor.write("Block " .. reactor_id)
- for i = 1, 4 do
- monitor.setCursorPos(1 + x_offset + 1, 1 + y_offset + 1 + i)
- monitor.write("Stab " .. i)
- end
- end
- local function init_powerline_display(x_offset, y_offset)
- print("Initializing powerline display")
- monitor.setCursorPos(1+ x_offset, 1 + y_offset)
- monitor.write("Energieabnahme")
- for i = 1, 6 do
- monitor.setCursorPos(1 + x_offset + 1, 1 + y_offset + 1 + i)
- monitor.write("Leitung " .. i)
- end
- end
- local function init_fuel_display(x_offset, y_offset)
- print("Initializing fuel display")
- monitor.setCursorPos(1 + x_offset, 1 + y_offset)
- monitor.write("Treibstoff")
- end
- local function update_reactor_display(reactor_id, x_offset, y_offset)
- print("Updating reactor display for block " .. reactor_id)
- for i = 1, 4 do
- local message = " "
- local boiler_state = reactors[reactor_id].rods[i].boiler.getLine(1)
- local generator_state = reactors[reactor_id].rods[i].boiler.getLine(6)
- if string.find(boiler_state, "Max") then
- if string.find(generator_state, "236 RPM") then
- reactors[reactor_id].rods[i].deactivated = false
- monitor.setTextColor(colors.green)
- message = "aktiv OK"
- else
- reactors[reactor_id].rods[i].deactivated = true
- monitor.setTextColor(colors.red)
- message = "aktiv ER"
- end
- elseif string.find(boiler_state, "Idle") and reactors[reactor_id].rods[i].deactivated then
- monitor.setTextColor(colors.red)
- message = "deaktiv ER"
- elseif string.find(boiler_state, "Idle") then
- monitor.setTextColor(colors.lightGray)
- message = "inaktiv OK"
- else
- monitor.setTextColor(colors.red)
- monitor.setTextColor(colors.yellow)
- message = "startet "
- end
- monitor.setCursorPos(1 + x_offset + 8, 1 + y_offset + 1 + i)
- monitor.write(message)
- monitor.setTextColor(colors.white)
- end
- end
- local function update_powerline_display(x_offset, y_offset)
- print("Updating powerline display")
- for i = 1, 6 do
- local power = tostring(power_lines[i].getAveragePower())
- if power == "0" then
- monitor.setTextColor(colors.lightGray)
- end
- for j = 1, 5 - #power do
- power = " " .. power
- end
- monitor.setCursorPos(1 + x_offset + 11, 1 + y_offset + 1 + i)
- monitor.write(power)
- monitor.setTextColor(colors.white)
- end
- end
- local function update_clock_display(x_offset, y_offset)
- print("Updating clock display")
- monitor.setCursorPos(1 + x_offset, 1 + y_offset)
- local time = textutils.formatTime(os.time(), true)
- if #time == 4 then
- time = "0" .. time
- end
- monitor.write(time)
- end
- local function update_fuel_display(x_offset, y_offset)
- print("Updating fuel display")
- local fuelInfo = me_system.getItem({name = fuel_type})
- local amount = "0"
- if fuelInfo ~= nil then
- amount = tostring(fuelInfo.amount)
- for i = 1, 5 - #amount do
- amount = " " .. amount
- end
- end
- if fuelInfo == nil or fuelInfo.amount < 64 then
- monitor.setTextColor(colors.red)
- elseif fuelInfo.amount < 256 then
- monitor.setTextColor(colors.yellow)
- else
- monitor.setTextColor(colors.green)
- end
- monitor.setCursorPos(1 + x_offset + 11, 1 + y_offset)
- monitor.write(amount)
- monitor.setTextColor(colors.white)
- end
- -- #endregion
- -- #region Init
- monitor.setTextScale(1)
- monitor.setCursorBlink(false)
- monitor.clear()
- reactors["A"].x_offset = 1
- reactors["A"].y_offset = 1
- reactors["B"].x_offset = 21
- reactors["B"].y_offset = 1
- reactors["C"].x_offset = 1
- reactors["C"].y_offset = 9
- reactors["D"].x_offset = 21
- reactors["D"].y_offset = 9
- local power_lines_x_offset = 43
- local power_lines_y_offset = 9
- local clock_x_offset = 54
- local clock_y_offset = 1
- local fuel_x_offset = 43
- local fuel_y_offset = 3
- for _, id in ipairs({"A", "B", "C", "D"}) do
- if reactors[id].active then
- init_reactor_display(id, reactors[id].x_offset, reactors[id].y_offset)
- end
- end
- init_powerline_display(power_lines_x_offset, power_lines_y_offset)
- init_fuel_display(fuel_x_offset, fuel_y_offset)
- -- #endregion
- local function update_reactor(reactor_id)
- if not reactors[reactor_id].active then
- return
- end
- while true do
- update_reactor_display(reactor_id, reactors[reactor_id].x_offset, reactors[reactor_id].y_offset)
- sleep(10)
- end
- end
- local function update_reactor_A()
- update_reactor("A")
- end
- local function update_reactor_B()
- update_reactor("B")
- end
- local function update_reactor_C()
- update_reactor("C")
- end
- local function update_reactor_D()
- update_reactor("D")
- end
- local function update_powerline()
- while true do
- update_powerline_display(power_lines_x_offset, power_lines_y_offset)
- sleep(10)
- end
- end
- local function update_clock()
- while true do
- update_clock_display(clock_x_offset, clock_y_offset)
- sleep(5)
- end
- end
- local function update_fuel()
- while true do
- update_fuel_display(fuel_x_offset, fuel_y_offset)
- sleep(10)
- end
- end
- print("Starting reactor monitoring")
- parallel.waitForAll(update_reactor_A, update_reactor_B, update_reactor_C, update_reactor_D, update_powerline, update_clock, update_fuel)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement