bobmarley12345

MESystem Storage Monitor (CC)

Oct 6th, 2020 (edited)
995
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. MonitorSide = "monitor_84"
  2. -- MESystemPCSide = "appeng_me_tilecontroller_4"
  3. MESystemPCSide  = "left"
  4. Monitor = peripheral.wrap(MonitorSide)
  5. MESystemPC = peripheral.wrap(MESystemPCSide)
  6. InfoFetchDelay = 2
  7.  
  8. function ClearMonitor()
  9.     Monitor.setTextColor(colours.black)
  10.     Monitor.setBackgroundColor(colours.black)
  11.     Monitor.clear()
  12.     Monitor.setCursorPos(1,1)
  13. end
  14.  
  15. function DrawText(xPos, yPos, text, textColour, backgroundColour)
  16.     Monitor.setBackgroundColor(backgroundColour)
  17.     Monitor.setTextColor(textColour)
  18.     Monitor.setCursorPos(xPos,yPos)
  19.     Monitor.write(text)
  20. end
  21.  
  22. function DrawLine(x, y, lineLength, colour)
  23.     Monitor.setBackgroundColor(colour)
  24.     Monitor.setTextColor(colour)
  25.     Monitor.setCursorPos(x,y)
  26.     Monitor.write(string.rep(" ", lineLength))
  27. end
  28.  
  29. function ProgressBar(xPos, yPos, barLength, value, maxValue, backgroundColour, progressColour)
  30.     DrawLine(xPos, yPos, barLength, backgroundColour) --backgoround bar
  31.     local barSize = math.floor((value/maxValue) * barLength)
  32.     DrawLine(xPos, yPos, barSize, progressColour) --progress so far
  33. end
  34.  
  35. function MainFunc()
  36.     local totalBytes = MESystemPC.getTotalBytes()
  37.     local freeBytes =  MESystemPC.getFreeBytes()
  38.     local monX, monY = Monitor.getSize()
  39.  
  40.     ClearMonitor()
  41.     DrawText(2, 2, "ME System Storage Monitor", colours.white, colours.black)
  42.     DrawText(2, 3, string.rep("-", monX - 2), colours.white, colours.black)
  43.  
  44.     DrawText(2, 4, "Total Bytes", colours.white, colours.black)
  45.     DrawText(2, 5, math.floor(totalBytes / 1000000) .. " MB", colours.white, colours.black)
  46.  
  47.     DrawText(2, 6, string.rep("-", monX - 2), colours.white, colours.black)
  48.  
  49.     DrawText(2, 7, "Used Bytes", colours.white, colours.black)
  50.     local usedBytes = totalBytes - freeBytes
  51.     ProgressBar(2, 8, monX - 2, usedBytes, totalBytes, colours.grey, colours.lightBlue)
  52.  
  53.     DrawText(2, 9, string.rep("-", monX - 2), colours.white, colours.black)
  54.  
  55.     DrawText(2, 10, "Free Bytes", colours.white, colours.black)
  56.     ProgressBar(2, 11, monX - 2, freeBytes, totalBytes, colours.grey, colours.lightBlue)
  57. end
  58.  
  59. while true do
  60.     MainFunc()
  61.     sleep(InfoFetchDelay)
  62. end
RAW Paste Data