Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- /---------------------------------\
- | Big Reactors Status Display |
- \---------------------------------/
- ]]
- -- Config
- -- This is the side on which your reactor is connected
- local reactor_side = "BigReactors-Reactor_0"
- -- This is the side on which your monitor is connected
- local monitor_side = "right"
- -- Target Core Temperature
- local target_temp = 900
- -- Hysteresis +/- temperature offset before controlling rods
- local hysteresis = 30
- -- If the reactor is not connected, exit the program
- if not peripheral.isPresent(reactor_side) then
- print("Please check, that the reactor is connected to the same side as in your config!")
- return
- end
- -- If the monitor is not connected, exit
- if not peripheral.isPresent(monitor_side) then
- print("Please check, that the monitor is connected to the same side as in your config!")
- return
- end
- -- Wrap the peripherals
- local reactor = peripheral.wrap(reactor_side)
- while not reactor.getConnected() do sleep(10) end
- local monitor = peripheral.wrap(monitor_side)
- monitor.setCursorPos(1,9)
- print("The program is now running on the monitor!")
- -- BEGIN FUNCTIONS PART
- function clear()
- monitor.clear()
- monitor.setTextColor(colors.white)
- monitor.setBackgroundColor(colors.black)
- monitor.setCursorPos(1, 1)
- end
- function resetColors()
- monitor.setTextColor(colors.white)
- monitor.setBackgroundColor(colors.black)
- end
- function reactortoggle()
- if reactor.getActive() then
- reactor.setActive(false)
- else reactor.setActive(true)
- end
- end
- function newLine()
- local x, y = monitor.getCursorPos()
- monitor.setCursorPos(1, y+1)
- end
- function drawUI()
- monitor.write("/-------------------------------------\\")
- for x = 2, 11, 1 do
- monitor.setCursorPos(1, x)
- monitor.write("|")
- monitor.setCursorPos(29, x)
- monitor.write("|")
- monitor.setCursorPos(39, x)
- monitor.write("|")
- end
- monitor.setCursorPos(2, 3)
- monitor.write("---------------------------")
- monitor.setCursorPos(2, 5)
- monitor.write("---------------------------")
- monitor.setCursorPos(2, 8)
- monitor.write("---------------------------")
- monitor.setCursorPos(30, 8)
- monitor.write("---------")
- monitor.setCursorPos(1, 12)
- monitor.write("\\-------------------------------------/")
- end
- local function Button(
- width,
- height,
- label,
- backgroundColorNormal,
- backgroundColorPressed,
- textColorNormal,
- textColorPressed,
- hasBorder,
- borderColorNormal,
- borderColorPressed,
- startColumn,
- startRow,
- isPressed,
- defaultBackgroundColor,
- defaultTextColor
- )
- local button = {}
- button.height=height or 1
- button.width=width or 1
- button.label=label or ""
- button.backgroundColorNormal=backgroundColorNormal or colors.black
- button.backgroundColorPressed=backgroundColorPressed or colors.white
- button.textColorNormal=textColorNormal or colors.white
- button.textColorPressed=textColorPressed or colors.black
- button.hasBorder = hasBorder or false
- button.borderColorNormal = borderColorNormal or backGroundColorNormal
- button.borderColorPressed = borderColorPressed or backGroundColorPressed
- button.defaultBackgroundColor = defaultBackgroundColor or colors.black
- button.defaultTextColor = defaultTextColor or colors.white
- button.startColumn = startColumn or 1
- button.startRow = startRow or 1
- button.isPressed=isPressed or false
- function button.press()
- button.isPressed = not button.isPressed
- end
- function button.clicked(column,row)
- return (column >= button.startColumn and column < button.startColumn + button.width and row >= button.startRow and row < button.startRow + button.height)
- end
- function button.draw(display,isPressed,startColumn,startRow)
- button.startColumn = startColumn or button.startColumn
- button.startRow = startRow or button.startRow
- display = display or term
- if isPressed == false or isPressed then
- button.isPressed = isPressed
- else isPressed = button.isPressed
- end
- local width = button.width
- local height = button.height
- startRow = button.startRow
- startColumn = button.startColumn
- local label = button.label
- local labelPad = 2
- -- set border params and draw border if hasBorder
- if button.hasBorder == true then
- -- button must be at least 3x3, if not, make it so
- if width < 3 then
- width = 3
- end
- if height < 3 then
- height = 3
- end
- -- set border colors
- if not isPressed then
- if not display.isColor() then
- display.setBackgroundColor(colors.white)
- else
- display.setBackgroundColor(button.borderColorNormal)
- end
- else
- if not display.isColor() then
- display.setBackgroundColor(colors.white)
- else
- display.setBackgroundColor(button.borderColorPressed)
- end
- end
- -- draw button border (inset)
- display.setCursorPos(startColumn,startRow)
- display.write(string.rep(" ",width))
- for row = 2,height-1 do
- display.setCursorPos(startColumn,button.startRow+row -1)
- display.write(" ")
- display.setCursorPos(startColumn+width -1 ,startRow + row-1)
- display.write(" ")
- end
- display.setCursorPos(startColumn,startRow+height-1)
- display.write(string.rep(" ",width))
- -- reset startColumn,startRow,width,column to inset button and label
- startColumn=startColumn+1
- startRow = startRow +1
- width = width - 2
- height = height - 2
- end
- --set button background and text colors
- if not isPressed then
- if not display.isColor() then
- display.setBackgroundColor(colors.black)
- display.setTextColor(colors.white)
- else
- display.setBackgroundColor(button.backgroundColorNormal)
- display.setTextColor(button.textColorNormal)
- end
- else
- if not display.isColor() then
- display.setBackgroundColor(colors.white)
- display.setTextColor(colors.black)
- else
- display.setBackgroundColor(button.backgroundColorPressed)
- display.setTextColor(button.textColorPressed)
- end
- end
- -- draw button background (will be inside border if there is one)
- for row = 1,height do
- --print(tostring(startColumn)..","..tostring(startRow-row))
- display.setCursorPos(startColumn,startRow + row -1)
- display.write(string.rep(" ",width))
- end
- -- prepare label, truncate label if necessary
- -- prepare label, truncate label if necessary
- if width < 3 then
- labelPad = 0
- end
- if #label > width - labelPad then
- label = label:sub(1,width - labelPad)
- end
- -- draw label
- display.setCursorPos(startColumn + math.floor((width - #label)/2),startRow + math.floor((height-1)/2))
- display.write(label)
- display.setBackgroundColor(button.defaultBackgroundColor)
- display.setTextColor(button.defaultTextColor)
- end
- button.toggle = function ()
- button.isPressed = not button.isPressed
- return button.isPressed
- end
- return button
- end
- ----------------------------------------------------------------------
- buttons = {}
- buttons.on= Button(9,3," ON/OFF",colors.red,colors.lime,colors.black,colors.white,false,colors.green,colors.pink,30,3,false,nil,nil)
- ----------------------------------------------------------------------
- -- END FUNCTIONS PART
- -- Repeat forever
- function update()
- while true do
- -- Clear the terminal---------------------------------------------------------------------
- clear()
- -- Draw the basic UI layout
- drawUI()
- -- Reactor status
- active = reactor.getActive()
- monitor.setCursorPos(3, 2)
- monitor.write("Status: ")
- if active then
- monitor.setBackgroundColor(colors.green)
- monitor.setTextColor(colors.white)
- monitor.write("ACTIVE (Auto)")
- else
- monitor.setBackgroundColor(colors.red)
- monitor.setTextColor(colors.white)
- monitor.write("INACTIVE")
- end
- -- End Reactor status
- resetColors()
- monitor.setCursorPos(3, 4)
- -- Steam Output
- energy = reactor.getHotFluidProducedLastTick()
- -- Print out the reactor status
- monitor.setTextColor(colors.white)
- monitor.write("Steam Output: ")
- monitor.setTextColor(colors.yellow)
- monitor.write(energy)
- monitor.write(" mB/T")
- -- END reactor status
- -- Temperatures
- monitor.setCursorPos(3, 6)
- monitor.setTextColor(colors.red)
- monitor.write("Core Temp:")
- monitor.setCursorPos(15, 6)
- monitor.setTextColor(colors.white)
- monitor.write("| Power Level:")
- monitor.setCursorPos(15, 7)
- monitor.write("|")
- local coreTemp = math.floor(reactor.getFuelTemperature())
- local powerLevel = 100 - math.floor(reactor.getControlRodLevel(1))
- local controlRods = reactor.getControlRodLevel(1)
- monitor.setCursorPos(3, 7)
- monitor.setTextColor(colors.cyan)
- monitor.write(coreTemp .. " C")
- monitor.setCursorPos(17, 7)
- monitor.write(powerLevel .. " %")
- if active then --Only move control rods when reactor is active
- -- If core temp rises above the target_temp + hysteresis value, lower control rods
- if coreTemp >= (target_temp + hysteresis) then
- reactor.setAllControlRodLevels(controlRods + 1)
- end
- -- If core temp falls below the target_temp - hysteresis value, raise control rods
- if coreTemp <= (target_temp - hysteresis) then
- reactor.setAllControlRodLevels(controlRods - 1)
- end
- -- Avoid critial core temp
- if coreTemp >= 1500 then
- reactor.setAllControlRodLevels(100)
- end
- end
- -- END temperature control
- -- Waste, Water and fuel status
- local waste = math.floor(reactor.getFuelConsumedLastTick()*1000+0.5)/1000
- local fuel = math.floor((100/reactor.getFuelAmountMax()) * reactor.getFuelAmount())
- local water = math.floor((100/50000) * reactor.getCoolantAmount())
- monitor.setTextColor(colors.white)
- monitor.setCursorPos(3, 9)
- monitor.write("Burnup Rate:")
- monitor.setCursorPos(15, 9)
- monitor.write("| Fuel Left:")
- monitor.setCursorPos(3, 10)
- monitor.setTextColor(colors.yellow)
- monitor.write(waste)
- monitor.setTextColor(colors.white)
- monitor.setCursorPos(15, 10)
- monitor.write("|")
- monitor.setCursorPos(17, 10)
- monitor.setTextColor(colors.red)
- monitor.write(fuel .. " %")
- monitor.setCursorPos(31, 9)
- monitor.setTextColor(colors.cyan)
- monitor.write("Water %")
- monitor.setCursorPos(32, 10)
- monitor.setTextColor(colors.lightBlue)
- monitor.write(water)
- -- END Waste and Fuel Status
- for key,button in pairs(buttons) do
- button.draw(monitor)
- end
- sleep(0.5)
- end
- end
- function interrupt()
- while true do
- event ={os.pullEvent()}
- if event[1] =="monitor_touch" then
- for key,button in pairs(buttons) do
- if button.clicked(event[3],event[4]) then -- column,row
- reactortoggle()
- button.toggle()
- break -- we found one, so we don't need to keep looking
- end
- end
- end
- end
- end
- parallel.waitForAny(update, interrupt)
- -- Sleep for 1 second
- --end
Add Comment
Please, Sign In to add comment