Advertisement
Guest User

PO2 induction matrix

a guest
Apr 25th, 2017
730
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.71 KB | None | 0 0
  1.  
  2. -- Printing right aligned text on a line
  3. -- This is used for printing our dynamic
  4. -- values to the screen properly
  5. --
  6. -- @param line The line to print on
  7. -- @param text The text to print there
  8. -- @param color The color to print in
  9. -- @return void
  10. function putValue (line, text, color)
  11. local align = 50 - string.len(text)
  12. term.setCursorPos(align, line)
  13. term.setTextColor(color)
  14. print(text)
  15. end
  16.  
  17.  
  18. -- Get a number in a human readable format
  19. -- This is used to display numbers on screen
  20. --
  21. -- @param number The number to format
  22. -- @return The formatted number
  23. function putNumber (number)
  24. local round = 0
  25. local texts = ""
  26.  
  27. if number >= 1000000000000000000 then
  28. round = (number / 1000000000000000000)
  29. texts = string.sub(round, 0, 5) .. " ERF"
  30. else
  31. if number >= 1000000000000000 then
  32. round = (number / 1000000000000000)
  33. texts = string.sub(round, 0, 5) .. " PRF"
  34. else
  35. if number >= 1000000000000 then
  36. round = (number / 1000000000000)
  37. texts = string.sub(round, 0, 5) .. " TRF"
  38. else
  39. if number >= 1000000000 then
  40. round = (number / 1000000000)
  41. texts = string.sub(round, 0, 5) .. " GRF"
  42. else
  43. if number >= 1000000 then
  44. round = (number / 1000000)
  45. texts = string.sub(round, 0, 5) .. " MRF"
  46. else
  47. if number >= 1000 then
  48. round = (number / 1000)
  49. texts = string.sub(round, 0, 5) .. " kRF"
  50. else
  51. texts = string.sub(number, 0, 5) .. " RF"
  52. end
  53. end
  54. end
  55. end
  56. end
  57. end
  58.  
  59. return texts
  60. end
  61.  
  62.  
  63.  
  64.  
  65. -- Initialize our interface!
  66. -- Find all of our peripherals
  67. monitor = peripheral.wrap("back")
  68. battery = peripheral.find("Induction Matrix")
  69.  
  70. -- Check and bind monitor
  71. if monitor == nil then
  72. error("ER: No screen found to display!")
  73. else
  74. monitor.clear()
  75. term.redirect(monitor)
  76. term.setCursorPos(1, 1)
  77. term.setBackgroundColor(colors.black)
  78. end
  79.  
  80. -- Check if we have a battery
  81. if battery == nil then
  82. error("ER: No battery connected to computer")
  83. end
  84.  
  85. -- Draw our static fill volume box
  86. term.setTextColor(colors.white)
  87. term.setCursorPos(2, 2)
  88. print("+------+")
  89. term.setCursorPos(2, 11)
  90. print("+------+")
  91. for i = 3, 10 do
  92. term.setCursorPos(2, i)
  93. print("|")
  94. term.setCursorPos(9, i)
  95. print("|")
  96. end
  97.  
  98. -- Draw our static interface text
  99. term.setCursorPos(11, 2);
  100. print("Max RF:")
  101. term.setCursorPos(11, 3);
  102. print("Max Thru:")
  103.  
  104. term.setCursorPos(11, 5);
  105. print("Cur In:")
  106. term.setCursorPos(11, 6);
  107. print("Cur Out:")
  108. term.setCursorPos(11, 7);
  109. print("Cur Bal:")
  110.  
  111. term.setCursorPos(11, 9);
  112. print("Stored:")
  113. term.setCursorPos(11, 10);
  114. print("Filled:")
  115. local term.setCursorPos(11, 11):
  116. print("word") end
  117.  
  118. -- Entering our infinite loop of checking the battery
  119. -- This will refresh all information every 2 seconds
  120. alarmIsRinging = false
  121. alarmIsActive = false
  122. alarmCounter = 0
  123.  
  124. while true do
  125.  
  126. -- Get our fixed battery values
  127. batteryMaxCharge = battery. getMaxEnergy()
  128. batteryMaxInOuts = battery. getTransferCap()
  129. putValue(2, putNumber(batteryMaxCharge), colors.lightBlue)
  130. putValue(3, putNumber(batteryMaxInOuts), colors.lightBlue)
  131.  
  132. -- Get our input/output/balance battery values
  133. batteryCurrentIn = battery. getInput()
  134. batteryCurrentOut = battery. getOutput()
  135. putValue(5, putNumber(batteryCurrentIn), colors.lightBlue)
  136. putValue(6, putNumber(batteryCurrentOut), colors.lightBlue)
  137.  
  138. batteryCurrentBalance = batteryCurrentIn - batteryCurrentOut
  139. batteryCurrentColor = (batteryCurrentBalance >= 0) and colors.green or colors.red
  140. batteryCurrentSign = (batteryCurrentBalance >= 0) and "+" or ""
  141. putValue(7, batteryCurrentSign .. putNumber(batteryCurrentBalance), batteryCurrentColor)
  142.  
  143. -- Get our statistical values
  144. batteryCurrentCharge = battery. getEnergy()
  145. putValue(9, putNumber(batteryCurrentCharge), colors.lightBlue)
  146.  
  147. batteryCurrentColor = colors.red
  148. batteryCurrentPercentage = ((batteryCurrentCharge / batteryMaxCharge) * 100)
  149. if batteryCurrentPercentage > 30 then batteryCurrentColor = colors.orange end
  150. if batteryCurrentPercentage > 60 then batteryCurrentColor = colors.green end
  151. if batteryCurrentPercentage < 95 then redstone.setOutput("top", false) end
  152. if batteryCurrentPercentage > 15 then redstone.setOutput("top", true) end
  153. if batteryCurrentPercentage < 100 then BatteryCurrentCritical = "Alert: Full Power System malfunctioning"
  154. batteryCurrentColor = colors.yellow end
  155. putValue(10, string.sub(putNumber(batteryCurrentPercentage), 0, 4) .. "%", batteryCurrentColor)
  156.  
  157. batteryCurrentCritical = "Alert: Low power"
  158. batteryCurrentColor = colors.yellow
  159. if batteryCurrentPercentage > 15 then
  160. batteryCurrentCritical = "All Systems Operational"
  161. batteryCurrentColor = colors.green end
  162. if batteryCurrentPercentage < 5 then
  163. BatteryCurrentCritical = "ERROR: Low Power System Shutdown Imminent"
  164. batteryCurrentColor = colors.red end
  165. if batteryCurrentPercentage < 0.01 then
  166. batteryCurrentCritical = " ...System offline: insert fuel..."
  167. batteryCurrentColor = colors.purple end
  168. putValue(11, batteryCurrentCritical, batteryCurrentColor)
  169.  
  170. -- Draw the current charge graph
  171. batteryCurrentColor = colors.red
  172. if batteryCurrentPercentage > 30 then term.setTextColor(colors.orange) end
  173. if batteryCurrentPercentage > 60 then term.setTextColor(colors.green) end
  174. if batteryCurrentPercentage >= 100 then term.setTextColor(colors.lightBlue) end
  175.  
  176. for i = 3, 10 do
  177. term.setCursorPos(3, i)
  178. print(" ")
  179. end
  180.  
  181. iterator = 0
  182. for i = 3, 10 do
  183. local compare = (12.5 * iterator)
  184. if (batteryCurrentPercentage >= compare) then
  185. term.setCursorPos(3, (13 - i))
  186. local filler = ""
  187. for i = 1, 6 do
  188. local inhere = (compare + (i*2))
  189. if batteryCurrentPercentage >= inhere then
  190. filler = filler .. "#"
  191. else
  192. if batteryCurrentPercentage >= (inhere - 1) then
  193. filler = filler .. "="
  194. else
  195. filler = filler .. "_"
  196. end
  197. end
  198. end
  199. print(filler)
  200. end
  201.  
  202. iterator = iterator + 1
  203. end
  204.  
  205. -- Hey, ring the alarm!
  206. if batteryCurrentPercentage > 10 then
  207. alarmIsRinging = false
  208. alarmIsActive = false
  209. end
  210.  
  211. if batteryCurrentPercentage < 10 and alarmIsActive == false then
  212. alarmIsRinging = true
  213. alarmIsActive = true
  214. alarmCounter = 0
  215. redstone.setOutput("left", true)
  216. end
  217.  
  218. if alarmIsRinging == true then
  219. alarmCounter = alarmCounter + 1
  220. if alarmCounter >= 10 then
  221. redstone.setOutput("left", false)
  222. alarmIsRinging = false
  223. end
  224. end
  225.  
  226. -- Wait 2s until next iteration
  227. os.sleep(2)
  228.  
  229. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement