Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[ Power Monitoring Program Written By: 0_Mr_Redstone_0 AKA MoJoCreatior
- This code is considered free for use both commercial and private and can be redistributed so long as it meets following criteria:
- 1: Player_Athena and MoJoCreatior are credited as the original authors
- 2: You do not try to take full ownership of the code/written program
- 3: If you modify the code for re-upload you must provide it under the same conditions. as in- Open Source, and credited to me as original author]]
- program = "Power Monitoring Program V:30"
- --Function
- function intro()
- term.setBackgroundColour(colors.white)
- term.clear()
- term.setCursorPos(1,1)
- term.setTextColour(colors.green)
- print(program.." -Written By: 0_Mr_Redstone_0 AKA MoJoCreatior")
- print(" ")
- end
- function centerText(text,yVal)
- length = string.len(text)
- minus = math.floor(monX-length)
- x = math.floor(minus/2)
- mon.setCursorPos(x+1,yVal)
- mon.write(text)
- end
- function centerTextC(text,line,colorB,colorT)
- mon.setBackgroundColour(colorB)
- mon.setTextColour(colorT)
- length = string.len(text)
- minus = math.floor(monX-length)
- x = math.floor(minus/2)
- mon.setCursorPos(x+1,line)
- mon.write(text)
- end
- function clearScreen()
- mon.setBackgroundColour(convert(colorMB))
- mon.clear()
- end
- function config(name)
- if fs.exists("config/"..name) then
- cfg = fs.open("config/"..name,"r")
- name = cfg.readAll()
- cfg.close()
- return name
- else
- fs.delete("startup")
- startup = fs.open("startup","w")
- startup.write('shell.run("setup.lua")')
- startup.close()
- term.setTextColour(colors.red)
- print("ERROR! 404")
- print(name.." config not found")
- term.setTextColour(colors.blue)
- print("rebooting into setup")
- print("3") sleep(1)
- print("2") sleep(1)
- print("1") sleep(1)
- os.reboot()
- end
- end
- function textScale()
- mon.setTextScale(0.5)
- monX,monY = mon.getSize()
- if monX <= 16 or monY <= 11 then mon.setTextScale(0.5) elseif
- monX <= 37 or monY <= 25 then mon.setTextScale(1) elseif
- monX <= 58 or monY <= 39 then mon.setTextScale(1.5) elseif
- monX <= 80 or monY <= 53 then mon.setTextScale(2) elseif
- monX <= 101 or monY <= 68 then mon.setTextScale(2.5) else
- mon.setTextScale(3)
- end
- end
- function IC2Check()
- IC2 = false
- if peripheral.find("mfsu") == nil then
- else cube = peripheral.find("mfsu")
- IC2 = true
- end
- if peripheral.find("mfe") == nil then
- else cube = peripheral.find("mfe")
- IC2 = true
- end
- if peripheral.find("cesu") == nil then
- else cube = peripheral.find("cesu")
- IC2 = true
- end
- if peripheral.find("batbox") == nil then
- else cube = peripheral.find("batbox")
- IC2 = true
- end
- end
- function mekanismCheck()
- mekanism = false
- if peripheral.find("Basic Energy Cube") == nil then
- else cube = peripheral.find("Basic Energy Cube")
- mekanism = true
- end
- if peripheral.find("Advanced Energy Cube") == nil then
- else cube = peripheral.find("Advanced Energy Cube")
- mekanism = true
- end
- if peripheral.find("Elite Energy Cube") == nil then
- else cube = peripheral.find("Elite Energy Cube")
- mekanism = true
- end
- if peripheral.find("Ultimate Energy Cube") == nil then
- else cube = peripheral.find("Ultimate Energy Cube")
- mekanism = true
- end
- if peripheral.find("Induction Matrix") == nil then
- else cube = peripheral.find("Induction Matrix")
- mekanism = true
- end
- end
- function RFAPI()
- rfAPI = false
- if peripheral.find("tile_thermalexpansion_cell_resonant_name") == nil then
- else cube = peripheral.find("tile_thermalexpansion_cell_resonant_name")
- rfAPI = true
- end
- if peripheral.find("tile_blockcapacitorbank_name") == nil then
- else cube = peripheral.find("tile_blockcapacitorbank_name")
- rfAPI = true
- end
- if peripheral.find("extrautils_generatorsolar") == nil then
- else cube = peripheral.find("extrautils_generatorsolar")
- rfAPI = true
- end
- end
- function convert(color)
- if color == "white" then color = colors.white end
- if color == "orange" then color = colors.orange end
- if color == "magenta" then color = colors.magenta end
- if color == "lightBlue" then color = colors.lightBlue end
- if color == "yellow" then color = colors.yellow end
- if color == "lime" then color = colors.lime end
- if color == "pinkgray" then color = colors.pinkgray end
- if color == "gray" then color = colors.gray end
- if color == "lightGray" then color = colors.lightGray end
- if color == "cyan" then color = colors.cyan end
- if color == "purple" then color = colors.purple end
- if color == "blue" then color = colors.blue end
- if color == "brown" then color = colors.brown end
- if color == "green" then color = colors.green end
- if color == "red" then color = colors.red end
- if color == "black" then color = colors.black end
- return color
- end
- function eChange()
- newE = curE
- local difference = (newE-oldE)
- oldE = curE
- if rate == "f" then dividend = 20 elseif rate == "s" then dividend = 100 end
- local change = math.floor(difference/dividend)
- return(change)
- end
- --PreFace
- --Color Coneverter
- --Load Settings
- title = config("title")
- rate = config("rate")
- dynamic = config("dynamic")
- colorTB = config("colorTB")
- colorTT = config("colorTT")
- colorMB = config("colorMB")
- colorST = config("colorST")
- colorBT = config("colorBT")
- colorBE = config("colorBE")
- colorBF = config("colorBF")
- colorPR = config("colorPR")
- colorPos = config("colorPos")
- colorNeg = config("colorNeg")
- redstone = config("redstone")
- side = config("side")
- bundled = config("bundled")
- options = config("options")
- IC2Check()
- mekanismCheck()
- RFAPI()
- --Shows Settings inside control computer
- intro()
- term.setTextColour(colors.red)
- print("Final Settings")
- term.setTextColour(colors.blue)
- print(" Title: "..title)
- if rate == "f" then print(" Refresh Rate: fast") else print(" Refresh Rate: slow") end
- if mekanism == true then print(" Mekanism: true") else print(" Mekanism: false") end
- if IC2 == true then print(" IC2: true") else print(" IC2: false") end
- if dynamic == "y" then print(" Dynamic Scaling: true") else print(" Dynamic Scaling: false") end
- if options == "y" then
- term.setTextColour(colors.red)
- print("\nAdvanced Options")
- term.setTextColour(colors.blue)
- print(" Title Text Color: "..colorTT)
- print(" Title Background: "..colorTB)
- print(" Background Color: "..colorMB)
- print(" Statistics Color: "..colorST)
- print(" Bar Percent Text: "..colorBT)
- print(" Bars Empty Color: "..colorBE)
- print(" Bar Filled Color: "..colorBF)
- print(" Positive Change: "..colorPos)
- print(" Negative Change: "..colorNeg)
- end
- term.setTextColour(colors.gray)
- print("Million < Billion < Trillion < Quadrillion")
- term.setTextColour(colors.red)
- print("\nIf settings are incorrect. Run setup.lua")
- print("Hold CTRL+T to stop program")
- --RF/EU label
- if IC2 == true then energyAPI = " EU" else energyAPI = " RF" end
- if IC2 == true then energyAPI_ = "EU" else energyAPI_ = "RF" end
- --Wraps the Monitor
- mon = peripheral.find("monitor")
- monX,monY = mon.getSize()
- textScale()
- monX,monY = mon.getSize()
- oldE,newE,curE,maxE = 0,0,0,0
- while true do
- if dynamic == "y" then textScale() end
- --Main Program
- --Variables for Calculations
- if mekanism == true then maxE = cube.getMaxEnergy() or 1
- elseif IC2 == true then maxE = cube.getEUCapacity() or 1
- else maxE = cube.getMaxEnergyStored() or 1
- end
- if mekanism == true then curE = cube.getEnergy() or 1
- elseif IC2 == true then curE = cube.getEUStored() or 1
- else curE = cube.getEnergyStored() or 1
- end
- if mekanism == true then
- maxE = math.floor(maxE/2.5)
- curE = math.floor(curE/2.5)
- end
- percent = math.floor(((curE/maxE)*100)+0.5)
- bar = math.floor(((curE/maxE)*(monX-2))+0.5)
- stats = curE
- --Redstone Output
- if redstone == "y" then
- if bundled == "1" then
- if percent >= 99 then
- rs.setBundledOutput(side,convert(colorPR))
- else rs.setBundledOutput(side,0)
- end
- else
- if percent >= 99 then
- rs.setOutput(side,true)
- else rs.setOutput(side,false)
- end
- end
- end
- --Centers and Displays Title On Monitor
- clearScreen()
- mon.setBackgroundColour(colors.black)
- mon.setTextColour(colors.lightGray)
- mon.setCursorPos(1,1)
- centerTextC(string.rep(" ",string.len(title)+2),1,convert(colorTB),convert(colorTT))
- centerTextC(title,1,convert(colorTB),convert(colorTT))
- --Monitor Statistics
- --[[if curE >= 1000000 and curE <= 1000000000 then
- stats = math.floor(stats/1000)
- stats = (stats/1000)
- mbtq = " M"
- else]]if curE >= 1000000000 and curE <= 1000000000000 then
- stats = math.floor(stats/1000000)
- stats = (stats/1000)
- mbtq = " B"
- elseif curE >= 1000000000000 and curE <= 1000000000000000 then
- stats = math.floor(stats/1000000000)
- stats = (stats/1000)
- mbtq = " T"
- elseif curE >= 1000000000000000 then
- stats = math.floor(stats/1000000000000)
- stats = (stats/1000)
- mbtq = " Q"
- elseif curE <= 1000000 then mbtq = " "
- end
- mon.setBackgroundColour(convert(colorMB))
- mon.setTextColour(convert(colorST))
- if curE >= 1000000 then eAPI = energyAPI_ else eAPI = energyAPI end
- centerText(stats..mbtq..eAPI,3)
- --[[
- if monX >= math.floor(string.len(stats)+9)
- then
- centerText("Total:"..stats..mbtq..eAPI,3)
- else
- centerText("Total:",3)
- centerText(stats..mbtq..eAPI,4)
- end
- ]]
- --Change Per Tick Calculator and Display
- e_Change = eChange()
- if e_Change >= 0 then sign = "+" elseif e_Change <= 0 then sign = "-" end
- if e_Change >= 0 then signC = colorPos elseif e_Change <= 0 then signC = colorNeg end
- centerTextC(sign..e_Change..energyAPI.."/t",5,convert(colorMB),convert(signC))
- centerTextC(percent.."% Full",monY-3,convert(colorMB),convert(colorBT))
- --Loading Bar Code Re-Written Much MUCH simpler than before
- mon.setCursorPos(2,monY-2)
- mon.setBackgroundColour(convert(colorBE))
- mon.write(string.rep(" ",monX-2))
- mon.setCursorPos(2,monY-2)
- mon.setBackgroundColour(convert(colorBF))
- mon.write(string.rep(" ",bar))
- mon.setCursorPos(2,monY-1)
- mon.setBackgroundColour(convert(colorBE))
- mon.write(string.rep(" ",monX-2))
- mon.setCursorPos(2,monY-1)
- mon.setBackgroundColour(convert(colorBF))
- mon.write(string.rep(" ",bar))
- if rate == "f" then os.sleep(1)
- elseif rate == "s" then os.sleep(5)
- else os.sleep(5) end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement