MoJoCreatior

Power Monitor Program V:13

Feb 11th, 2016
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.64 KB | None | 0 0
  1. --[[  Power Monitoring Program Written By: 0_Mr_Redstone_0  AKA  MoJoCreatior
  2. This code is considered free for use both commercial and private and can be redistributed so long as it meats following criteria:
  3. 1: 0_Mr_Redstone_0 and MoJoCreatior are credited as the original authors
  4. 2: You do not try to take full ownership of the code/written program
  5. 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]]
  6.  
  7. program = "Power Monitoring Program V:13"
  8.  
  9. --Function
  10.   function intro()
  11.     term.setBackgroundColour(colors.white)
  12.     term.clear()
  13.     term.setCursorPos(1,1)
  14.     term.setTextColour(colors.green)
  15.     print(program.." -Written By: 0_Mr_Redstone_0  AKA  MoJoCreatior")
  16.     print(" ")
  17.   end
  18.  
  19.   function centerText(text,yVal)
  20.     length = string.len(text)
  21.     minus = math.floor(monX-length)
  22.     x = math.floor(minus/2)
  23.     mon.setCursorPos(x+1,yVal)
  24.     mon.write(text)
  25.   end
  26.  
  27.   function clearScreen()
  28.     mon.setBackgroundColour(colors.white)
  29.     mon.clear()
  30.   end
  31.  
  32.   function config(name)
  33.     cfg = fs.open("config/"..name,"r")
  34.     name = cfg.readAll()
  35.     cfg.close()
  36.     return name
  37.   end
  38.  
  39.   function textScale()
  40.     mon.setTextScale(0.5)
  41.     monX,monY = mon.getSize()
  42.     if monX <= 16 or monY <= 11 then mon.setTextScale(0.5) elseif
  43.       monX <= 37 or monY <= 25 then mon.setTextScale(1) elseif
  44.       monX <= 58 or monY <= 39 then mon.setTextScale(1.5) elseif
  45.       monX <= 80 or monY <= 53 then mon.setTextScale(2) elseif
  46.       monX <= 101 or monY <= 68 then mon.setTextScale(2.5) else
  47.       mon.setTextScale(3)
  48.     end  
  49.   end
  50.  
  51.   function IC2Check()
  52.     IC2 = false
  53.     if peripheral.find("mfsu") == nil then
  54.       else cube = peripheral.find("mfsu")
  55.       IC2 = true
  56.     end
  57.     if peripheral.find("mfe") == nil then
  58.       else cube = peripheral.find("mfe")
  59.       IC2 = true
  60.     end
  61.     if peripheral.find("cesu") == nil then
  62.       else cube = peripheral.find("cesu")
  63.       IC2 = true
  64.     end
  65.     if peripheral.find("batbox") == nil then
  66.       else cube = peripheral.find("batbox")
  67.       IC2 = true
  68.     end
  69.   end
  70.  
  71.   function mekanismCheck()
  72.     mekanism = false
  73.     if peripheral.find("Basic Energy Cube") == nil then
  74.       else cube = peripheral.find("Basic Energy Cube")
  75.       mekanism = true
  76.     end
  77.     if peripheral.find("Advanced Energy Cube") == nil then
  78.       else cube = peripheral.find("Advanced Energy Cube")
  79.       mekanism = true
  80.     end
  81.     if peripheral.find("Elite Energy Cube") == nil then
  82.       else cube = peripheral.find("Elite Energy Cube")
  83.       mekanism = true
  84.     end
  85.     if peripheral.find("Ultimate Energy Cube") == nil then
  86.       else cube = peripheral.find("Ultimate Energy Cube")
  87.       mekanism = true
  88.     end
  89.     if peripheral.find("Induction Matrix") == nil then
  90.       else cube = peripheral.find("Induction Matrix")
  91.       mekanism = true
  92.     end
  93.   end
  94.  
  95.   function RFAPI()
  96.     if peripheral.find("tile_thermalexpansion_cell_resonant_name") == nil then
  97.       else cube = peripheral.find("tile_thermalexpansion_cell_resonant_name")
  98.     end
  99.     if peripheral.find("tile_blockcapacitorbank_name") == nil then
  100.       else cube = peripheral.find("tile_blockcapacitorbank_name")
  101.     end
  102.   end
  103.  
  104.  
  105. --PreFace
  106.   --Load Settings
  107.     title = config("title")
  108.     rate = config("rate")
  109.     dynamic = config("dynamic")
  110.     IC2Check()
  111.     mekanismCheck()
  112.     RFAPI()
  113.    
  114.   --Shows Settings inside control computer
  115.     intro()
  116.     term.setTextColour(colors.red)
  117.     print("Final Settings\n")
  118.     term.setTextColour(colors.blue)
  119.     print("Title: "..title)
  120.     print("Rate: "..rate.." fast/slow")
  121.     if mekanism == true then print("Mekanism: true") else print("Mekanism: false") end
  122.     if IC2 == true then print("IC2: true") else print("IC2: false") end
  123.     if dynamic == "y" then print("Dynamic Scaling: true") else print("ynamic Scaling: false") end
  124.     term.setTextColour(colors.red)
  125.     print("\nIf settings are incorrect. Run setup again")
  126.     print("Hold CTRL+T to stop program")
  127.  
  128.   --RF/EU label
  129.     if IC2 == true then energyAPI = " EU" else energyAPI = " RF" end
  130.    
  131.   --Wraps the Peripherals
  132.     mon = peripheral.find("monitor")
  133.  
  134.   while true do    
  135.     --mon.setTextScale(scale)
  136.           monX,monY = mon.getSize()
  137.           width = monX-2 height1 = monY-1 height2 = monY-2
  138.  
  139.   --Main Program
  140.     --Variables for Calculations
  141.       if mekanism == true then maxE = cube.getMaxEnergy() or 1
  142.         elseif IC2 == true then maxE = cube.getEUCapacity() or 1
  143.         else maxE = cube.getMaxEnergyStored() or 1
  144.       end
  145.       if mekanism == true then curE = cube.getStored() or 1
  146.         elseif IC2 == true then curE = cube.getEUStored() or 1
  147.         else curE = cube.getEnergyStored() or 1
  148.       end
  149.       if mekanism == true then
  150.         maxE = math.floor(maxE/2.5)
  151.         curE = math.floor(curE/2.5)
  152.       end
  153.      
  154.       rawPer = curE/maxE
  155.       percent = math.floor((rawPer*100)+0.5)
  156.       bar = math.floor((rawPer*width)+0.5)
  157.       stats = curE
  158.  
  159.     --Variable for Dynamic Screen Size ( in the loop so you can change the screen size while the program is running)
  160.       if dynamic == "y" then textScale() end
  161.       monX,monY = mon.getSize()
  162.       width = monX-2 height1 = monY-1 height2 = monY-2
  163.          
  164.     --Centers and Displays Title On Monitor
  165.  
  166.       clearScreen()
  167.       mon.setBackgroundColour(colors.black)
  168.       mon.setTextColour(colors.lightGray)
  169.       mon.setCursorPos(1,1)
  170.       centerText(string.rep(" ",string.len(title)+2),1)
  171.       centerText(title,1)
  172.  
  173.     --Monitor Statistics
  174.       mon.setBackgroundColour(colors.white)
  175.       mon.setTextColour(colors.blue)
  176.       if monX >= math.floor(string.len(stats)+18)
  177.         then
  178.           centerText("Current Energy:"..curE..energyAPI,3)
  179.         else
  180.           centerText("Current Energy:",3)
  181.           centerText("   "..curE..energyAPI,4)
  182.       end
  183.      
  184.       mon.setTextColour(colors.green)
  185.       centerText(percent.."% Full",6)
  186.    
  187.     --Loading Bar Code Re-Written Much MUCH simpler than before
  188.       mon.setCursorPos(2,height2)
  189.       mon.setBackgroundColour(colors.gray)
  190.       mon.write(string.rep(" ",width))
  191.       mon.setCursorPos(2,height2)
  192.       mon.setBackgroundColour(colors.lime)
  193.       mon.write(string.rep(" ",bar))
  194.    
  195.       mon.setCursorPos(2,height1)
  196.       mon.setBackgroundColour(colors.gray)
  197.       mon.write(string.rep(" ",width))
  198.       mon.setCursorPos(2,height1)
  199.       mon.setBackgroundColour(colors.lime)
  200.       mon.write(string.rep(" ",bar))
  201.    
  202.       if rate == "f" then os.sleep(1)
  203.       elseif rate == "s" then os.sleep(5)
  204.       else os.sleep(1) end
  205.   end
Add Comment
Please, Sign In to add comment