DerReuter

Turbine I

Apr 2nd, 2020 (edited)
290
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.92 KB | None | 0 0
  1. --[[
  2.    /---------------------------------\
  3.    | The Big Reactors Status Display |
  4.    \---------------------------------
  5. ]]
  6.  
  7. -- =============
  8. -- Configuration
  9. -- =============
  10.  
  11. -- This is the side on which your reactor is connected
  12. local turbine0_side = "BigReactors-Turbine_0"
  13. local turbine1_side = "BigReactors-Turbine_1"
  14. -- This is the side on which your monitor is connected
  15. local monitor_side = "right"
  16.  
  17.  
  18.  
  19. -- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  20. -- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  21.  
  22. -- If the reactor is not connected, exit the program
  23. if not peripheral.isPresent(turbine0_side) then
  24.   print("Please check, that the turbine is connected to the same side as in your config!")
  25.   return
  26. end
  27. if not peripheral.isPresent(turbine1_side) then
  28.   print("Please check, that the turbine is connected to the same side as in your config!")
  29.   return
  30. end
  31. -- If the monitor is not connected, exit
  32. if not peripheral.isPresent(monitor_side) then
  33.   print("Please check, that the monitor is connected to the same side as in your config!")
  34.   return
  35. end
  36.  
  37. -- Wrap the peripherals
  38. local t1 = peripheral.wrap(turbine0_side)
  39. local t2 = peripheral.wrap(turbine1_side)
  40. while not t1.getConnected() do sleep(10) end
  41. while not t2.getConnected() do sleep(10) end
  42. local m = peripheral.wrap(monitor_side)
  43.  
  44. print("The program is now running on the monitor!")
  45.  
  46. -- BEGIN FUNCTIONS PART
  47. function clear()
  48.   m.clear()
  49.   m.setTextColor(colors.white)
  50.   m.setBackgroundColor(colors.black)
  51.   m.setCursorPos(1, 1)
  52. end
  53.  
  54. function resetColors()
  55.   m.setTextColor(colors.white)
  56.   m.setBackgroundColor(colors.black)
  57. end
  58.  
  59. function newLine()
  60.   local x, y = m.getCursorPos()
  61.   m.setCursorPos(1, y+1)
  62. end
  63.  
  64. function drawUI()
  65.   m.write("/---------------------------\\")
  66.  
  67.   for x = 2, 19, 1 do
  68.     m.setCursorPos(1, x)
  69.         m.write("|")
  70.         m.setCursorPos(29, x)
  71.         m.write("|")
  72.   end
  73.  
  74.   m.setCursorPos(2, 8)
  75.   m.write("---------------------------")
  76.  
  77.   m.setCursorPos(1, 19)
  78.   m.write("\\---------------------------/")
  79. end
  80.  
  81. -- END FUNCTIONS PART
  82.  
  83. -- Repeat forever
  84. while true do
  85.   -- Clear the terminal
  86.   clear()
  87.   -- Draw the basic UI layout
  88.   resetColors()
  89.   drawUI()
  90.  
  91.   -- Turbine Status
  92.   local t1active = t1.getActive()
  93.   local t2active = t2.getActive()
  94.   m.setCursorPos(3, 2)
  95.   m.write("Turbine 1: ")
  96.   m.setCursorPos(3, 9)
  97.   m.write("Turbine 2: ")
  98.  
  99.   m.setCursorPos(17, 2)
  100.   if t1active then
  101.     m.setBackgroundColor(colors.green)
  102.     m.setTextColor(colors.white)
  103.     m.write("  ACTIVE  ")
  104.   else
  105.     m.setBackgroundColor(colors.red)
  106.     m.setTextColor(colors.white)
  107.     m.write(" INACTIVE ")
  108.   end
  109.  
  110.   m.setCursorPos(17, 9)
  111.   if t2active then
  112.     m.setBackgroundColor(colors.green)
  113.     m.setTextColor(colors.white)
  114.     m.write("  ACTIVE  ")
  115.   else
  116.     m.setBackgroundColor(colors.red)
  117.     m.setTextColor(colors.white)
  118.     m.write(" INACTIVE ")
  119.   end
  120.   -- END Turbine Status
  121.  
  122.   -- Turbine RPM
  123.   local rpmt1
  124.   local rpmt2
  125.   resetColors()
  126.   rpmt1 = math.ceil(t1.getRotorSpeed())
  127.   m.setCursorPos(3, 4)  
  128.   m.setTextColor(colors.white)
  129.   m.write("Rotor Speed: ")
  130.   m.setCursorPos(18, 4)
  131.   m.setTextColor(colors.yellow)
  132.   m.write(rpmt1 .. " RPM")
  133.  
  134.   rpmt2 = math.ceil(t2.getRotorSpeed())
  135.   m.setCursorPos(3, 11)  
  136.   m.setTextColor(colors.white)
  137.   m.write("Rotor Speed: ")
  138.   m.setCursorPos(18, 11)
  139.   m.setTextColor(colors.yellow)
  140.   m.write(rpmt2 .. " RPM")
  141.   -- END Turbine RPM
  142.  
  143.   -- Turbine Flow Rate
  144.   resetColors()
  145.   local flowt1
  146.   local flowt2
  147.   flowt1 = math.floor(t1.getFluidFlowRate())
  148.   m.setCursorPos(3, 5)
  149.   m.setTextColor(colors.white)
  150.   m.write("Flow Rate:")
  151.   m.setCursorPos(18, 5)
  152.   m.setTextColor(colors.cyan)
  153.   m.write(flowt1 .. " mB/T")
  154.  
  155.   flowt2 = math.floor(t2.getFluidFlowRate())
  156.   m.setCursorPos(3, 12)
  157.   m.setTextColor(colors.white)
  158.   m.write("Flow Rate:")
  159.   m.setCursorPos(18, 12)
  160.   m.setTextColor(colors.cyan)
  161.   m.write(flowt2 .. " mB/T")
  162.   -- END Flow Rate
  163.  
  164.  
  165.   -- Turbine Energy Output
  166.   resetColors()
  167.   local powert1
  168.   local powert2
  169.   powert1 = math.floor(t1.getEnergyProducedLastTick())
  170.   m.setCursorPos(3, 6)
  171.   m.setTextColor(colors.white)
  172.   m.write("Energy Output:")
  173.   m.setCursorPos(18, 6)
  174.   m.setTextColor(colors.purple)
  175.   m.write(powert1 .. " RF/T")
  176.  
  177.   powert2 = math.floor(t2.getEnergyProducedLastTick())
  178.   m.setCursorPos(3, 13)
  179.   m.setTextColor(colors.white)
  180.   m.write("Energy Output:")
  181.   m.setCursorPos(18, 13)
  182.   m.setTextColor(colors.purple)
  183.   m.write(powert2 .. " RF/T")
  184.   -- END Energy Output
  185.  
  186.   -- Total Energy
  187.   resetColors()
  188.   m.setCursorPos(8, 16)
  189.   m.setTextColor(colors.white)
  190.   m.write("Total Output:")
  191.   resetColors()
  192.   m.setCursorPos(10, 17)
  193.   m.setTextColor(colors.purple)
  194.   m.write(powert1 + powert2.. " RF/T")
  195.   -- END Total Energy
  196.  
  197.   -- Sleep for a 1/4 of a second (decreases CPU load significantly)...
  198.   sleep(1)
  199. end
Add Comment
Please, Sign In to add comment