yoyoyyoghurtboyyyy

Untitled

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