Guest User

Untitled

a guest
Nov 21st, 2021
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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 meets following criteria:
  3. 1: Player_Athena 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:30"
  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.wrap("back") == nil then
  80.       else cube = peripheral.wrap("back")
  81.       IC2 = true
  82.     end
  83.   end
  84.  
  85.  
  86.   function convert(color)
  87.     if color == "white" then color = colors.white end
  88.     if color == "orange" then color = colors.orange end
  89.     if color == "magenta" then color = colors.magenta end
  90.     if color == "lightBlue" then color = colors.lightBlue end
  91.     if color == "yellow" then color = colors.yellow end
  92.     if color == "lime" then color = colors.lime end
  93.     if color == "pinkgray" then color = colors.pinkgray end
  94.     if color == "gray" then color = colors.gray end
  95.     if color == "lightGray" then color = colors.lightGray end
  96.     if color == "cyan" then color = colors.cyan end
  97.     if color == "purple" then color = colors.purple end
  98.     if color == "blue" then color = colors.blue end
  99.     if color == "brown" then color = colors.brown end
  100.     if color == "green" then color = colors.green end
  101.     if color == "red" then color = colors.red end
  102.     if color == "black" then color = colors.black end
  103.     return color
  104.   end
  105.  
  106.   function eChange()
  107.     newE = curE
  108.     local difference = (newE-oldE)
  109.     oldE = curE
  110.     if rate == "f" then dividend = 20 elseif rate == "s" then dividend = 100 end
  111.     local change = math.floor(difference/dividend)
  112.     return(change)
  113.   end
  114.  
  115. --PreFace
  116.   --Color Coneverter
  117.   --Load Settings
  118.     title = config("title")
  119.     rate = config("rate")
  120.     dynamic = config("dynamic")
  121.     colorTB = config("colorTB")
  122.     colorTT = config("colorTT")
  123.     colorMB = config("colorMB")
  124.     colorST = config("colorST")
  125.     colorBT = config("colorBT")
  126.     colorBE = config("colorBE")
  127.     colorBF = config("colorBF")
  128.     colorPR = config("colorPR")
  129.     colorPos = config("colorPos")
  130.     colorNeg = config("colorNeg")
  131.     redstone = config("redstone")
  132.     side = config("side")
  133.     bundled = config("bundled")
  134.     options = config("options")
  135.     IC2Check()
  136.    
  137.   --Shows Settings inside control computer
  138.     intro()
  139.     term.setTextColour(colors.red)
  140.     print("Final Settings")
  141.     term.setTextColour(colors.blue)
  142.     print(" Title: "..title)
  143.     if rate == "f" then print(" Refresh Rate: fast") else print(" Refresh Rate: slow") end
  144.     if dynamic == "y" then print(" Dynamic Scaling: true") else print(" Dynamic Scaling: false") end
  145.     if options == "y" then
  146.       term.setTextColour(colors.red)
  147.       print("\nAdvanced Options")
  148.       term.setTextColour(colors.blue)
  149.       print(" Title Text Color: "..colorTT)
  150.       print(" Title Background: "..colorTB)
  151.       print(" Background Color: "..colorMB)
  152.       print(" Statistics Color: "..colorST)
  153.       print(" Bar Percent Text: "..colorBT)
  154.       print(" Bars Empty Color: "..colorBE)
  155.       print(" Bar Filled Color: "..colorBF)
  156.       print(" Positive Change: "..colorPos)
  157.       print(" Negative Change: "..colorNeg)
  158.     end
  159.     term.setTextColour(colors.gray)
  160.     print("Million < Billion < Trillion < Quadrillion")
  161.     term.setTextColour(colors.red)
  162.     print("\nIf settings are incorrect. Run setup.lua")
  163.     print("Hold CTRL+T to stop program")
  164.  
  165.   --RF/EU label
  166.     if IC2 == true then energyAPI = " RF" else energyAPI = " RF" end
  167.     if IC2 == true then energyAPI_ = "RF" else energyAPI_ = "RF" end
  168.    
  169.   --Wraps the Monitor
  170.     mon = peripheral.find("monitor")
  171.     monX,monY = mon.getSize()
  172.     textScale()
  173.    
  174.     monX,monY = mon.getSize()
  175.     oldE,newE,curE,maxE = 0,0,0,0
  176.    
  177.   while true do    
  178.       if dynamic == "y" then textScale() end
  179.  
  180.   --Main Program
  181.     --Variables for Calculations
  182.       capacitorCount = 1
  183.       maxE = 1000000 * capacitorCount
  184.       curE = cube.getEnergyStored() or 1
  185.  
  186.       percent = math.floor(((curE/maxE)*100)+0.5)
  187.       bar = math.floor(((curE/maxE)*(monX-2))+0.5)
  188.       stats = curE
  189.      
  190.     --Redstone Output
  191.       if redstone == "y" then
  192.         if bundled == "1" then
  193.           if percent >= 99 then
  194.             rs.setBundledOutput(side,convert(colorPR))
  195.             else rs.setBundledOutput(side,0)
  196.           end
  197.         else
  198.           if percent >= 99 then
  199.             rs.setOutput(side,true)
  200.             else rs.setOutput(side,false)
  201.           end
  202.         end
  203.       end
  204.  
  205.     --Centers and Displays Title On Monitor
  206.  
  207.       clearScreen()
  208.       mon.setBackgroundColour(colors.black)
  209.       mon.setTextColour(colors.lightGray)
  210.       mon.setCursorPos(1,1)
  211.       centerTextC(string.rep(" ",string.len(title)+2),1,convert(colorTB),convert(colorTT))
  212.       centerTextC(title,1,convert(colorTB),convert(colorTT))
  213.  
  214.     --Monitor Statistics
  215.       --[[if curE >= 1000000 and curE <= 1000000000 then
  216.         stats = math.floor(stats/1000)
  217.         stats = (stats/1000)
  218.         mbtq = " M"
  219.       else]]if curE >= 1000000000 and curE <= 1000000000000 then
  220.         stats = math.floor(stats/1000000)
  221.         stats = (stats/1000)
  222.         mbtq = " B"
  223.       elseif curE >= 1000000000000 and curE <= 1000000000000000 then
  224.         stats = math.floor(stats/1000000000)
  225.         stats = (stats/1000)
  226.         mbtq = " T"
  227.       elseif curE >= 1000000000000000 then
  228.         stats = math.floor(stats/1000000000000)
  229.         stats = (stats/1000)
  230.         mbtq = " Q"
  231.       elseif curE <= 1000000 then mbtq = " "
  232.       end
  233.       mon.setBackgroundColour(convert(colorMB))
  234.       mon.setTextColour(convert(colorST))
  235.       if curE >= 1000000 then eAPI = energyAPI_ else eAPI = energyAPI end
  236.       centerText(stats..mbtq..eAPI,3)
  237.       --[[
  238.       if monX >= math.floor(string.len(stats)+9)
  239.         then
  240.           centerText("Total:"..stats..mbtq..eAPI,3)
  241.         else
  242.           centerText("Total:",3)
  243.           centerText(stats..mbtq..eAPI,4)
  244.       end
  245.       ]]
  246.      
  247.     --Change Per Tick Calculator and Display
  248.       e_Change = eChange()
  249.       if e_Change >= 0 then sign = "+" elseif e_Change <= 0 then sign = "-" end
  250.       if e_Change >= 0 then signC = colorPos elseif e_Change <= 0 then signC = colorNeg end
  251.       centerTextC(sign..e_Change..energyAPI.."/t",5,convert(colorMB),convert(signC))
  252.      
  253.       centerTextC(percent.."% Full",monY-3,convert(colorMB),convert(colorBT))
  254.    
  255.     --Loading Bar Code Re-Written Much MUCH simpler than before
  256.       mon.setCursorPos(2,monY-2)
  257.       mon.setBackgroundColour(convert(colorBE))
  258.       mon.write(string.rep(" ",monX-2))
  259.       mon.setCursorPos(2,monY-2)
  260.       mon.setBackgroundColour(convert(colorBF))
  261.       mon.write(string.rep(" ",bar))
  262.    
  263.       mon.setCursorPos(2,monY-1)
  264.       mon.setBackgroundColour(convert(colorBE))
  265.       mon.write(string.rep(" ",monX-2))
  266.       mon.setCursorPos(2,monY-1)
  267.       mon.setBackgroundColour(convert(colorBF))
  268.       mon.write(string.rep(" ",bar))
  269.    
  270.       if rate == "f" then os.sleep(1)
  271.       elseif rate == "s" then os.sleep(5)
  272.       else os.sleep(5) end
  273.   end
Advertisement
Add Comment
Please, Sign In to add comment