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.wrap("back") == nil then
- else cube = peripheral.wrap("back")
- IC2 = 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
- function timeLeft(tickspersec, left)
- local time = math.floor(left/tickspersec)
- local min = math.floor(time/20/60)
- if min < 0 then min = min * -1 end
- return(min)
- 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")
- storage = tonumber(config("storage")) or 0
- side = config("side")
- bundled = config("bundled")
- options = config("options")
- IC2Check()
- --Shows Settings inside control computer
- intro()
- term.setTextColour(colors.red)
- print("Final Settings")
- term.setTextColour(colors.blue)
- print(" Title: "..title)
- print(" Total storage: " ..storage)
- if rate == "f" then print(" Refresh Rate: fast") else print(" Refresh Rate: slow") 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 = " RF" else energyAPI = " RF" end
- if IC2 == true then energyAPI_ = "RF" 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
- maxE = storage
- curE = cube.getEnergyStored() or 1
- mbtq = ""
- ebtq = ""
- percent = math.floor(((curE/maxE)*100)+0.5)
- bar = math.floor(((curE/maxE)*(monX-2))+0.5)
- stats = curE
- statsmax = maxE
- --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
- --Monitor Statistics
- --[[if maxE >= 1000000 and maxE <= 1000000000 then
- statsmax = math.floor(stats/1000)
- statsmax = (stats/1000)
- ebtq = " M"
- else]]if maxE >= 1000000000 and maxE <= 1000000000000 then
- statsmax = math.floor(stats/1000000)
- statsmax = (stats/1000)
- ebtq = " B"
- elseif maxE >= 1000000000000 and maxE <= 1000000000000000 then
- statsmax = math.floor(stats/1000000000)
- statsmax = (stats/1000)
- ebtq = " T"
- elseif maxE >= 1000000000000000 then
- statsmax = math.floor(stats/1000000000000)
- statsmax = (stats/1000)
- ebtq = " Q"
- elseif maxE <= 1000000 then ebtq = " "
- end
- mon.setBackgroundColour(convert(colorMB))
- mon.setTextColour(convert(colorST))
- if curE >= 1000000 then eAPI = energyAPI_ else eAPI = energyAPI end
- centerText(stats..mbtq..eAPI.." / "..statsmax..ebtq..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()
- T_Left = ""
- Suffix = ""
- if E_Change == 0 then T_Left = "Storage Full" else T_Left = timeLeft(E_Change, curE) end
- if E_Change == 0 then T_Left = "Storage Full" elseif E_Change <= 0 then Suffix = " Min Left!" elseif E_Change >= 0 then T_Left = "Charging" end
- 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(T_Left..Suffix,6,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
Add Comment
Please, Sign In to add comment