Advertisement
MrBartek

OC

Apr 22nd, 2021 (edited)
890
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.60 KB | None | 0 0
  1. --Power Monitoring Program
  2.  
  3. --Version 13
  4.  
  5.  
  6.  
  7. --Center Text Function
  8.  
  9.   function centerText(text,yVal)
  10.         length = string.len(text)
  11.         minus = math.floor(monX-length)
  12.         x = math.floor(minus/2)
  13.         mon.setCursorPos(x+1,yVal)
  14.         mon.write(text)
  15.   end
  16.  
  17.  
  18.  
  19. --Sets the BackGround to White (Cleaner than before)
  20.   function clearScreen()
  21.         mon.clear()
  22.         mon.setBackgroundColour(colors.white)
  23.         for i=1,monY do
  24.           mon.setCursorPos(1,i)
  25.           mon.write(string.rep(" ",monX))
  26.         end
  27.   end
  28.  
  29.  
  30. --PreFace
  31.   --Set Variables and load settings
  32.         config = fs.open("config/monitor","r")
  33.         mon = config.readAll()
  34.         config.close()
  35.  
  36.         config = fs.open("config/cube","r")
  37.         cube = config.readAll()
  38.         config.close()
  39.  
  40.         config = fs.open("config/title","r")
  41.         title = config.readAll()
  42.         config.close()
  43.  
  44.         config = fs.open("config/mekanism","r")
  45.         mekanism = config.readAll()
  46.         config.close()
  47.  
  48.         config = fs.open("config/IC2","r")
  49.         IC2 = config.readAll()
  50.         config.close()
  51.        
  52.         config = fs.open("config/rate","r")
  53.         rate = config.readAll()
  54.         config.close()
  55.  
  56.   --Shows Settings inside control computer
  57.         term.setTextColour(colors.red)
  58.         print("Final Settings")
  59.         term.setTextColour(colors.blue)
  60.         print("Monitor: "..mon)
  61.         print("Battery: "..cube)
  62.         print("Title: "..title)
  63.         print("Mekanism: "..mekanism)
  64.         print("IC2: "..IC2)
  65.         print("Rate: "..rate.." fast/slow")
  66.         term.setTextColour(colors.red)
  67.         print("If settings are incorrect. Run setup again")
  68.         print("Hold CTRL+T to stop program")
  69.  
  70.   --RF/EU label
  71.         if IC2 == "y" then energyAPI = " EU" else energyAPI = " RF" end
  72.  
  73.   --Wraps the Peripherals
  74.         cube = peripheral.wrap(cube)
  75.         mon = peripheral.wrap(mon)
  76.  
  77.   while true do  
  78.         --mon.setTextScale(scale)
  79.                   monX,monY = mon.getSize()
  80.                   width = monX-2 height1 = monY-1 height2 = monY-2
  81.   --Main Program
  82.  
  83.         --Variables for Calculations
  84.           if mekanism == "y" then maxE = cube.getMaxEnergy() or 1
  85.                 elseif IC2 == "y" then maxE = cube.getEUCapacity() or 1
  86.                 else maxE = cube.getMaxEnergyStored() or 1
  87.           end
  88.  
  89.           if mekanism == "y" then curE = cube.getStored() or 6.66
  90.                 elseif IC2 == "y" then curE = cube.getEUStored() or 6.66
  91.                 else curE = cube.getEnergyStored() or 6.66
  92.           end
  93.  
  94.           if mekanism == "y" then maxE = maxE/2.5 end
  95.           if mekanism == "y" then curE = curE/2.5 end
  96.  
  97.  
  98.  
  99.           rawPer = curE/maxE
  100.           percent = math.floor((rawPer*100)+0.5)
  101.           bar = math.floor((rawPer*width)+0.5)
  102.           stats = curE
  103.  
  104.           --Variable for Dynamic Screen Size ( in the loop so you can change the screen size while the program is running)
  105.                 mon.setTextScale(0.5)
  106.                 monX,monY = mon.getSize()
  107.                 if monX <= 16 or monY <= 11 then mon.setTextScale(0.5) elseif
  108.                   monX <= 37 or monY <= 25 then mon.setTextScale(1) elseif
  109.                   monX <= 58 or monY <= 39 then mon.setTextScale(1.5) elseif
  110.                   monX <= 80 or monY <= 53 then mon.setTextScale(2) elseif
  111.                   monX <= 101 or monY <= 68 then mon.setTextScale(2.5) else
  112.                   mon.setTextScale(3)
  113.                 end  
  114.  
  115.                   monX,monY = mon.getSize()
  116.                   width = monX-2
  117.                   height1 = monY-1
  118.                   height2 = monY-2
  119.                  
  120.           --Centers and Displays Title On Monitor        
  121.           clearScreen()
  122.           mon.setBackgroundColour(colors.black)
  123.           mon.setTextColour(colors.lightGray)
  124.           mon.setCursorPos(1,1)
  125.           centerText(string.rep(" ",string.len(title)+2),1)
  126.           centerText(title,1)
  127.  
  128.         --Monitor Statistics
  129.           mon.setBackgroundColour(colors.white)
  130.           mon.setTextColour(colors.blue)
  131.           if monX >= math.floor(string.len(stats)+18)
  132.                 then
  133.                   centerText("Current Energy:"..curE..energyAPI,3)
  134.                 else
  135.                   centerText("Current Energy:",3)
  136.                   centerText("   "..curE..energyAPI,4)
  137.           end
  138.  
  139.           if percent == 666
  140.                 then
  141.                   mon.setTextColour(colors.red)
  142.                   centerText("Connect Cell!",6)
  143.                 else
  144.                   mon.setTextColour(colors.green)
  145.                   centerText(percent.."% Full",6)
  146.           end
  147.  
  148.  
  149.  
  150.         --Loading Bar Code Re-Written Much MUCH simpler than before
  151.           mon.setCursorPos(2,height2)
  152.           mon.setBackgroundColour(colors.gray)
  153.           mon.write(string.rep(" ",width))
  154.           mon.setCursorPos(2,height2)
  155.           if percent == 666 then mon.setBackgroundColour(colors.red) else
  156.           mon.setBackgroundColour(colors.lime) end
  157.           mon.write(string.rep(" ",bar))
  158.  
  159.           mon.setCursorPos(2,height1)
  160.           mon.setBackgroundColour(colors.gray)
  161.           mon.write(string.rep(" ",width))
  162.           mon.setCursorPos(2,height1)
  163.           if percent == 666 then mon.setBackgroundColour(colors.red) else
  164.           mon.setBackgroundColour(colors.lime) end
  165.           mon.write(string.rep(" ",bar))
  166.  
  167.           if rate == "f" then os.sleep(1)
  168.           elseif rate == "s" then os.sleep(5)
  169.           else os.sleep(1)
  170.   end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement