Advertisement
Guest User

GTOC power monitor

a guest
Feb 15th, 2016
655
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.87 KB | None | 0 0
  1. local component = require("component")
  2. local sides = require("sides")
  3. local powerbox = component.inventory_controller
  4. local battery1 = {}
  5. local battery2 = {}
  6. local battery3 = {}
  7. local battery4 = {}
  8. local battery5 = {}
  9. local battery6 = {}
  10. local battery7 = {}
  11. local battery8 = {}
  12. local battery9 = {}
  13. local battery10 = {}
  14. local battery11 = {}
  15. local battery12 = {}
  16. local battery13 = {}
  17. local battery14 = {}
  18. local battery15 = {}
  19. local battery16 = {}
  20.  
  21. local gpu = component.gpu
  22. local w, h = gpu.getResolution()
  23. local refreshRate = 5
  24.  
  25. local EUtotal = 0
  26. local EUMax = 0
  27. local EUprevious = 0
  28. local EUchange = 1
  29.  
  30. gpu.fill(1, 1, w, h, " ")
  31.  
  32. gpu.set(1, 1, "         Doomascus Power Stats         ")
  33.  
  34. local function round(num) return math.floor(num+.5) end
  35.  
  36. local function pollBatteries()
  37. battery1 = powerbox.getStackInSlot(sides.bottom, 1)
  38. battery2 = powerbox.getStackInSlot(sides.bottom, 2)
  39. battery3 = powerbox.getStackInSlot(sides.bottom, 3)
  40. battery4 = powerbox.getStackInSlot(sides.bottom, 4)
  41. battery5 = powerbox.getStackInSlot(sides.bottom, 5)
  42. battery6 = powerbox.getStackInSlot(sides.bottom, 6)
  43. battery7 = powerbox.getStackInSlot(sides.bottom, 7)
  44. battery8 = powerbox.getStackInSlot(sides.bottom, 8)
  45. battery9 = powerbox.getStackInSlot(sides.bottom, 9)
  46. battery10 = powerbox.getStackInSlot(sides.bottom, 10)
  47. battery11 = powerbox.getStackInSlot(sides.bottom, 11)
  48. battery12 = powerbox.getStackInSlot(sides.bottom, 12)
  49. battery13 = powerbox.getStackInSlot(sides.bottom, 13)
  50. battery14 = powerbox.getStackInSlot(sides.bottom, 14)
  51. battery15 = powerbox.getStackInSlot(sides.bottom, 15)
  52. battery16 = powerbox.getStackInSlot(sides.bottom, 16)
  53. end
  54.  
  55. local function addEU()
  56. EUMax = 0
  57. EUtotal = 0
  58. if battery1 ~= nil then
  59. EUtotal = EUtotal + battery1.charge
  60. EUMax = EUMax + battery1.maxCharge
  61. end
  62. if battery2 ~= nil then
  63. EUtotal = EUtotal + battery2.charge
  64. EUMax = EUMax + battery2.maxCharge
  65. end
  66. if battery3 ~= nil then
  67. EUtotal = EUtotal + battery3.charge
  68. EUMax = EUMax + battery3.maxCharge
  69. end
  70. if battery4 ~= nil then
  71. EUtotal = EUtotal + battery4.charge
  72. EUMax = EUMax + battery4.maxCharge
  73. end
  74. if battery5 ~= nil then
  75. EUtotal = EUtotal + battery5.charge
  76. EUMax = EUMax + battery5.maxCharge
  77. end
  78. if battery6 ~= nil then
  79. EUtotal = EUtotal + battery6.charge
  80. EUMax = EUMax + battery6.maxCharge
  81. end
  82. if battery7 ~= nil then
  83. EUtotal = EUtotal + battery7.charge
  84. EUMax = EUMax + battery7.maxCharge
  85. end
  86. if battery8 ~= nil then
  87. EUtotal = EUtotal + battery8.charge
  88. EUMax = EUMax + battery8.maxCharge
  89. end
  90. if battery9 ~= nil then
  91. EUtotal = EUtotal + battery9.charge
  92. EUMax = EUMax + battery9.maxCharge
  93. end
  94. if battery10 ~= nil then
  95. EUtotal = EUtotal + battery10.charge
  96. EUMax = EUMax + battery10.maxCharge
  97. end
  98. if battery11 ~= nil then
  99. EUtotal = EUtotal + battery11.charge
  100. EUMax = EUMax + battery11.maxCharge
  101. end
  102. if battery12 ~= nil then
  103. EUtotal = EUtotal + battery12.charge
  104. EUMax = EUMax + battery12.maxCharge
  105. end
  106. if battery13 ~= nil then
  107. EUtotal = EUtotal + battery13.charge
  108. EUMax = EUMax + battery13.maxCharge
  109. end
  110. if battery14 ~= nil then
  111. EUtotal = EUtotal + battery14.charge
  112. EUMax = EUMax + battery14.maxCharge
  113. end
  114. if battery15 ~= nil then
  115. EUtotal = EUtotal + battery15.charge
  116. EUMax = EUMax + battery15.maxCharge
  117. end
  118. if battery16 ~= nil then
  119. EUtotal = EUtotal + battery16.charge
  120. EUMax = EUMax + battery16.maxCharge
  121. end
  122.  
  123. if EUprevious > EUtotal then
  124. EUchange = 0
  125. else
  126. EUchange = 1
  127. end
  128.  
  129. EUprevious = EUtotal
  130. end
  131.  
  132. local function drawScreen()
  133. pollBatteries()
  134. addEU()
  135. gpu.fill(1, 2, w, h, " ")
  136. gpu.set(1, 2, "Stored: " .. EUtotal .. " EU")
  137. gpu.set(1, 3, "Max: " .. EUMax .. " EU")
  138. gpu.set(1, 4, "Storage Percent: " .. tostring(round(((EUtotal/EUMax)*100))) .. "%")
  139.  
  140. if EUchange == 0 then
  141. gpu.set(1, 5, "Power Levels: !!SHORTAGE!!")
  142. else
  143. gpu.set(1, 5, "Power Levels: OPTIMAL.")
  144. end
  145.  
  146. end
  147.  
  148. drawScreen()
  149.  
  150. while true do
  151.     drawScreen()
  152.     os.sleep(refreshRate)
  153. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement