Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- settings.load()
- -- #region Setup
- local monitor = peripheral.wrap(settings.get("monitorSide"))
- local modem_side = settings.get("rednet.modemSide")
- local protocol = settings.get("rednet.protocol")
- -- #endregion
- -- #region Functions
- local function init_reactor_display(x_offset, y_offset, reactor)
- print("Initializing reactor display for block " .. reactor.name)
- monitor.setCursorPos(1 + x_offset, 1 + y_offset)
- monitor.write("Block " .. reactor.name)
- if reactor.rods ~= nil then
- for i, _ in ipairs(reactor.rods) do
- monitor.setCursorPos(1 + x_offset + 1, 1 + y_offset + 1 + i)
- monitor.write("Stab " .. i)
- end
- 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 init_clock_display(x_offset, y_offset)
- print("Initializing clock display")
- monitor.setCursorPos(1 + x_offset, 1 + y_offset)
- monitor.write("Datenstand")
- end
- local function update_reactor_display(x_offset, y_offset, reactor)
- print("Updating reactor display for block " .. reactor.name)
- if reactor.rods ~= nil then
- for i, rod in ipairs(reactor.rods) do
- local message = "unknown"
- if rod.state == nil then
- monitor.setTextColor(colors.orange)
- elseif rod.state == "active OK" then
- monitor.setTextColor(colors.green)
- message = "aktiv OK"
- elseif rod.state == "active ERROR" then
- monitor.setTextColor(colors.red)
- message = "aktiv ER"
- elseif rod.state == "inactive OK" then
- monitor.setTextColor(colors.lightGray)
- message = "inaktiv OK"
- elseif rod.state == "deactived ERROR" then
- monitor.setTextColor(colors.red)
- message = "deaktiv ER"
- elseif rod.state == "starting" then
- monitor.setTextColor(colors.yellow)
- message = "startet "
- else
- monitor.setTextColor(colors.orange)
- end
- monitor.setCursorPos(1 + x_offset + 8, 1 + y_offset + 1 + i)
- monitor.write(message)
- monitor.setTextColor(colors.white)
- end
- end
- end
- local function update_powerline_display(x_offset, y_offset, power_lines)
- print("Updating powerline display")
- for i, value in ipairs(power_lines) do
- local power = "0"
- if value.power ~= nil then
- power = tostring(value.power)
- else
- monitor.setTextColor(colors.red)
- power = "ERR"
- end
- if power == "0" then
- monitor.setTextColor(colors.lightGray)
- end
- for _ = 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 + 11, 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, fuel_amount)
- print("Updating fuel display")
- local amount = "0"
- amount = tostring(fuel_amount)
- for i = 1, 5 - #amount do
- amount = " " .. amount
- end
- if fuel_amount < 64 then
- monitor.setTextColor(colors.red)
- elseif fuel_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.setBackgroundColor(colors.black)
- monitor.setCursorBlink(false)
- monitor.clear()
- local offsets = {}
- for _, id in ipairs({"A", "B", "C", "D"}) do
- offsets[id] = {}
- end
- offsets["A"].x_offset = 1
- offsets["A"].y_offset = 1
- offsets["B"].x_offset = 21
- offsets["B"].y_offset = 1
- offsets["C"].x_offset = 1
- offsets["C"].y_offset = 9
- offsets["D"].x_offset = 21
- offsets["D"].y_offset = 9
- local power_lines_x_offset = 43
- local power_lines_y_offset = 9
- local clock_x_offset = 43
- local clock_y_offset = 1
- local fuel_x_offset = 43
- local fuel_y_offset = 3
- rednet.open(modem_side)
- -- #endregion
- local function update_display()
- local id, msg = rednet.receive(protocol, 12)
- if msg == nil then
- print("No updates recieved")
- monitor.setBackgroundColor(colors.red)
- monitor.clear()
- monitor.setTextScale(3)
- monitor.setCursorPos(6, 4)
- monitor.write("NO DATA ...")
- monitor.setBackgroundColor(colors.black)
- return
- end
- monitor.clear()
- monitor.setTextScale(1)
- init_clock_display(clock_x_offset, clock_y_offset)
- update_clock_display(clock_x_offset, clock_y_offset)
- if msg.fuel ~= nil then
- init_fuel_display(fuel_x_offset, fuel_y_offset)
- update_fuel_display(fuel_x_offset, fuel_y_offset, msg.fuel)
- end
- if msg.power_lines ~= nil then
- init_powerline_display(power_lines_x_offset, power_lines_y_offset)
- update_powerline_display(power_lines_x_offset, power_lines_y_offset, msg.power_lines)
- end
- if msg.reactors ~= nil then
- for reactor_id, reactor in pairs(msg.reactors) do
- init_reactor_display(offsets[reactor_id].x_offset, offsets[reactor_id].y_offset, reactor)
- update_reactor_display(offsets[reactor_id].x_offset, offsets[reactor_id].y_offset, reactor)
- end
- end
- end
- print("Starting reactor monitoring")
- while true do
- update_display()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement