bobmarley12345

MESystem Storage Monitor (CC)

Oct 6th, 2020 (edited)
1,178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.37 KB | None | 0 0
  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 = 5
  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.     if (MESystemPC == nil) then
  37.         MESystemPC = peripheral.wrap(MESystemPCSide)
  38.         return
  39.     end
  40.     if (Monitor == nil) then
  41.         Monitor = peripheral.wrap(MonitorSide)
  42.         return
  43.     end
  44.     local totalBytes = MESystemPC.getTotalBytes()
  45.     local freeBytes =  MESystemPC.getFreeBytes()
  46.     local monX, monY = Monitor.getSize()
  47.  
  48.     ClearMonitor()
  49.     DrawText(2, 2, "ME System Storage Monitor", colours.white, colours.black)
  50.     DrawText(2, 3, string.rep("-", monX - 2), colours.white, colours.black)
  51.  
  52.     DrawText(2, 4, "Total Bytes", colours.white, colours.black)
  53.     DrawText(2, 5, math.floor(totalBytes / 1000000) .. " MB", colours.white, colours.black)
  54.  
  55.     DrawText(2, 6, string.rep("-", monX - 2), colours.white, colours.black)
  56.  
  57.     DrawText(2, 7, "Used Bytes", colours.white, colours.black)
  58.     local usedBytes = totalBytes - freeBytes
  59.     ProgressBar(2, 8, monX - 2, usedBytes, totalBytes, colours.grey, colours.lightBlue)
  60.  
  61.     DrawText(2, 9, string.rep("-", monX - 2), colours.white, colours.black)
  62.  
  63.     DrawText(2, 10, "Free Bytes", colours.white, colours.black)
  64.     ProgressBar(2, 11, monX - 2, freeBytes, totalBytes, colours.grey, colours.lightBlue)
  65. end
  66.  
  67. while true do
  68.     MainFunc()
  69.     sleep(InfoFetchDelay)
  70. end
Add Comment
Please, Sign In to add comment