Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[ Power Monitoring Program Written By: Player_Athena / 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 / 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 Player_Athena / MoJoCreatior as original author]]
- --This program, in it's current state, is an Alpha version and may contain bugs
- local program = "Power Monitor OC:Edition v1.0"
- local title = program --Change this to whatever string you would like to use, by default it just uses the name of the program itself
- --Important!!! DO NOT ALTER IN ANY WAY!! IT WILL BREAK THINGS!
- local component = require("component")
- local thread = require("thread")
- local event = require("event")
- local gpu = component.gpu
- gpu.setResolution(64,20)
- local x,y = gpu.getResolution()
- local deviceRF = {}
- local RF_devices = {}
- local deviceMek = {}
- local Mek_devices = {}
- local deviceIC2 = {}
- local IC2_devices = {}
- local RF = {[1]={},[2]={},[3]={}}
- local EU = {[1]={},[2]={},[3]={}}
- local kJ = {[1]={},[2]={},[3]={}}
- local fold = 1
- local totFold = 1
- local page = "RF"
- local RFc,RFp,EUc,EUp,kJc,kJp,filled = 0,0,0,0,0,0,0
- --Functions
- local function intro()
- gpu.setForeground(0x00FF00)
- gpu.fill(1,1,x,y, " ")
- gpu.set(3,2, program.." -Written By: Player_Athena")
- os.sleep(1.5)
- end
- local function clear()
- gpu.setForeground(0xFFFFFF)
- gpu.fill(1,1,x,y, "█")
- end
- local function banner(text,y)
- gpu.setForeground(0xFFFFFF)
- gpu.setBackground(0x000000)
- gpu.set((x-#text-3)/2,y, " "..text.." ")
- gpu.set((x-#text-3)/2,y+1, string.rep(" ",#text+4))
- end
- --gather devices into a table
- local function deviceDiscover()
- for address in component.list("v_capacitor") do
- table.insert(deviceRF, address)
- end
- for address in component.list("energy_device") do
- table.insert(deviceRF, address)
- end
- for address in component.list("induction_matrix") do
- table.insert(deviceMek, address)
- end
- for address in component.list("basic_energy_cube") do
- table.insert(deviceMek, address)
- end
- for address in component.list("ic2") do
- table.insert(deviceIC2, address)
- end
- if deviceRF[1] ~= nil then
- for _,address in ipairs(deviceRF) do
- table.insert(RF_devices, component.proxy(address))
- end
- end
- if deviceMek[1] ~= nil then
- for _,address in ipairs(deviceMek) do
- table.insert(Mek_devices, component.proxy(address))
- end
- end
- if deviceIC2[1] ~= nil then
- for _,address in ipairs(deviceIC2) do
- table.insert(IC2_devices, component.proxy(address))
- end
- end
- end
- local function totalDevices()
- if page == "Mek" then return #Mek_devices
- elseif page == "IC2" then return #IC2_devices
- elseif page == "RF" then return #RF_devices
- else return "Error"
- end
- end
- local function percent(m,c)
- local f = math.floor((100/m*c)+0.5)
- return f
- end
- --Logic
- local function totalsBarLogic()
- local RFt,RFc = 0,0
- local EUt,EUc = 0,0
- local kJt,kJc = 0,0
- local filled = 0
- for i=1, #RF_devices do
- RFc = RFc + RF_devices[i].getEnergyStored()
- end
- for i=1, #RF_devices do
- RFt = RFt + RF_devices[i].getMaxEnergyStored()
- end
- for i=1, #IC2_devices do
- EUc = EUc + IC2_devices[i].getEnergy()
- end
- for i=1, #IC2_devices do
- EUt = EUt + IC2_devices[i].getCapacity()
- end
- for i=1, #Mek_devices do
- kJc = kJc + Mek_devices[i].getEnergy()
- end
- for i=1, #Mek_devices do
- kJt = kJt + Mek_devices[i].getMaxEnergy()
- end
- EUc = math.floor(EUc+0.5)
- local RFp = percent(RFt,RFc)
- local EUp = percent(EUt,EUc)
- local kJp = percent(kJt,kJc)
- if page == "RF" then filled = math.floor((0.6*RFp)+0.5) end
- if page == "IC2" then filled = math.floor((0.6*EUp)+0.5) end
- if page == "Mek" then filled = math.floor((0.6*kJp)+0.5) end
- return RFc,RFp,EUc,EUp,kJc,kJp,filled
- end
- local function nextPage()
- if page == "IC2" then
- page = "Mek"
- elseif page == "Mek" then
- page = "RF"
- elseif page == "RF" then
- page = "IC2"
- end
- fold = 1
- gpu.setForeground(0x000000)
- gpu.fill(4,6,16,5, "█")
- gpu.fill(21,6,9,5, "█")
- end
- --Folders
- local function folderRF()
- for i=1, #RF_devices do
- if i <= 5 then
- RF[1][i] = percent(RF_devices[i].getMaxEnergyStored(), RF_devices[i].getEnergyStored())
- end
- if i >= 6 then if i <= 10 then
- RF[2][i-5] = percent(RF_devices[i].getMaxEnergyStored(), RF_devices[i].getEnergyStored())
- end end
- if i >= 11 then if i <= 16 then
- RF[3][i-10] = percent(RF_devices[i].getMaxEnergyStored(), RF_devices[i].getEnergyStored())
- end end
- if i >=17 then
- print("error! too many devices")
- end
- end
- end
- local function folderIC2()
- for i=1, #IC2_devices do
- if i <= 5 then
- EU[1][i] = percent(IC2_devices[i].getCapacity(), IC2_devices[i].getEnergy())
- end
- if i >= 6 then if i <= 10 then
- EU[2][i-5] = percent(IC2_devices[i].getCapacity(), IC2_devices[i].getEnergy())
- end end
- if i >= 11 then if i <= 16 then
- EU[3][i-10] = percent(IC2_devices[i].getCapacity(), IC2_devices[i].getEnergy())
- end end
- if i >=17 then
- print("error! too many devices")
- end
- end
- end
- local function folderMek()
- for i=1, #Mek_devices do
- if i <= 5 then
- kJ[1][i] = percent(Mek_devices[i].getMaxEnergy(), Mek_devices[i].getEnergy())
- end
- if i >= 6 then if i <= 10 then
- kJ[2][i-5] = percent(Mek_devices[i].getMaxEnergy(), Mek_devices[i].getEnergy())
- end end
- if i >= 11 then if i <= 16 then
- kJ[3][i-10] = percent(Mek_devices[i].getMaxEnergy(), Mek_devices[i].getEnergy())
- end end
- if i >=17 then
- print("error! too many devices")
- end
- end
- end
- local function folds()
- if page == "RF" then if RF[3][1] ~= nil then totFold = 3
- elseif RF[2][1] ~= nil then totFold = 2
- else totFold = 1 end end
- if page == "IC2" then if EU[3][1] ~= nil then totFold = 3
- elseif EU[2][1] ~= nil then totFold = 2
- else totFold = 1 end end
- if page == "Mek" then if kJ[3][1] ~= nil then totFold = 3
- elseif kJ[2][1] ~= nil then totFold = 2
- else totFold = 1 end end
- return totFold
- end
- local function foldMe(i)
- if i == "l" then fold = fold-1 end
- if i == "r" then fold = fold+1 end
- if fold == 0 then fold = 3 end
- if fold == 4 then fold = 1 end
- gpu.setForeground(0x000000)
- gpu.fill(4,6,16,5, "█")
- gpu.fill(21,6,9,5, "█")
- end
- --Rendering
- local function selector()
- gpu.setForeground(0x404099)
- if page == "RF" then
- gpu.set(35,8,"█")
- gpu.setForeground(0xFFFFFF)
- gpu.set(36,8,">")
- gpu.setForeground(0x000000)
- gpu.set(35,9,"█>")
- gpu.set(35,10,"█>")
- elseif page == "IC2" then
- gpu.set(35,9,"█")
- gpu.setForeground(0xFFFFFF)
- gpu.set(36,9,">")
- gpu.setForeground(0x000000)
- gpu.set(35,8,"█>")
- gpu.set(35,10,"█>")
- elseif page == "Mek" then
- gpu.set(35,10,"█")
- gpu.setForeground(0xFFFFFF)
- gpu.set(36,10,">")
- gpu.setForeground(0x000000)
- gpu.set(35,8,"█>")
- gpu.set(35,9,"█>")
- end
- end
- local function renderPageBar()
- gpu.setForeground(0x000000)
- gpu.set(41,8,string.rep("█",16))
- gpu.set(41,9,string.rep("█",16))
- gpu.set(41,10,string.rep("█",16))
- gpu.setForeground(0xFF4545)
- gpu.set(41,8,RFp.."% | "..RFc)
- gpu.setForeground(0x4545FF)
- gpu.set(41,9,EUp.."% | "..EUc)
- gpu.setForeground(0x45FF45)
- gpu.set(41,10,kJp.."% | "..kJc)
- if page == "RF" then gpu.setForeground(0xFF4545) end
- if page == "IC2" then gpu.setForeground(0x4545FF) end
- if page == "Mek" then gpu.setForeground(0x45FF45) end
- gpu.fill(3,16,filled,3,"█")
- end
- local function renderFolder()
- if page == "RF" then
- folderRF()
- for i=1, #RF[fold] do
- gpu.setForeground(0x858585)
- gpu.set(6,(5+i),"RF Device:"..i)
- gpu.set(24,(5+i), RF[fold][i].." %")
- end
- end
- if page == "IC2" then
- folderIC2()
- for i=1, #EU[fold] do
- gpu.setForeground(0x858585)
- gpu.set(6,(5+i),"IC2 Device:"..i)
- gpu.set(24,(5+i), EU[fold][i].." %")
- end
- end
- if page == "Mek" then
- folderMek()
- for i=1, #kJ[fold] do
- gpu.setForeground(0x858585)
- gpu.set(6,(5+i),"Mek Device:"..i)
- gpu.set(24,(5+i), kJ[fold][i].." %")
- end
- end
- end
- local function activeScreen()
- --[[gpu.setForeground(0x000000) --Left Menu
- gpu.fill(4,6,16,5, "█")
- gpu.fill(21,6,9,5, "█")]]
- gpu.setForeground(0xFFFFFF)
- gpu.set(25,5, tostring(totalDevices()).." ")
- renderFolder()
- gpu.setForeground(0x909010)
- gpu.set(16,13,fold.."/3")
- selector() --Right Menu
- gpu.setForeground(0x858585) --bar
- gpu.fill(3,16,60,3, "█")
- renderPageBar()
- end
- local function inertScreen()
- clear()
- banner(title,1)
- gpu.setForeground(0x000000) --bar
- gpu.fill(2,15,62,5, "█")
- gpu.setForeground(0x500050) --Left Menu
- gpu.fill(3,4,28,10, "█")
- gpu.setForeground(0x000000)
- gpu.fill(4,5,16,6, "█")
- gpu.fill(21,5,9,6, "█")
- gpu.fill(11,12,12,2, "█")
- gpu.setForeground(0x904510)
- gpu.fill(3,12,8,1,"/")
- gpu.fill(3,13,8,1,"\\")
- gpu.setForeground(0x459010)
- gpu.fill(23,12,8,1,"\\")
- gpu.fill(23,13,8,1,"/")
- gpu.setForeground(0x909010)
- gpu.set(15,12,"PAGE:")
- gpu.setForeground(0xFFFFFF)
- gpu.set(5,5,"Total Devices:")
- gpu.setForeground(0x404099) --Right Menu
- gpu.fill(34,6,28,7, "█")
- gpu.setForeground(0x000000)
- gpu.fill(35,7,26,5, "█")
- gpu.setForeground(0xFF4545)
- gpu.set(37,8,"RF:")
- gpu.setForeground(0x4545FF)
- gpu.set(37,9,"EU:")
- gpu.setForeground(0x45FF45)
- gpu.set(37,10,"kJ:")
- end
- local function finalRender()
- inertScreen()
- while true do
- activeScreen()
- os.sleep(1)
- end
- end
- local function finalTouch()
- while true do
- local junk1,junk2,tx,ty = event.pull("touch")
- if tx >= 37 then if tx <= 58 then if ty >= 6 then if ty <= 12 then
- nextPage()
- activeScreen()
- end end end end
- if tx >= 3 then if tx <= 16 then if ty >= 12 then if ty <= 13 then
- foldMe("l")
- activeScreen()
- end end end end
- if tx >= 18 then if tx <= 30 then if ty >= 12 then if ty <= 13 then
- foldMe("r")
- activeScreen()
- end end end end
- end
- end
- local function finalStartup()
- intro()
- gpu.set(3,4,"Searching for connected devices")
- deviceDiscover()
- gpu.set(3,6,"Search Complete. Please enjoy :D")
- os.sleep(2)
- clear()
- inertScreen()
- end
- local function finalLogic()
- while true do
- RFc,RFp,EUc,EUp,kJc,kJp,filled = totalsBarLogic() --final logic
- os.sleep(1)
- end
- end
- finalStartup()
- thread.create(finalLogic)
- thread.create(finalTouch)
- thread.create(finalRender)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement