Guest User

turbine_display

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