bobmarley12345

mebackuppowermonitor

Oct 10th, 2020 (edited)
833
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. MonitorSide = "bottom"
  2. Monitor = peripheral.wrap(MonitorSide)
  3. cell1 = peripheral.wrap("cofh_thermalexpansion_energycell_77")
  4. cell2 = peripheral.wrap("cofh_thermalexpansion_energycell_78")
  5. cell3 = peripheral.wrap("cofh_thermalexpansion_energycell_79")
  6. cell4 = peripheral.wrap("cofh_thermalexpansion_energycell_80")
  7. cell5 = peripheral.wrap("cofh_thermalexpansion_energycell_81")
  8. cell6 = peripheral.wrap("cofh_thermalexpansion_energycell_82")
  9. cell7 = peripheral.wrap("cofh_thermalexpansion_energycell_83")
  10. cell8 = peripheral.wrap("cofh_thermalexpansion_energycell_84")
  11. cell9 = peripheral.wrap("cofh_thermalexpansion_energycell_85")
  12.  
  13. function ClearMonitor()
  14.     Monitor.setTextColor(colours.black)
  15.     Monitor.setBackgroundColor(colours.black)
  16.     Monitor.clear()
  17.     Monitor.setCursorPos(1,1)
  18. end
  19.  
  20. function DrawText(xPos, yPos, text, textColour, backgroundColour)
  21.     Monitor.setBackgroundColor(backgroundColour)
  22.     Monitor.setTextColor(textColour)
  23.     Monitor.setCursorPos(xPos,yPos)
  24.     Monitor.write(text)
  25. end
  26.  
  27. function DrawLine(xPos, yPos, lineLength, colour)
  28.     Monitor.setBackgroundColor(colour)
  29.     Monitor.setTextColor(colour)
  30.     Monitor.setCursorPos(xPos,yPos)
  31.     Monitor.write(string.rep(" ", lineLength))
  32. end
  33.  
  34. function ProgressBar(xPos, yPos, barLength, value, maxValue, backgroundColour, progressColour)
  35.     DrawLine(xPos, yPos, barLength, backgroundColour) --backgoround bar
  36.     local barSize = math.floor((value/maxValue) * barLength)
  37.     DrawLine(xPos, yPos, barSize, progressColour) --progress so far
  38. end
  39.  
  40. function GroupBox(xPos, yPos, height, header, textColour, headerBackgroundColour, rightPadding)
  41.     GroupBoxHeader(xPos, yPos, header, textColour, headerBackgroundColour, rightPadding)
  42.     GroupBoxFooter(xPos, yPos + height + 1, textColour, headerBackgroundColour, rightPadding)
  43. end
  44.  
  45. function GroupBoxHeader(xPos, yPos, header, textColour, backgroundColour, rightPadding)
  46.     local repeatChars
  47.     local headerLength = string.len(header)
  48.    
  49.     local monX, monY = Monitor.getSize()
  50.     repeatChars = monX - 4 - headerLength - rightPadding
  51.  
  52.     if (repeatChars < 0) then
  53.         repeatChars = 0
  54.     end
  55.  
  56.     local head = "--- " .. header .. " " .. string.rep("-", repeatChars - rightPadding)
  57.     DrawText(xPos, yPos, head, textColour, backgroundColour)
  58. end
  59.  
  60. function GroupBoxFooter(xPos, yPos, textColour, backgroundColour, rightPadding)
  61.     local repeatChars
  62.    
  63.     local monX, monY = Monitor.getSize()
  64.     repeatChars = monX - rightPadding
  65.  
  66.     if (repeatChars < 0) then
  67.         repeatChars = 0
  68.     end
  69.  
  70.     local head = string.rep("-", repeatChars)
  71.     DrawText(xPos, yPos, head, textColour, backgroundColour)
  72. end
  73.  
  74. function GetColourFromPercent(percentage)
  75.     local colourOut = colours.red
  76.     if (percentage > 15)   then colourOut = colours.orange end
  77.     if (percentage > 45)  then colourOut = colours.yellow end
  78.     if (percentage > 70)  then colourOut = colours.green end
  79.     if (percentage > 90)  then colourOut = colours.cyan end
  80.     return colourOut
  81. end
  82.  
  83. function Main()
  84.     Monitor.setTextScale(1)
  85.     while (true) do
  86.         local monX, monY = Monitor.getSize()
  87.  
  88.         local cell1Energy = cell1.getEnergyStored("unknown")
  89.         local cell2Energy = cell2.getEnergyStored("unknown")
  90.         local cell3Energy = cell3.getEnergyStored("unknown")
  91.         local cell4Energy = cell4.getEnergyStored("unknown")
  92.         local cell5Energy = cell5.getEnergyStored("unknown")
  93.         local cell6Energy = cell6.getEnergyStored("unknown")
  94.         local cell7Energy = cell7.getEnergyStored("unknown")
  95.         local cell8Energy = cell8.getEnergyStored("unknown")
  96.         local cell9Energy = cell9.getEnergyStored("unknown")
  97.  
  98.         local cell1MaxEnergy = cell1.getMaxEnergyStored("unknown")
  99.         local cell2MaxEnergy = cell2.getMaxEnergyStored("unknown")
  100.         local cell3MaxEnergy = cell3.getMaxEnergyStored("unknown")
  101.         local cell4MaxEnergy = cell4.getMaxEnergyStored("unknown")
  102.         local cell5MaxEnergy = cell5.getMaxEnergyStored("unknown")
  103.         local cell6MaxEnergy = cell6.getMaxEnergyStored("unknown")
  104.         local cell7MaxEnergy = cell7.getMaxEnergyStored("unknown")
  105.         local cell8MaxEnergy = cell8.getMaxEnergyStored("unknown")
  106.         local cell9MaxEnergy = cell9.getMaxEnergyStored("unknown")
  107.  
  108.         local cell1Percent = math.floor((cell1Energy / cell1MaxEnergy) * 100)
  109.         local cell2Percent = math.floor((cell2Energy / cell2MaxEnergy) * 100)
  110.         local cell3Percent = math.floor((cell3Energy / cell3MaxEnergy) * 100)
  111.         local cell4Percent = math.floor((cell4Energy / cell4MaxEnergy) * 100)
  112.         local cell5Percent = math.floor((cell5Energy / cell5MaxEnergy) * 100)
  113.         local cell6Percent = math.floor((cell6Energy / cell6MaxEnergy) * 100)
  114.         local cell7Percent = math.floor((cell7Energy / cell7MaxEnergy) * 100)
  115.         local cell8Percent = math.floor((cell8Energy / cell8MaxEnergy) * 100)
  116.         local cell9Percent = math.floor((cell9Energy / cell9MaxEnergy) * 100)
  117.  
  118.         local c1c
  119.         local c2c
  120.         local c3c
  121.         local c4c
  122.         local c5c
  123.         local c6c
  124.         local c7c
  125.         local c8c
  126.         local c9c
  127.  
  128.         if (cell1Percent == 0) then c1c = colours.red else c1c = colours.grey end
  129.         if (cell2Percent == 0) then c2c = colours.red else c2c = colours.grey end
  130.         if (cell3Percent == 0) then c3c = colours.red else c3c = colours.grey end
  131.         if (cell4Percent == 0) then c4c = colours.red else c4c = colours.grey end
  132.         if (cell5Percent == 0) then c5c = colours.red else c5c = colours.grey end
  133.         if (cell6Percent == 0) then c6c = colours.red else c6c = colours.grey end
  134.         if (cell7Percent == 0) then c7c = colours.red else c7c = colours.grey end
  135.         if (cell8Percent == 0) then c8c = colours.red else c8c = colours.grey end
  136.         if (cell9Percent == 0) then c9c = colours.red else c9c = colours.grey end
  137.  
  138.         ClearMonitor()
  139.  
  140.         GroupBox(2, 2, 19, "ME Backup Cells Power", colours.orange, colours.black, 0)
  141.  
  142.         DrawText(3, 4, "Cell 1", colours.white, colours.black)
  143.         ProgressBar(10, 4, monX - 15, cell1Energy, cell1MaxEnergy, c1c, GetColourFromPercent(cell1Percent))
  144.         DrawText(monX - 4, 4, cell1Percent .. "%", colours.white, colours.black)
  145.        
  146.         DrawText(3, 6, "Cell 2", colours.white, colours.black)
  147.         ProgressBar(10, 6, monX - 15, cell2Energy, cell2MaxEnergy, c2c, GetColourFromPercent(cell2Percent))
  148.         DrawText(monX - 4, 6, cell2Percent .. "%", colours.white, colours.black)
  149.        
  150.         DrawText(3, 8, "Cell 3", colours.white, colours.black)
  151.         ProgressBar(10, 8, monX - 15, cell3Energy, cell3MaxEnergy, c3c, GetColourFromPercent(cell3Percent))
  152.         DrawText(monX - 4, 8, cell3Percent .. "%", colours.white, colours.black)
  153.  
  154.         DrawText(3, 10, "Cell 4", colours.white, colours.black)
  155.         ProgressBar(10, 10, monX - 15, cell4Energy, cell4MaxEnergy, c4c, GetColourFromPercent(cell4Percent))
  156.         DrawText(monX - 4, 10, cell4Percent .. "%", colours.white, colours.black)
  157.  
  158.         DrawText(3, 12, "Cell 5", colours.white, colours.black)
  159.         ProgressBar(10, 12, monX - 15, cell5Energy, cell5MaxEnergy, c5c, GetColourFromPercent(cell5Percent))
  160.         DrawText(monX - 4, 12, cell5Percent .. "%", colours.white, colours.black)
  161.  
  162.         DrawText(3, 14, "Cell 6", colours.white, colours.black)
  163.         ProgressBar(10, 14, monX - 15, cell6Energy, cell6MaxEnergy, c6c, GetColourFromPercent(cell6Percent))
  164.         DrawText(monX - 4, 14, cell6Percent .. "%", colours.white, colours.black)
  165.  
  166.         DrawText(3, 16, "Cell 7", colours.white, colours.black)
  167.         ProgressBar(10, 16, monX - 15, cell7Energy, cell7MaxEnergy, c7c, GetColourFromPercent(cell7Percent))
  168.         DrawText(monX - 4, 16, cell7Percent .. "%", colours.white, colours.black)
  169.  
  170.         DrawText(3, 18, "Cell 8", colours.white, colours.black)
  171.         ProgressBar(10, 18, monX - 15, cell8Energy, cell8MaxEnergy, c8c, GetColourFromPercent(cell8Percent))
  172.         DrawText(monX - 4, 18, cell8Percent .. "%", colours.white, colours.black)
  173.  
  174.         DrawText(3, 20, "Cell 9", colours.white, colours.black)
  175.         ProgressBar(10, 20, monX - 15, cell9Energy, cell9MaxEnergy, c9c, GetColourFromPercent(cell9Percent))
  176.         DrawText(monX - 4, 20, cell9Percent .. "%", colours.white, colours.black)
  177.  
  178.         sleep(1)
  179.     end
  180. end
  181.  
  182. Main()
RAW Paste Data