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 meats following criteria:
- 1: 0_Mr_Redstone_0 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:13"
- --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 clearScreen()
- mon.setBackgroundColour(colors.white)
- mon.clear()
- end
- function config(name)
- cfg = fs.open("config/"..name,"r")
- name = cfg.readAll()
- cfg.close()
- return name
- 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()
- if peripheral.find("tile_thermalexpansion_cell_resonant_name") == nil then
- else cube = peripheral.find("tile_thermalexpansion_cell_resonant_name")
- end
- if peripheral.find("tile_blockcapacitorbank_name") == nil then
- else cube = peripheral.find("tile_blockcapacitorbank_name")
- end
- end
- --PreFace
- --Load Settings
- title = config("title")
- rate = config("rate")
- dynamic = config("dynamic")
- IC2Check()
- mekanismCheck()
- RFAPI()
- --Shows Settings inside control computer
- intro()
- term.setTextColour(colors.red)
- print("Final Settings\n")
- term.setTextColour(colors.blue)
- print("Title: "..title)
- print("Rate: "..rate.." fast/slow")
- 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("ynamic Scaling: false") end
- term.setTextColour(colors.red)
- print("\nIf settings are incorrect. Run setup again")
- print("Hold CTRL+T to stop program")
- --RF/EU label
- if IC2 == true then energyAPI = " EU" else energyAPI = " RF" end
- --Wraps the Peripherals
- mon = peripheral.find("monitor")
- while true do
- --mon.setTextScale(scale)
- monX,monY = mon.getSize()
- width = monX-2 height1 = monY-1 height2 = monY-2
- --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.getStored() 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
- rawPer = curE/maxE
- percent = math.floor((rawPer*100)+0.5)
- bar = math.floor((rawPer*width)+0.5)
- stats = curE
- --Variable for Dynamic Screen Size ( in the loop so you can change the screen size while the program is running)
- if dynamic == "y" then textScale() end
- monX,monY = mon.getSize()
- width = monX-2 height1 = monY-1 height2 = monY-2
- --Centers and Displays Title On Monitor
- clearScreen()
- mon.setBackgroundColour(colors.black)
- mon.setTextColour(colors.lightGray)
- mon.setCursorPos(1,1)
- centerText(string.rep(" ",string.len(title)+2),1)
- centerText(title,1)
- --Monitor Statistics
- mon.setBackgroundColour(colors.white)
- mon.setTextColour(colors.blue)
- if monX >= math.floor(string.len(stats)+18)
- then
- centerText("Current Energy:"..curE..energyAPI,3)
- else
- centerText("Current Energy:",3)
- centerText(" "..curE..energyAPI,4)
- end
- mon.setTextColour(colors.green)
- centerText(percent.."% Full",6)
- --Loading Bar Code Re-Written Much MUCH simpler than before
- mon.setCursorPos(2,height2)
- mon.setBackgroundColour(colors.gray)
- mon.write(string.rep(" ",width))
- mon.setCursorPos(2,height2)
- mon.setBackgroundColour(colors.lime)
- mon.write(string.rep(" ",bar))
- mon.setCursorPos(2,height1)
- mon.setBackgroundColour(colors.gray)
- mon.write(string.rep(" ",width))
- mon.setCursorPos(2,height1)
- mon.setBackgroundColour(colors.lime)
- mon.write(string.rep(" ",bar))
- if rate == "f" then os.sleep(1)
- elseif rate == "s" then os.sleep(5)
- else os.sleep(1) end
- end
Add Comment
Please, Sign In to add comment