bobmarley12345

mepowermonitor

Oct 30th, 2020 (edited)
718
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. MonitorSide = "top"
  2. GlassesSide = "left"
  3. Monitor = peripheral.wrap(MonitorSide)
  4. Glasses = peripheral.wrap(GlassesSide)
  5. cell1 = peripheral.wrap("cofh_thermalexpansion_energycell_111")
  6. cell2 = peripheral.wrap("cofh_thermalexpansion_energycell_112")
  7.  
  8. function GetHexFromColour(clr)
  9.     local colourOut = 0xCC4C4C --red
  10.     if (clr == colours.white) then colourOut = 0xFFFFFF end
  11.     if (clr == colours.orange) then colourOut = 0xF2B233 end
  12.     if (clr == colours.yellow) then colourOut = 0xDEDE6C end
  13.     if (clr == colours.green) then colourOut = 0x57A64E end
  14.     if (clr == colours.cyan) then colourOut = 0x4C99B2 end
  15.     return colourOut;
  16. end
  17.  
  18. function GetColourFromPercent(percentage)
  19.     local colourOut = colours.red
  20.     if (percentage > 15)   then colourOut = colours.orange end
  21.     if (percentage > 45)  then colourOut = colours.yellow end
  22.     if (percentage > 70)  then colourOut = colours.green end
  23.     if (percentage > 90)  then colourOut = colours.cyan end
  24.     return colourOut
  25. end
  26.  
  27. function ClearScreens()
  28.     Monitor.setTextColor(colours.black)
  29.     Monitor.setBackgroundColor(colours.black)
  30.     Monitor.clear()
  31.     Monitor.setCursorPos(1,1)
  32.     Glasses.clear()
  33. end
  34.  
  35. function DrawText(xPos, yPos, text, textColour, backgroundColour)
  36.     Monitor.setBackgroundColor(backgroundColour)
  37.     Monitor.setTextColor(textColour)
  38.     Monitor.setCursorPos(xPos,yPos)
  39.     Monitor.write(text)
  40.     Glasses.addText(xPos * 5, yPos * 5, text, GetHexFromColour(textColour))
  41. end
  42.  
  43. function DrawLine(xPos, yPos, lineLength, colour)
  44.     Monitor.setBackgroundColor(colour)
  45.     Monitor.setTextColor(colour)
  46.     Monitor.setCursorPos(xPos,yPos)
  47.     Monitor.write(string.rep(" ", lineLength))
  48.     Glasses.addBox(xPos * 5, yPos * 5, lineLength * 5, 5, GetHexFromColour(colour), 1)
  49. end
  50.  
  51. function ProgressBar(xPos, yPos, barLength, value, maxValue, backgroundColour, progressColour)
  52.     DrawLine(xPos, yPos, barLength, backgroundColour) --backgoround bar
  53.     local barSize = math.floor((value/maxValue) * barLength)
  54.     DrawLine(xPos, yPos, barSize, progressColour) --progress so far
  55. end
  56.  
  57. function MainFunc()
  58.     Monitor.setTextScale(1)
  59.     while (true) do
  60.         local monX, monY = Monitor.getSize()
  61.  
  62.         local cell1Energy = cell1.getEnergyStored("unknown")
  63.         local cell2Energy = cell2.getEnergyStored("unknown")
  64.  
  65.         local cell1MaxEnergy = cell1.getMaxEnergyStored("unknown")
  66.         local cell2MaxEnergy = cell2.getMaxEnergyStored("unknown")
  67.  
  68.         local cell1Percent = math.floor((cell1Energy / cell1MaxEnergy) * 100)
  69.         local cell2Percent = math.floor((cell2Energy / cell2MaxEnergy) * 100)
  70.  
  71.         local c1c
  72.         local c2c
  73.  
  74.         if (cell1Percent == 0) then c1c = colours.red else c1c = colours.grey end
  75.         if (cell2Percent == 0) then c2c = colours.red else c2c = colours.grey end
  76.  
  77.         ClearScreens()
  78.  
  79.         DrawText(3, 2, "Cell 1", colours.white, colours.black)
  80.         ProgressBar(10, 2, monX - 15, cell1Energy, cell1MaxEnergy, c1c, GetColourFromPercent(cell1Percent))
  81.         DrawText(monX - 4, 2, cell1Percent .. "%", colours.white, colours.black)
  82.        
  83.         DrawText(3, 4, "Cell 2", colours.white, colours.black)
  84.         ProgressBar(10, 4, monX - 15, cell2Energy, cell2MaxEnergy, c2c, GetColourFromPercent(cell2Percent))
  85.         DrawText(monX - 4, 4, cell2Percent .. "%", colours.white, colours.black)
  86.  
  87.         sleep(1)
  88.     end
  89. end
  90.  
  91. MainFunc()
RAW Paste Data