Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Wireless BigReactor Control
- -- by SparkyBearBomb
- -- Original by jaranvil aka jared314
- --
- -- feel free to use and/or modify this code
- --
- -----------------------------------------------
- -- Wireless Reactor Control - Version History
- --
- --
- -- Version 1.1 - 26.12.2020
- -- - original program forked from ELJptBRk
- --
- --peripherals
- local modem
- local mon
- local version = 3.0
- --monitor size
- local monX
- local monY
- term.clear()
- -------------------FORMATTING-------------------------------
- function clear()
- mon.setBackgroundColor(colors.black)
- mon.clear()
- mon.setCursorPos(1,1)
- end
- --display text on computer's terminal screen
- function draw_text_term(x, y, text, text_color, bg_color)
- term.setTextColor(text_color)
- term.setBackgroundColor(bg_color)
- term.setCursorPos(x,y)
- write(text)
- end
- --display text text on monitor, "mon" peripheral
- function draw_text(x, y, text, text_color, bg_color)
- mon.setBackgroundColor(bg_color)
- mon.setTextColor(text_color)
- mon.setCursorPos(x,y)
- mon.write(text)
- end
- --draw line on computer terminal
- function draw_line(x, y, length, color)
- mon.setBackgroundColor(color)
- mon.setCursorPos(x,y)
- mon.write(string.rep(" ", length))
- end
- --draw line on computer terminal
- function draw_line_term(x, y, length, color)
- term.setBackgroundColor(color)
- term.setCursorPos(x,y)
- term.write(string.rep(" ", length))
- end
- -- Round Decimal Numbers
- function roundNumber(num, n)
- local mult = 10^(n or 0)
- return math.floor(num * mult + 0.5) / mult
- end
- --create progress bar
- --draws two overlapping lines
- --background line of bg_color
- --main line of bar_color as a percentage of minVal/maxVal
- function progress_bar(x, y, length, minVal, maxVal, bar_color, bg_color)
- draw_line(x, y, length, bg_color) --backgoround bar
- local barSize = math.floor((minVal/maxVal) * length)
- draw_line(x, y, barSize, bar_color) --progress so far
- end
- --create status bar
- --draws three overlapping lines
- --background line of bg_color
- function status_bar(x, y, length, minVal, medVal, maxVal, bar_color1, bar_color2, bg_color)
- draw_line(x, y, length, bg_color) --backgoround bar
- local barSize1 = math.floor((medVal/maxVal) * length)
- local barSize2 = math.floor((minVal/maxVal) * length)
- draw_line(x, y, barSize1, bar_color1) --progress so far
- draw_line(x, y, barSize2, bar_color2) --progress so far
- end
- --same as above but on the computer terminal
- function progress_bar_term(x, y, length, minVal, maxVal, bar_color, bg_color)
- draw_line_term(x, y, length, bg_color) --backgoround bar
- local barSize = math.floor((minVal/maxVal) * length)
- draw_line_term(x, y, barSize, bar_color) --progress so far
- end
- --header and footer bars on monitor
- function menu_bar()
- draw_line(1, 1, monX, colors.purple)
- draw_text(2, 1, " Wireless Reactor Receiver", colors.white, colors.purple)
- draw_line(1, 26, monX, colors.purple)
- draw_text(2, 26, " Wireless Reactor Receiver", colors.white, colors.purple)
- end
- --basic popup screen with title bar and exit button
- function popup_screen(y, title, height)
- clear()
- menu_bar()
- draw_line(4, y, 22, colors.purple)
- draw_line(25, y, 1, colors.red)
- for counter = y+1, height+y do
- draw_line(4, counter, 22, colors.white)
- end
- draw_text(25, y, "X", colors.white, colors.red)
- draw_text(5, y, title, colors.white, colors.purple)
- end
- --write settings to config file
- function save_config()
- sw = fs.open("config.txt", "w")
- sw.writeLine(version)
- sw.writeLine(auto_string)
- sw.writeLine(on)
- sw.writeLine(off)
- sw.writeLine(auto_rods)
- sw.writeLine(auto_rf)
- sw.close()
- end
- --read settings from file
- function load_config()
- sr = fs.open("config.txt", "r")
- version = tonumber(sr.readLine())
- auto_string = sr.readLine()
- on = tonumber(sr.readLine())
- off = tonumber(sr.readLine())
- auto_rods = sr.readLine()
- auto_rf = tonumber(sr.readLine())
- sr.close()
- end
- ------------------------END FORMATTING--------------------------
- -- peripheral searching thanks to /u/kla_sch
- function modemSearch()
- local names = peripheral.getNames()
- local i, name
- for i, name in pairs(names) do
- if peripheral.getType(name) == "modem" then
- return peripheral.wrap(name)
- else
- --return null
- end
- end
- end
- function monitorSearch()
- local names = peripheral.getNames()
- local i, name
- for i, name in pairs(names) do
- if peripheral.getType(name) == "monitor" then
- test = name
- return peripheral.wrap(name)
- else
- --return null
- end
- end
- end
- function pharseMessage(message)
- local results = {}
- for pharseData in string.gmatch(message, "[^, ]+") do
- table.insert(results,pharseData)
- end
- active = results[1]
- numRod = results[2]
- energyStored = results[3]
- fuelTemp = results[4]
- caseTemp = results[5]
- fuelQty = results[6]
- wasteQty = results[7]
- fuelMax = results[8]
- rodLevel = results[9]
- energyTick = results[10]
- fluidTick = results[11]
- coolType = results[12]
- coolQty = results[13]
- fluidType = results[14]
- react = results[15]
- fuelTick = results[16]
- isCooled = results[17]
- sleep(pharseSleep)
- call_homepage()
- end
- -----------------------Settings--------------------------------
- function rf_mode()
- wait = read()
- end
- function steam_mode()
- wait = read()
- end
- function terminal_screen()
- term.clear()
- draw_line_term(1, 1, 55, colors.purple)
- draw_text_term(13, 1, "BigReactor Controls", colors.white, colors.purple)
- draw_line_term(1, 19, 55, colors.purple)
- draw_text_term(13, 19, "by SparkyBearBomb", colors.white, colors.purple)
- draw_text_term(1, 3, "Current program:", colors.white, colors.black)
- draw_text_term(1, 4, "Reactor Control v"..version, colors.blue, colors.black)
- draw_text_term(1, 6, "Installer:", colors.white, colors.black)
- draw_text_term(1, 7, "pastebin.com/ELJptBRk", colors.blue, colors.black)
- draw_text_term(1, 9, "Please give me your feedback, suggestions,", colors.white, colors.black)
- draw_text_term(1, 10, "and errors!", colors.white, colors.black)
- draw_text_term(1, 11, "http://pastebin.com/u/Sparkybearbomb", colors.blue, colors.black)
- end
- --run both homepage() and stop() until one returns
- function call_homepage()
- if stop_function == "terminal_screen" then
- stop_function = "nothing"
- setup_wizard()
- else if stop_function == "monitor_touch" then
- stop_function = "nothing"
- mon_touch()
- end
- end
- end
- --test if the entered monitor and reactor can be wrapped
- function test_configs()
- term.clear()
- draw_line_term(1, 1, 55, colors.purple)
- draw_text_term(10, 1, "BigReactors Controls", colors.white, colors.purple)
- draw_line_term(1, 19, 55, colors.purple)
- draw_text_term(10, 19, "by SparkyBearBomb", colors.white, colors.purple)
- draw_text_term(1, 3, "Searching for a peripherals...", colors.white, colors.black)
- sleep(1)
- modem = modemSearch()
- mon = monitorSearch()
- modem = modemSearch()
- port = 16969
- modem.closeAll()
- modem.open(port)
- draw_text_term(2, 5, "Connecting to reactor...", colors.white, colors.black)
- sleep(0.5)
- if modem == null then
- draw_text_term(1, 8, "Error:", colors.red, colors.black)
- draw_text_term(1, 9, "Could not connect to reactor transmitter", colors.red, colors.black)
- draw_text_term(1, 10, "a Wireless Modem must be connected to the computer", colors.white, colors.black)
- draw_text_term(1, 12, "Press Enter to continue...", colors.gray, colors.black)
- wait = read()
- setup_wizard()
- else
- draw_text_term(27, 5, "success", colors.green, colors.black)
- sleep(0.5)
- end
- draw_text_term(2, 6, "Connecting to monitor...", colors.white, colors.black)
- sleep(0.5)
- if mon == null then
- draw_text_term(1, 7, "Error:", colors.red, colors.black)
- draw_text_term(1, 8, "Could not connect to a monitor. Place a 3x4 advanced monitor", colors.red, colors.black)
- draw_text_term(1, 11, "Press Enter to continue...", colors.gray, colors.black)
- wait = read()
- setup_wizard()
- else
- monX, monY = mon.getSize()
- draw_text_term(27, 6, "success", colors.green, colors.black)
- sleep(0.5)
- end
- draw_text_term(2, 7, "saving configuration...", colors.white, colors.black)
- save_config()
- sleep(0.1)
- draw_text_term(1, 9, "Setup Complete!", colors.green, colors.black)
- sleep(1)
- auto = auto_string == "true"
- end
- ----------------SETUP-------------------------------
- function setup_wizard()
- term.clear()
- draw_text_term(1, 1, "BigReactor Controls v"..version, colors.green, colors.black)
- draw_text_term(1, 2, "Peripheral setup", colors.white, colors.black)
- draw_text_term(1, 4, "Step 1:", colors.green, colors.black)
- draw_text_term(1, 5, "-Place 3 wide x 4 tall advanced monitors next to computer.", colors.white, colors.black)
- draw_text_term(1, 7, "Step 2:", colors.green, colors.black)
- draw_text_term(1, 8, "-Place a wireless modem on this computer", colors.white, colors.black)
- draw_text_term(1, 10, "Press Enter when ready...", colors.gray, colors.black)
- wait = read()
- test_configs()
- end
- function start()
- --if configs exists, load values and test
- if fs.exists("config.txt") then
- load_config()
- test_configs()
- else
- setup_wizard()
- end
- end
- start()
- while true do
- event, side, frequency, replyFrequency, message, distance = os.pullEvent("modem_message")
- pharseMessage(message)
- clear()
- menu_bar()
- terminal_screen()
- --------POWER STAT--------------
- draw_text(2, 3, "Power:", colors.lightGray, colors.black)
- if active == "true" then
- draw_text(9, 3, " ONLINE ", colors.gray, colors.green)
- draw_text(17, 3, " OFFLINE ", colors.black, colors.gray)
- else
- draw_text(9, 3, " ONLINE ", colors.black, colors.gray)
- draw_text(17, 3, " OFFLINE ", colors.gray, colors.red)
- end
- -----------FUEL---------------------
- draw_text(2, 5, "Fuel Level:", colors.lightGray, colors.black)
- local maxVal = fuelMax
- local waste = wasteQty
- local minVal = fuelQty
- local medVal = waste + minVal
- local percent = math.floor((minVal/maxVal)*100)
- draw_text(15, 5, percent.."%", colors.white, colors.black)
- if percent < 20 then
- status_bar(2, 6, monX-2, minVal, medVal, maxVal, colors.blue, colors.red, colors.gray)
- else if percent < 40 then
- status_bar(2, 6, monX-2, minVal, medVal, maxVal, colors.blue, colors.orange, colors.gray)
- else if percent < 60 then
- status_bar(2, 6, monX-2, minVal, medVal, maxVal, colors.blue, colors.yellow, colors.gray)
- else if percent <= 80 then
- status_bar(2, 6, monX-2, minVal, medVal, maxVal, colors.blue, colors.lime, colors.gray)
- else if percent <= 100 then
- status_bar(2, 6, monX-2, minVal, medVal, maxVal, colors.blue, colors.green, colors.gray)
- end
- end
- end
- end
- end
- -----------ROD HEAT---------------
- draw_text(2, 8, "Fuel Temp:", colors.lightGray, colors.black)
- local maxVal = 2000
- local minVal = math.floor(fuelTemp)
- if minVal < 500 then
- progress_bar(2, 9, monX-2, minVal, maxVal, colors.cyan, colors.gray)
- else if minVal < 1000 then
- progress_bar(2, 9, monX-2, minVal, maxVal, colors.lime, colors.gray)
- else if minVal < 1500 then
- progress_bar(2, 9, monX-2, minVal, maxVal, colors.yellow, colors.gray)
- else if minVal < 2000 then
- progress_bar(2, 9, monX-2, minVal, maxVal, colors.orange, colors.gray)
- else if minVal >= 2000 then
- progress_bar(2, 9, monX-2, 2000, maxVal, colors.red, colors.gray)
- end
- end
- end
- end
- end
- draw_text(15, 8, math.floor(minVal).." C", colors.white, colors.black)
- -----------CASING HEAT---------------
- draw_text(2, 11, "Casing Temp:", colors.lightGray, colors.black)
- local maxVal = 2000
- local minVal = math.floor(caseTemp)
- if minVal < 500 then
- progress_bar(2, 12, monX-2, minVal, maxVal, colors.cyan, colors.gray)
- else if minVal < 1000 then
- progress_bar(2, 12, monX-2, minVal, maxVal, colors.lime, colors.gray)
- else if minVal < 1500 then
- progress_bar(2, 12, monX-2, minVal, maxVal, colors.yellow, colors.gray)
- else if minVal < 2000 then
- progress_bar(2, 12, monX-2, minVal, maxVal, colors.orange, colors.gray)
- else if minVal >= 2000 then
- progress_bar(2, 12, monX-2, 2000, maxVal, colors.red, colors.gray)
- end
- end
- end
- end
- end
- draw_text(15, 11, math.floor(minVal).." C", colors.white, colors.black)
- -------------FUEL CONSUMPTION-------------------
- draw_text(2, 14, "Fuel/Tick:", colors.lightGray, colors.black)
- fuel_usage = fuelTick
- fuelConsumed = roundNumber(fuel_usage, 5)
- draw_text(13, 14, fuelConsumed.." mB/T", colors.white, colors.black)
- -------------OUTPUT-------------------
- if isCooled == "true" then
- draw_text(2, 16, "mB/tick:", colors.lightGray, colors.black)
- mbt = math.floor(fluidTick)
- draw_text(13, 16, mbt.." mB/t", colors.white, colors.black)
- else
- draw_text(2, 16, "RF/Tick:", colors.lightGray, colors.black)
- rft = math.floor(energyTick)
- draw_text(13, 16, rft.." RF/T", colors.white, colors.black)
- end
- ------------STORAGE------------
- energy_stored = energyStored
- if isCooled == "true" then
- draw_text(2, 18, "mB Stored:", colors.lightGray, colors.black)
- fluid_stored = coolQty
- fluid_max = 10000000
- fluid_stored_percent = math.floor((fluid_stored/fluid_max)*100)
- draw_text(13, 18, fluid_stored_percent.."% ("..fluid_stored.." mB)", colors.white, colors.black)
- else
- draw_text(2, 18, "RF Stored:", colors.lightGray, colors.black)
- energy_stored_percent = math.floor((energy_stored/10000000)*100)
- local maxVal = 100
- local minVal = energy_stored_percent
- draw_text(13, 18, energy_stored_percent.."% ("..energy_stored.." RF)", colors.white, colors.black)
- progress_bar(2, 19, monX-2, minVal, maxVal, colors.green, colors.gray)
- end
- ------------CONTROL RODS------------
- draw_text(2, 21, "Control Rods:", colors.lightGray, colors.black)
- draw_text(16, 21, rodLevel.."%", colors.white, colors.black)
- local maxVal = 100
- local minVal = rodLevel
- progress_bar(2, 22, monX-2, minVal, maxVal, colors.cyan, colors.gray)
- end
Advertisement
Add Comment
Please, Sign In to add comment