Advertisement
Aguia_016

test

Mar 1st, 2024
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.77 KB | None | 0 0
  1. -- This file contains functions for controlling a turbine system
  2.  
  3. -- Clear the terminal screen
  4. function clear()
  5. mon.setBackgroundColor(colors.black)
  6. mon.clear()
  7. mon.setCursorPos(1,1)
  8. end
  9.  
  10. -- Draw text on the terminal screen
  11. function draw_text_term(x, y, text, text_color, bg_color)
  12. term.setTextColor(text_color)
  13. term.setBackgroundColor(bg_color)
  14. term.setCursorPos(x,y)
  15. write(text)
  16. end
  17.  
  18. -- Draw text on the monitor screen
  19. function draw_text(x, y, text, text_color, bg_color)
  20. mon.setBackgroundColor(bg_color)
  21. mon.setTextColor(text_color)
  22. mon.setCursorPos(x,y)
  23. mon.write(text)
  24. end
  25.  
  26. -- Draw a line on the monitor screen
  27. function draw_line(x, y, length, color)
  28. mon.setBackgroundColor(color)
  29. mon.setCursorPos(x,y)
  30. mon.write(string.rep(" ", length))
  31. end
  32.  
  33. -- Draw a line on the terminal screen
  34. function draw_line_term(x, y, length, color)
  35. term.setBackgroundColor(color)
  36. term.setCursorPos(x,y)
  37. term.write(string.rep(" ", length))
  38. end
  39.  
  40. -- Draw a progress bar on the monitor screen
  41. function progress_bar(x, y, length, minVal, maxVal, bar_color, bg_color)
  42. draw_line(x, y, length, bg_color) --background bar
  43. local barSize = math.floor((minVal/maxVal) * length)
  44. draw_line(x, y, barSize, bar_color) --progress so far
  45. end
  46.  
  47. -- Draw a progress bar on the terminal screen
  48. function progress_bar_term(x, y, length, minVal, maxVal, bar_color, bg_color)
  49. draw_line_term(x, y, length, bg_color) --background bar
  50. local barSize = math.floor((minVal/maxVal) * length)
  51. draw_line_term(x, y, barSize, bar_color) --progress so far
  52. end
  53.  
  54. -- Draw the menu bar on the monitor screen
  55. function menu_bar()
  56. draw_line(1, 1, monX, colors.blue)
  57. draw_text(2, 1, " Turbine Control", colors.white, colors.blue)
  58. draw_line(1, 19, monX, colors.blue)
  59. draw_text(2, 19, " Turbine Control", colors.white, colors.blue)
  60. end
  61.  
  62. -- Main function for displaying turbine homepage
  63. function turbine_homepage()
  64. while true do
  65. clear()
  66. menu_bar()
  67. terminal_screen()
  68.  
  69. -- Get turbine status
  70. active = turbine.getActive()
  71. energy_stored = turbine.getEnergyStored()
  72.  
  73. -- Display power status
  74. draw_text(2, 3, "Status: ", colors.yellow, colors.black)
  75. if active then
  76. draw_text(10, 3, "ONLINE", colors.lime, colors.black)
  77. else
  78. draw_text(10, 3, "OFFLINE", colors.red, colors.black)
  79. end
  80.  
  81. -- Display router speed
  82. draw_text(2, 5, "Router Speed: ", colors.yellow, colors.black)
  83. local maxVal = 2000
  84. local minVal = math.floor(turbine.getRotorSpeed())
  85. draw_text(19, 5, minVal.." rpm", colors.white, colors.black)
  86.  
  87. -- Draw progress bar based on router speed
  88. if minVal < 700 then
  89. progress_bar(2, 6, monX-2, minVal, maxVal, colors.lightBlue, colors.gray)
  90. elseif minVal < 900 then
  91. progress_bar(2, 6, monX-2, minVal, maxVal, colors.lime, colors.gray)
  92. elseif minVal < 1700 then
  93. progress_bar(2, 6, monX-2, minVal, maxVal, colors.lightBlue, colors.gray)
  94. elseif minVal < 1900 then
  95. progress_bar(2, 6, monX-2, minVal, maxVal, colors.lime, colors.gray)
  96. elseif minVal < 2000 then
  97. progress_bar(2, 6, monX-2, minVal, maxVal, colors.yellow, colors.gray)
  98. elseif minVal >= 2000 then
  99. progress_bar(2, 6, monX-2, minVal, maxVal, colors.red, colors.gray)
  100. end
  101.  
  102. -- Display steam level
  103. draw_text(2, 8, "Steam Amount: ", colors.yellow, colors.black)
  104. local maxVal = 4000
  105. local minVal = math.floor(turbine.getInputAmount())
  106. draw_text(19, 8, minVal.." mB", colors.white, colors.black)
  107. progress_bar(2, 9, monX-2, minVal, maxVal, colors.lightGray, colors.gray)
  108.  
  109. -- Display water level
  110. draw_text(2, 11, "Water Amount: ", colors.yellow, colors.black)
  111. local maxVal = 4000
  112. local minVal = math.floor(turbine.getOutputAmount())
  113. draw_text(19, 11, minVal.." mB", colors.white, colors.black)
  114. progress_bar(2, 12, monX-2, minVal, maxVal, colors.blue, colors.gray)
  115.  
  116. -- Display RF production
  117. draw_text(2, 14, "RF/tick: ", colors.yellow, colors.black)
  118. rft = math.floor(turbine.getEnergyProducedLastTick())
  119. draw_text(19, 14, rft.." RF/T", colors.white, colors.black)
  120.  
  121. -- Display RF storage
  122. draw_text(2, 15, "RF Stored:", colors.yellow, colors.black)
  123. local maxVal = 1000000
  124. local minVal = energy_stored
  125. local percent = math.floor((energy_stored/maxVal)*100)
  126. draw_text(19, 15, percent.."%", colors.white, colors.black)
  127.  
  128. -- Display flow rate
  129. draw_text(2, 16, "Flow Rate: ", colors.yellow, colors.black)
  130. flow_rate = turbine.getFluidFlowRateMax()
  131. draw_text(19, 16, flow_rate.." mB/t", colors.white, colors.black)
  132.  
  133. -- Display coil status
  134. engaged = turbine.getInductorEngaged()
  135. draw_text(2, 17, "Coils: ", colors.yellow, colors.black)
  136. if engaged then
  137. draw_text(19, 17, "Engaged", colors.lime, colors.black)
  138. else
  139. draw_text(19, 17, "Disengaged", colors.red, colors.black)
  140. end
  141.  
  142. sleep(0.5)
  143. end
  144. end
  145.  
  146. -- Function for displaying terminal screen
  147. function terminal_screen()
  148. term.clear()
  149. draw_line_term(1, 1, 55, colors.blue)
  150. draw_text_term(13, 1, "Turbine Control", colors.white, colors.blue)
  151. draw_line_term(1, 19, 55, colors.blue)
  152. draw_text_term(13, 19, "by jaranvil aka jared314", colors.white, colors.blue)
  153.  
  154. draw_text_term(1, 3, "Current program:", colors.white, colors.black)
  155. draw_text_term(1, 4, "Turbine Control v", colors.blue, colors.black)
  156.  
  157. draw_text_term(1, 6, "Installer:", colors.white, colors.black)
  158. draw_text_term(1, 7, "pastebin.com/p4zeq7Ma", colors.blue, colors.black)
  159.  
  160. draw_text_term(1, 9, "Please give me your feedback, suggestions,", colors.white, colors.black)
  161. draw_text_term(1, 10, "and errors!", colors.white, colors.black)
  162.  
  163. draw_text_term(1, 11, "reddit.com/r/br_controls", colors.blue, colors.black)
  164. end
  165.  
  166. -- Function for testing turbine connection
  167. function test_turbine_connection()
  168. turbine = peripheral.wrap(name) --wrap turbine
  169. c = turbine.getConnected()
  170. if unexpected_condition then error() end
  171. end
  172.  
  173. -- Function for testing monitor connection
  174. function test_monitor_connection()
  175. mon = peripheral.wrap(side) --wrap monitor
  176. monX, monY = mon.getSize() --get monitor size
  177. if unexpected_condition then error() end
  178. end
  179.  
  180. -- Test if the entered monitor and turbine can be wrapped
  181. function test_configs()
  182. term.clear()
  183. draw_line_term(1, 1, 55, colors.blue)
  184. draw_text_term(10, 1, "BigReactor Controls v", colors.white, colors.blue)
  185. draw_line_term(1, 19, 55, colors.blue)
  186. draw_text_term(10, 19, "by jaranvil aka jared314", colors.white, colors.blue)
  187. sleep(.4)
  188. draw_text_term(1, 3, "Wrapping peripherals...", colors.blue, colors.black)
  189. sleep(.15)
  190. draw_text_term(2, 5, "wrap monitor...", colors.white, colors.black)
  191. sleep(0.1)
  192. if pcall(test_monitor_connection) then
  193. draw_text_term(18, 5, "success", colors.lime, colors.black)
  194. else
  195. draw_text_term(1, 4, "Error:", colors.red, colors.black)
  196. draw_text_term(1, 8, "Could not connect to monitor on right", colors.red, colors.black)
  197. draw_text_term(1, 9, "Valid sides are 'left', 'right', 'top', 'bottom' and 'back'", colors.white, colors.black)
  198. draw_text_term(1, 11, "Press Enter to continue...", colors.gray, colors.black)
  199. wait = read()
  200. end
  201.  
  202. sleep(0.1)
  203. draw_text_term(2, 6, "wrap turbine...", colors.white, colors.black)
  204. sleep(0.1)
  205. if pcall(test_turbine_connection) then
  206. draw_text_term(18, 6, "success", colors.lime, colors.black)
  207. else
  208. draw_text_term(1, 8, "Error:", colors.red, colors.black)
  209. draw_text_term(1, 9, "Could not connect to ", colors.red, colors.black)
  210. draw_text_term(1, 10, "Turbine must be connected with networking cable and wired modem", colors.white, colors.black)
  211. draw_text_term(1, 12, "Press Enter to continue...", colors.gray, colors.black)
  212. wait = read()
  213. end
  214.  
  215. sleep(0.1)
  216. draw_text_term(1, 10, "Setup Complete!", colors.lime, colors.black)
  217. sleep(3)
  218.  
  219. auto = auto_string == "true"
  220. turbine_homepage()
  221. end
  222.  
  223. -- Function for starting the program
  224. function start()
  225. for k,v in pairs(rs.getSides()) do
  226. if peripheral.getType(v) == "BigReactors-Turbine" then
  227. name = v
  228. elseif peripheral.getType(v) == "monitor" then
  229. side = v
  230. end
  231. end
  232. test_configs()
  233. clear()
  234. end
  235.  
  236. start()
  237.  
Tags: test
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement