bobmarley12345

ccenergygeneratedmeasurement

Oct 12th, 2020 (edited)
883
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- carrot xddddddddddd
  2. MonitorSide = "right"
  3. Cell = peripheral.wrap("left")
  4. Monitor = peripheral.wrap(MonitorSide)
  5.  
  6. function ClearMonitor()
  7.     Monitor.setTextColor(colours.black)
  8.     Monitor.setBackgroundColor(colours.black)
  9.     Monitor.clear()
  10.     Monitor.setCursorPos(1,1)
  11. end
  12.  
  13. function DrawText(xPos, yPos, text, textColour, backgroundColour)
  14.     Monitor.setBackgroundColor(backgroundColour)
  15.     Monitor.setTextColor(textColour)
  16.     Monitor.setCursorPos(xPos,yPos)
  17.     Monitor.write(text)
  18. end
  19.  
  20. function DrawLine(xPos, yPos, lineLength, colour)
  21.     Monitor.setBackgroundColor(colour)
  22.     Monitor.setTextColor(colour)
  23.     Monitor.setCursorPos(xPos,yPos)
  24.     Monitor.write(string.rep(" ", lineLength))
  25. end
  26.  
  27. function ProgressBar(xPos, yPos, width, value, maxValue, backgroundColour, progressColour)
  28.     DrawLine(xPos, yPos, width, backgroundColour) --backgoround bar
  29.     local barSize = math.floor((value/maxValue) * width)
  30.     DrawLine(xPos, yPos, barSize, progressColour) --progress so far
  31. end
  32.  
  33. function GroupBoxHeader(xPos, yPos, width, header, textColour, backgroundColour)
  34.     local headerLength = string.len(header)
  35.     local repeatChars = width - 4 - headerLength
  36.  
  37.     if (repeatChars < 0) then
  38.         repeatChars = 0
  39.     end
  40.  
  41.     local head = "--- " .. header .. " " .. string.rep("-", repeatChars)
  42.     DrawText(xPos, yPos, head, textColour, backgroundColour)
  43. end
  44.  
  45. function Main()
  46.     local termWriteCounter = 0
  47.     while true do
  48.         os.sleep(0.2)
  49.         Cell = peripheral.wrap("left")
  50.         Monitor = peripheral.wrap(MonitorSide)
  51.  
  52.         if (Cell ~= nil and Monitor ~= nil) then
  53.             local maxEnergy = Cell.getMaxEnergyStored("unknown")
  54.             local energyLastTick = Cell.getEnergyStored("unknown")
  55.             local currentTicks = os.clock() * 20
  56.             local energyNextTicks = Cell.getEnergyStored("unknown")
  57.             local nextTicks = os.clock() * 20
  58.             local tickDifference = (nextTicks - currentTicks)
  59.             local energyDifference = math.ceil(energyNextTicks - energyLastTick)
  60.             local tickEnergyDifference
  61.            
  62.             if (tickDifference > 0) then
  63.                 tickEnergyDifference = energyDifference / tickDifference
  64.             else
  65.                 tickEnergyDifference = energyDifference
  66.             end
  67.            
  68.             term.clear()
  69.             term.setCursorPos(1, 1)
  70.             print("Max Energy: " .. maxEnergy)
  71.             print("Energy stored last tick: " .. energyLastTick .. " RF/t")
  72.             print("Energy stored last tick: " .. energyLastTick / 1000  .. " KiRF/t")
  73.             print("Energy stored next tick: " .. energyNextTicks)
  74.             print("Energy stored next tick: " .. energyNextTicks / 1000  .. " KiRF/t")
  75.             print("Energy Difference: " .. energyDifference .. " RF/t")
  76.             print("Energy Difference: " .. energyDifference / 1000 .. " KiRF/t")
  77.             print("Last Tick time: " .. currentTicks)
  78.             print("Next Tick time: " .. nextTicks)
  79.             print("Tick Difference: " .. tickDifference)
  80.             print("Energy Difference over passed ticks: " .. tickEnergyDifference)
  81.  
  82.             local finalEnergyDifference = tickEnergyDifference / 1000
  83.  
  84.             print("Energy Difference over passed ticks: " .. tickEnergyDifference .. " KiRF/t")
  85.  
  86.             local w, h = Monitor.getSize()
  87.             ClearMonitor()
  88.             DrawText(2, 2, "Energy Stored", colours.white, colours.black)
  89.             ProgressBar(2, 4, w - 2, energyNextTicks, maxEnergy, colours.grey, colours.green)
  90.             GroupBoxHeader(2, 6, w - 2, "Generated Energy", colours.cyan, colours.black)
  91.             DrawText(2, 8, finalEnergyDifference .. " KiRF/t Generated", colours.white, colours.black)
  92.         end
  93.     end
  94. end
  95.  
  96. Main()
RAW Paste Data