MoJoCreatior

Power Monitor Program V:20 --old

Mar 21st, 2017
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 9.44 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:21"
  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 centerTextC(text,line,colorB,colorT)
  28.     mon.setBackgroundColour(colorB)
  29.     mon.setTextColour(colorT)
  30.     length = string.len(text)
  31.     minus = math.floor(monX-length)
  32.     x = math.floor(minus/2)
  33.     mon.setCursorPos(x+1,line)
  34.     mon.write(text)
  35.   end
  36.  
  37.   function clearScreen()
  38.     mon.setBackgroundColour(convert(colorMB))
  39.     mon.clear()
  40.   end
  41.  
  42.   function config(name)
  43.     if fs.exists("config/"..name) then
  44.       cfg = fs.open("config/"..name,"r")
  45.       name = cfg.readAll()
  46.       cfg.close()
  47.       return name
  48.     else
  49.       fs.delete("startup")
  50.       startup = fs.open("startup","w")
  51.       startup.write('shell.run("setup.lua")')
  52.       startup.close()
  53.       term.setTextColour(colors.red)
  54.       print("ERROR! 404")
  55.       print(name.." config not found")
  56.       term.setTextColour(colors.blue)
  57.       print("rebooting into setup")
  58.       print("3") sleep(1)
  59.       print("2") sleep(1)
  60.       print("1") sleep(1)
  61.       os.reboot()
  62.     end
  63.   end
  64.  
  65.   function textScale()
  66.     mon.setTextScale(0.5)
  67.     monX,monY = mon.getSize()
  68.     if monX <= 16 or monY <= 11 then mon.setTextScale(0.5) elseif
  69.       monX <= 37 or monY <= 25 then mon.setTextScale(1) elseif
  70.       monX <= 58 or monY <= 39 then mon.setTextScale(1.5) elseif
  71.       monX <= 80 or monY <= 53 then mon.setTextScale(2) elseif
  72.       monX <= 101 or monY <= 68 then mon.setTextScale(2.5) else
  73.       mon.setTextScale(3)
  74.     end  
  75.   end
  76.  
  77.   function IC2Check()
  78.     IC2 = false
  79.     if peripheral.find("mfsu") == nil then
  80.       else cube = peripheral.find("mfsu")
  81.       IC2 = true
  82.     end
  83.     if peripheral.find("mfe") == nil then
  84.       else cube = peripheral.find("mfe")
  85.       IC2 = true
  86.     end
  87.     if peripheral.find("cesu") == nil then
  88.       else cube = peripheral.find("cesu")
  89.       IC2 = true
  90.     end
  91.     if peripheral.find("batbox") == nil then
  92.       else cube = peripheral.find("batbox")
  93.       IC2 = true
  94.     end
  95.   end
  96.  
  97.   function mekanismCheck()
  98.     mekanism = false
  99.     if peripheral.find("Basic Energy Cube") == nil then
  100.       else cube = peripheral.find("Basic Energy Cube")
  101.       mekanism = true
  102.     end
  103.     if peripheral.find("Advanced Energy Cube") == nil then
  104.       else cube = peripheral.find("Advanced Energy Cube")
  105.       mekanism = true
  106.     end
  107.     if peripheral.find("Elite Energy Cube") == nil then
  108.       else cube = peripheral.find("Elite Energy Cube")
  109.       mekanism = true
  110.     end
  111.     if peripheral.find("Ultimate Energy Cube") == nil then
  112.       else cube = peripheral.find("Ultimate Energy Cube")
  113.       mekanism = true
  114.     end
  115.     if peripheral.find("Induction Matrix") == nil then
  116.       else cube = peripheral.find("Induction Matrix")
  117.       mekanism = true
  118.     end
  119.   end
  120.  
  121.   function RFAPI()
  122.     if peripheral.find("tile_thermalexpansion_cell_resonant_name") == nil then
  123.       else cube = peripheral.find("tile_thermalexpansion_cell_resonant_name")
  124.     end
  125.     if peripheral.find("tile_blockcapacitorbank_name") == nil then
  126.       else cube = peripheral.find("tile_blockcapacitorbank_name")
  127.     end
  128.   end
  129.  
  130.   function convert(color)
  131.     if color == "white" then color = colors.white end
  132.     if color == "orange" then color = colors.orange end
  133.     if color == "magenta" then color = colors.magenta end
  134.     if color == "lightBlue" then color = colors.lightBlue end
  135.     if color == "yellow" then color = colors.yellow end
  136.     if color == "lime" then color = colors.lime end
  137.     if color == "pinkgray" then color = colors.pinkgray end
  138.     if color == "gray" then color = colors.gray end
  139.     if color == "lightGray" then color = colors.lightGray end
  140.     if color == "cyan" then color = colors.cyan end
  141.     if color == "purple" then color = colors.purple end
  142.     if color == "blue" then color = colors.blue end
  143.     if color == "brown" then color = colors.brown end
  144.     if color == "green" then color = colors.green end
  145.     if color == "red" then color = colors.red end
  146.     if color == "black" then color = colors.black end
  147.     return color
  148.   end
  149.  
  150. --PreFace
  151.   --Color Coneverter
  152.   --Load Settings
  153.     title = config("title")
  154.     rate = config("rate")
  155.     dynamic = config("dynamic")
  156.     colorTB = config("colorTB")
  157.     colorTT = config("colorTT")
  158.     colorMB = config("colorMB")
  159.     colorST = config("colorST")
  160.     colorBT = config("colorBT")
  161.     colorBE = config("colorBE")
  162.     colorBF = config("colorBF")
  163.     colorPR = config("colorPR")
  164.     redstone = config("redstone")
  165.     side = config("side")
  166.     bundled = config("bundled")
  167.     options = config("options")
  168.     IC2Check()
  169.     mekanismCheck()
  170.     RFAPI()
  171.    
  172.   --Shows Settings inside control computer
  173.     intro()
  174.     term.setTextColour(colors.red)
  175.     print("Final Settings")
  176.     term.setTextColour(colors.blue)
  177.     print(" Title: "..title)
  178.     if rate == "f" then print(" Refresh Rate: fast") else print(" Refresh Rate: slow") end
  179.     if mekanism == true then print(" Mekanism: true") else print(" Mekanism: false") end
  180.     if IC2 == true then print(" IC2: true") else print(" IC2: false") end
  181.     if dynamic == "y" then print(" Dynamic Scaling: true") else print(" Dynamic Scaling: false") end
  182.     if options == "y" then
  183.       term.setTextColour(colors.red)
  184.       print("\nAdvanced Options")
  185.       term.setTextColour(colors.blue)
  186.       print(" Title Text Color: "..colorTT)
  187.       print(" Title Background: "..colorTB)
  188.       print(" Background Color: "..colorMB)
  189.       print(" Statistics Color: "..colorST)
  190.       print(" Bar Percent Text: "..colorBT)
  191.       print(" Bars Empty Color: "..colorBE)
  192.       print(" Bar Filled Color: "..colorBF)
  193.     end
  194.     term.setTextColour(colors.red)
  195.     print("\nIf settings are incorrect. Run setup.lua")
  196.     print("Hold CTRL+T to stop program")
  197.  
  198.   --RF/EU label
  199.     if IC2 == true then energyAPI = " EU" else energyAPI = " RF" end
  200.    
  201.   --Wraps the Monitor
  202.     mon = peripheral.find("monitor")
  203.     monX,monY = mon.getSize()
  204.     textScale()
  205.    
  206.   while true do    
  207.       if dynamic == "y" then textScale() end
  208.       monX,monY = mon.getSize()
  209.  
  210.   --Main Program
  211.     --Variables for Calculations
  212.       if mekanism == true then maxE = cube.getMaxEnergy() or 1
  213.         elseif IC2 == true then maxE = cube.getEUCapacity() or 1
  214.         else maxE = cube.getMaxEnergyStored() or 1
  215.       end
  216.       if mekanism == true then curE = cube.getStored() or 1
  217.         elseif IC2 == true then curE = cube.getEUStored() or 1
  218.         else curE = cube.getEnergyStored() or 1
  219.       end
  220.       if mekanism == true then
  221.         maxE = math.floor(maxE/2.5)
  222.         curE = math.floor(curE/2.5)
  223.       end
  224.  
  225.       percent = math.floor(((curE/maxE)*100)+0.5)
  226.       bar = math.floor(((curE/maxE)*(monX-2))+0.5)
  227.       stats = curE
  228.      
  229.     --Redstone Output
  230.       if redstone == "y" then
  231.         if bundled == "1" then
  232.           if percent >= 99 then
  233.             rs.setBundledOutput(side,convert(colorPR))
  234.             else rs.setBundledOutput(side,0)
  235.           end
  236.         else
  237.           if percent >= 99 then
  238.             rs.setOutput(side,true)
  239.             else rs.setOutput(side,false)
  240.           end
  241.         end
  242.       end
  243.  
  244.     --Centers and Displays Title On Monitor
  245.  
  246.       clearScreen()
  247.       mon.setBackgroundColour(colors.black)
  248.       mon.setTextColour(colors.lightGray)
  249.       mon.setCursorPos(1,1)
  250.       centerTextC(string.rep(" ",string.len(title)+2),1,convert(colorTB),convert(colorTT))
  251.       centerTextC(title,1,convert(colorTB),convert(colorTT))
  252.  
  253.     --Monitor Statistics
  254.       mon.setBackgroundColour(convert(colorMB))
  255.       mon.setTextColour(convert(colorST))
  256.       if monX >= math.floor(string.len(stats)+18)
  257.         then
  258.           centerText("Current Energy:"..curE..energyAPI,3)
  259.         else
  260.           centerText("Current Energy:",3)
  261.           centerText("   "..curE..energyAPI,4)
  262.       end
  263.      
  264.       centerTextC(percent.."% Full",monY-4,convert(colorMB),convert(colorBT))
  265.    
  266.     --Loading Bar Code Re-Written Much MUCH simpler than before
  267.       mon.setCursorPos(2,monY-2)
  268.       mon.setBackgroundColour(convert(colorBE))
  269.       mon.write(string.rep(" ",monX-2))
  270.       mon.setCursorPos(2,monY-2)
  271.       mon.setBackgroundColour(convert(colorBF))
  272.       mon.write(string.rep(" ",bar))
  273.    
  274.       mon.setCursorPos(2,monY-1)
  275.       mon.setBackgroundColour(convert(colorBE))
  276.       mon.write(string.rep(" ",monX-2))
  277.       mon.setCursorPos(2,monY-1)
  278.       mon.setBackgroundColour(convert(colorBF))
  279.       mon.write(string.rep(" ",bar))
  280.    
  281.       if rate == "f" then os.sleep(1)
  282.       elseif rate == "s" then os.sleep(5)
  283.       else os.sleep(5) end
  284.   end
Add Comment
Please, Sign In to add comment