Evdev

reactor_control

Jul 16th, 2019
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --  BigReactor Control
  2. --  by jaranvil aka jared314
  3. --
  4. --  feel free to use and/or modify this code
  5. --
  6. -----------------------------------------------
  7. --Reactor Control - Version History
  8. --
  9. --  Version 2.3 - April 23/15
  10. --    - First update in awhile
  11. --    - lots of minor fixes and improvments
  12. --    - New loading and setup search with automated peripheral search
  13. --    - Changes to the update methods
  14. --    - Except new updates soon
  15.  
  16.  
  17. -----------------------------------------------
  18.  
  19. local version = 2.3
  20. --is auto power enabled
  21. local auto_string = true
  22. --auto on value
  23. local on = 0
  24. --auto off value
  25. local off = 100
  26. --is auto control rods enabled
  27. local auto_rods = true
  28. --control rod auto value
  29. local auto_rf = 0
  30.  
  31. --peripherals
  32. local reactor
  33. local mon
  34.  
  35. --monitor size
  36. local monX
  37. local monY
  38.  
  39. term.clear()
  40. -------------------FORMATTING-------------------------------
  41. function clear()
  42.   mon.setBackgroundColor(colors.black)
  43.   mon.clear()
  44.   mon.setCursorPos(1,1)
  45. end
  46.  
  47. --display text on computer's terminal screen
  48. function draw_text_term(x, y, text, text_color, bg_color)
  49.   term.setTextColor(text_color)
  50.   term.setBackgroundColor(bg_color)
  51.   term.setCursorPos(x,y)
  52.   write(text)
  53.  
  54. end
  55.  
  56. --display text text on monitor, "mon" peripheral
  57. function draw_text(x, y, text, text_color, bg_color)
  58.   mon.setBackgroundColor(bg_color)
  59.   mon.setTextColor(text_color)
  60.   mon.setCursorPos(x,y)
  61.   mon.write(text)
  62. end
  63.  
  64. --draw line on computer terminal
  65. function draw_line(x, y, length, color)
  66.     mon.setBackgroundColor(color)
  67.     mon.setCursorPos(x,y)
  68.     mon.write(string.rep(" ", length))
  69. end
  70.  
  71. --draw line on computer terminal
  72. function draw_line_term(x, y, length, color)
  73.     term.setBackgroundColor(color)
  74.     term.setCursorPos(x,y)
  75.     term.write(string.rep(" ", length))
  76. end
  77.  
  78. --create progress bar
  79. --draws two overlapping lines
  80. --background line of bg_color
  81. --main line of bar_color as a percentage of minVal/maxVal
  82. function progress_bar(x, y, length, minVal, maxVal, bar_color, bg_color)
  83.   draw_line(x, y, length, bg_color) --backgoround bar
  84.   local barSize = math.floor((minVal/maxVal) * length)
  85.   draw_line(x, y, barSize, bar_color) --progress so far
  86. end
  87.  
  88. --same as above but on the computer terminal
  89. function progress_bar_term(x, y, length, minVal, maxVal, bar_color, bg_color)
  90.   draw_line_term(x, y, length, bg_color) --backgoround bar
  91.   local barSize = math.floor((minVal/maxVal) * length)
  92.   draw_line_term(x, y, barSize, bar_color)  --progress so far
  93. end
  94.  
  95. --create button on monitor
  96. function button(x, y, length, text, txt_color, bg_color)
  97.   draw_line(x, y, length, bg_color)
  98.   draw_text((x+2), y, text, txt_color, bg_color)
  99. end
  100.  
  101. --header and footer bars on monitor
  102. function menu_bar()
  103.   draw_line(1, 1, monX, colors.blue)
  104.   draw_text(2, 1, "Power    Tools    Settings", colors.white, colors.blue)
  105.   draw_line(1, 19, monX, colors.blue)
  106.   draw_text(2, 19, "     Reactor Control", colors.white, colors.blue)
  107. end
  108.  
  109. --dropdown menu for power options
  110. function power_menu()
  111.   draw_line(1, 2, 9, colors.gray)
  112.   draw_line(1, 3, 9, colors.gray)
  113.   draw_line(1, 4, 9, colors.gray)
  114.   if active then
  115.     draw_text(2, 2, "ON", colors.lightGray, colors.gray)
  116.     draw_text(2, 3, "OFF", colors.white, colors.gray)
  117.   else
  118.     draw_text(2, 2, "ON", colors.white, colors.gray)
  119.     draw_text(2, 3, "OFF", colors.lightGray, colors.gray)
  120.   end
  121.   draw_text(2, 4, "Auto", colors.white, colors.gray)
  122. end
  123.  
  124. --dropbox menu for tools
  125. function tools_menu()
  126.   draw_line(10, 2, 14, colors.gray)
  127.   draw_line(10, 3, 14, colors.gray)
  128.   draw_line(10, 4, 14, colors.gray)
  129.   draw_line(10, 5, 14, colors.gray)
  130.   draw_text(11, 2, "Control Rods", colors.white, colors.gray)
  131.   draw_text(11, 3, "Efficiency", colors.white, colors.gray)
  132.   draw_text(11, 4, "Fuel", colors.white, colors.gray)
  133.   draw_text(11, 5, "Waste", colors.white, colors.gray)
  134. end
  135.  
  136. --dropdown menu for settings
  137. function settings_menu()
  138.   draw_line(12, 2, 18, colors.gray)
  139.   draw_line(12, 3, 18, colors.gray)
  140.   draw_text(13, 2, "Check for Updates", colors.white, colors.gray)
  141.   draw_text(13, 3, "Reset peripherals", colors.white, colors.gray)
  142. end
  143.  
  144. --basic popup screen with title bar and exit button
  145. function popup_screen(y, title, height)
  146.   clear()
  147.   menu_bar()
  148.  
  149.   draw_line(4, y, 22, colors.blue)
  150.   draw_line(25, y, 1, colors.red)
  151.  
  152.   for counter = y+1, height+y do
  153.     draw_line(4, counter, 22, colors.white)
  154.   end
  155.  
  156.   draw_text(25, y, "X", colors.white, colors.red)
  157.   draw_text(5, y, title, colors.white, colors.blue)
  158. end
  159.  
  160. --write settings to config file
  161. function save_config()
  162.   sw = fs.open("config.txt", "w")  
  163.     sw.writeLine(version)
  164.     sw.writeLine(auto_string)
  165.     sw.writeLine(on)
  166.     sw.writeLine(off)
  167.     sw.writeLine(auto_rods)
  168.     sw.writeLine(auto_rf)
  169.   sw.close()
  170. end
  171.  
  172. --read settings from file
  173. function load_config()
  174.   sr = fs.open("config.txt", "r")
  175.     version = tonumber(sr.readLine())
  176.     auto_string = sr.readLine()
  177.     on = tonumber(sr.readLine())
  178.     off = tonumber(sr.readLine())
  179.     auto_rods = sr.readLine()
  180.     auto_rf = tonumber(sr.readLine())
  181.   sr.close()
  182. end
  183.  
  184. ------------------------END FORMATTING--------------------------
  185.  
  186. --
  187. function homepage()
  188.   while true do
  189.     clear()
  190.     menu_bar()
  191.     terminal_screen()
  192.  
  193.     energy_stored = reactor.getEnergyStored()
  194.    
  195.     --------POWER STAT--------------
  196.     draw_text(2, 3, "Power:", colors.yellow, colors.black)
  197.     active = reactor.getActive()
  198.     if active then
  199.       draw_text(10, 3, "ONLINE", colors.lime, colors.black)
  200.     else
  201.       draw_text(10, 3, "OFFLINE", colors.red, colors.black)
  202.     end
  203.  
  204.     -----------FUEL---------------------
  205.     draw_text(2, 5, "Fuel Level:", colors.yellow, colors.black)
  206.     local maxVal = reactor.getFuelAmountMax()
  207.     local minVal = reactor.getFuelAmount()
  208.     local percent = math.floor((minVal/maxVal)*100)
  209.     draw_text(15, 5, percent.."%", colors.white, colors.black)
  210.  
  211.     if percent < 25 then
  212.     progress_bar(2, 6, monX-2, minVal, maxVal, colors.red, colors.gray)
  213.     elseif percent < 50 then
  214.     progress_bar(2, 6, monX-2, minVal, maxVal, colors.orange, colors.gray)
  215.     elseif percent < 75 then
  216.     progress_bar(2, 6, monX-2, minVal, maxVal, colors.yellow, colors.gray)
  217.     elseif percent <= 100 then
  218.     progress_bar(2, 6, monX-2, minVal, maxVal, colors.lime, colors.gray)
  219.     end
  220.     end
  221.     end
  222.     end
  223.  
  224.     -----------ROD HEAT---------------
  225.     --draw_text(2, 8, "Fuel Temp:", colors.yellow, colors.black)
  226.     --local maxFuelVal = 2000
  227.     --local minFuelVal = reactor.getFuelTemperature()
  228.  
  229.     --if minFuelVal < 500 then
  230.     --progress_bar(2, 9, monX-2, minFuelVal, maxFuelVal, colors.lime, colors.gray)
  231.     --elseif minFuelVal < 1000 then
  232.     --progress_bar(2, 9, monX-2, minFuelVal, maxFuelVal, colors.yellow, colors.gray)
  233.    -- elseif minFuelVal < 1500 then  
  234.     --progress_bar(2, 9, monX-2, minFuelVal, maxFuelVal, colors.orange, colors.gray)
  235.     --elseif minFuelVal < 2000 then
  236.     --progress_bar(2, 9, monX-2, minFuelVal, maxFuelVal, colors.red, colors.gray)
  237.     --elseif minVal >= 2000 then
  238.     --progress_bar(2, 9, monX-2, 2000, maxFuelVal, colors.red, colors.gray)
  239.     --end
  240.     --end
  241.     --end
  242.     --end
  243.     --end
  244.  
  245.     --draw_text(15, 8, math.floor(minFuelVal).."/"..maxFuelVal, colors.white, colors.black)
  246.  
  247.     -----------CASING HEAT---------------
  248.     --draw_text(2, 11, "Casing Temp:", colors.yellow, colors.black)
  249.     --local maxVal = 2000
  250.     --local minVal = math.floor(reactor.getCasingTemperature())
  251.     --if minVal < 500 then
  252.     --progress_bar(2, 12, monX-2, minVal, maxVal, colors.lime, colors.gray)
  253.     --elseif minVal < 1000 then
  254.     --progress_bar(2, 12, monX-2, minVal, maxVal, colors.yellow, colors.gray)
  255.     --elseif minVal < 1500 then  
  256.     --progress_bar(2, 12, monX-2, minVal, maxVal, colors.orange, colors.gray)
  257.     --elseif minVal < 2000 then
  258.     --progress_bar(2, 12, monX-2, minVal, maxVal, colors.red, colors.gray)
  259.     --elseif minVal >= 2000 then
  260.       --progress_bar(2, 12, monX-2, 2000, maxVal, colors.red, colors.gray)
  261.     --end
  262.     --end
  263.     --end
  264.     --end
  265.     --end
  266.     --draw_text(15, 11, math.floor(minVal).."/"..maxVal, colors.white, colors.black)
  267.  
  268.     -------------OUTPUT-------------------
  269.    -- if reactor.isActivelyCooled() then
  270.  
  271.      -- draw_text(2, 14, "mB/tick:", colors.yellow, colors.black)
  272.      -- mbt = math.floor(reactor.getHotFluidProducedLastTick())
  273.       --draw_text(13, 14, mbt.." mB/t", colors.white, colors.black)
  274.  
  275.     --else
  276.  
  277.       --draw_text(2, 14, "RF/tick:", colors.yellow, colors.black)
  278.       rft = math.floor(reactor.getEnergyProducedLastTick())
  279.       --draw_text(13, 14, rft.." RF/T", colors.white, colors.black)
  280.  
  281.     --end
  282.  
  283.     ------------STORAGE------------
  284.     --if reactor.isActivelyCooled() then
  285.  
  286.     --  draw_text(2, 15, "mB Stored:", colors.yellow, colors.black)
  287.     --  fluid_stored = reactor.getHotFluidAmount()
  288.     --  fluid_max = reactor.getHotFluidAmountMax()
  289.     --  fluid_stored_percent = math.floor((fluid_stored/fluid_max)*100)
  290.     --  draw_text(13, 15, fluid_stored_percent.."% ("..fluid_stored.." mB)", colors.white, colors.black)
  291.  
  292.    -- else
  293.  
  294.       --draw_text(2, 15, "RF Stored:", colors.yellow, colors.black)
  295.       energy_stored_percent = math.floor((energy_stored/10000000)*100)
  296.       --draw_text(13, 15, energy_stored_percent.."% ("..energy_stored.." RF)", colors.white, colors.black)
  297.  
  298.  
  299.     --end
  300.  
  301.     -------------AUTO CONTROL RODS-----------------------
  302.     auto_rods_bool = auto_rods == "true"
  303.     insertion_percent = reactor.getControlRodLevel(0)
  304.  
  305.     --if reactor.isActivelyCooled() then
  306.     --draw_text(16, 16, insertion_percent.."%", colors.white, colors.black)
  307.     --else
  308.       if auto_rods_bool then
  309.         if active then
  310.           if rft > auto_rf+50 then
  311.             reactor.setAllControlRodLevels(insertion_percent+1)
  312.           elseif rft < auto_rf-50 then
  313.             reactor.setAllControlRodLevels(insertion_percent-1)
  314.                end
  315.           end
  316.         end
  317.  
  318.         draw_text(2, 16, "Control Rods:", colors.yellow, colors.black)
  319.         draw_text(16, 16, insertion_percent.."%", colors.white, colors.black)
  320.         draw_text(21, 16, "(Auto)", colors.red, colors.black)
  321.      
  322.       else
  323.         draw_text(2, 16, "Control Rods:", colors.yellow, colors.black)
  324.         draw_text(16, 16, insertion_percent.."%", colors.white, colors.black)
  325.    
  326.       end
  327.    
  328.  
  329.     -------------AUTO SHUTOFF--------------------------
  330.     --if reactor.isActivelyCooled() then
  331.  
  332.       --i dont know what I should do here
  333.  
  334.  
  335.    -- else
  336.       draw_text(13, 15, "Auto Shutoff Function", colors.white, colors.black)
  337.       auto = auto_string == "true"
  338.       if auto then
  339.         if active then
  340.           draw_text(2, 17, "Auto off:", colors.yellow, colors.black)
  341.           draw_text(13, 17, off.."% RF Stored", colors.white, colors.black)
  342.           if energy_stored_percent >= off then
  343.             reactor.setActive(false)
  344.             call_homepage()
  345.           end
  346.         else
  347.           draw_text(2, 17, "Auto on:", colors.yellow, colors.black)
  348.           draw_text(13, 17, on.."% RF Stored", colors.white, colors.black)
  349.           if energy_stored_percent <= on then
  350.             reactor.setActive(true)
  351.             call_homepage()
  352.           end
  353.         end
  354.       else
  355.         draw_text(2, 17, "Auto power:", colors.yellow, colors.black)
  356.         draw_text(14, 17, "disabled", colors.red, colors.black)
  357.       end
  358.     end
  359.  
  360.     sleep(0.5)
  361.   --end
  362. --end
  363.  
  364. --------------MENU SCREENS--------------
  365.  
  366. --auto power menu
  367. function auto_off()
  368.     draw_text(13, 15, "Menu Screens", colors.white, colors.black)
  369.   auto = auto_string == "true"
  370.   if auto then --auto power enabled
  371.  
  372.     popup_screen(3, "Auto Power", 11)
  373.     draw_text(5, 5, "Enabled", colors.lime, colors.white)
  374.     draw_text(15, 5, " disable ", colors.white, colors.black)
  375.    
  376.     draw_text(5, 7, "ON when storage =", colors.gray, colors.white)
  377.     draw_text(5, 8, " - ", colors.white, colors.black)
  378.     draw_text(13, 8, on.."% RF", colors.black, colors.white)
  379.     draw_text(22, 8, " + ", colors.white, colors.black)
  380.  
  381.     draw_text(5, 10, "OFF when storage =", colors.gray, colors.white)
  382.     draw_text(5, 11, " - ", colors.white, colors.black)
  383.     draw_text(13, 11, off.."% RF", colors.black, colors.white)
  384.     draw_text(22, 11, " + ", colors.white, colors.black)
  385.  
  386.     draw_text(11, 13, " Save ", colors.white, colors.black)
  387.  
  388.     local event, side, xPos, yPos = os.pullEvent("monitor_touch")
  389.  
  390.     --disable auto
  391.     if yPos == 5 then
  392.       if xPos >= 15 and xPos <= 21 then
  393.         auto_string = "false"
  394.         save_config()
  395.         auto_off()
  396.       else
  397.         auto_off()
  398.       end
  399.     end
  400.  
  401.     --increase/decrease auto on %
  402.     if yPos == 8 then
  403.       if xPos >= 5 and xPos <= 8 then
  404.         previous_on = on
  405.         on = on-1
  406.       end
  407.       if xPos >= 22 and xPos <= 25 then
  408.         previous_on = on
  409.         on = on+1
  410.       end
  411.     end
  412.  
  413.     --increase/decrease auto off %
  414.     if yPos == 11 then
  415.       if xPos >= 5 and xPos <= 8 then
  416.         previous_off = off
  417.         off = off-1
  418.       end
  419.       if xPos >= 22 and xPos <= 25 then
  420.         previous_off = off
  421.         off = off+1
  422.       end
  423.     end
  424.  
  425.     if on < 0 then on = 0 end
  426.     if off >99 then off = 99 end
  427.  
  428.     if on == off or on > off then
  429.       on = previous_on
  430.       off = previous_off
  431.       popup_screen(5, "Error", 6)
  432.       draw_text(5, 7, "Auto On value must be", colors.black, colors.white)
  433.       draw_text(5, 8, "lower then auto off", colors.black, colors.white)
  434.       draw_text(11, 10, "Okay", colors.white, colors.black)
  435.       local event, side, xPos, yPos = os.pullEvent("monitor_touch")
  436.  
  437.       auto_off()
  438.     end
  439.  
  440.     --Okay button
  441.     if yPos == 13 and xPos >= 11 and xPos <= 17 then
  442.       save_config()
  443.       call_homepage()
  444.     end
  445.  
  446.     --Exit button
  447.     if yPos == 3 and xPos == 25 then
  448.       call_homepage()
  449.     end
  450.  
  451.     auto_off()
  452.   else
  453.     popup_screen(3, "Auto Power", 5)
  454.     draw_text(5, 5, "Disabled", colors.red, colors.white)
  455.     draw_text(15, 5, " enable ", colors.white, colors.gray)
  456.     draw_text(11, 7, "Okay", colors.white, colors.black)
  457.  
  458.     local event, side, xPos, yPos = os.pullEvent("monitor_touch")
  459.  
  460.     --Okay button
  461.     if yPos == 7 and xPos >= 11 and xPos <= 17 then
  462.       call_homepage()
  463.     end
  464.  
  465.     if yPos == 5 then
  466.       if xPos >= 15 and xPos <= 21 then
  467.         auto_string = "true"
  468.         save_config()
  469.         auto_off()
  470.       else
  471.         auto_off()
  472.       end
  473.     else
  474.       auto_off()
  475.     end
  476.   end
  477. end
  478.  
  479. --efficiency menu
  480. function efficiency()
  481.   popup_screen(3, "Efficiency", 12)
  482.   fuel_usage = reactor.getFuelConsumedLastTick()
  483.   rft = math.floor(reactor.getEnergyProducedLastTick())
  484.  
  485.   rfmb = rft / fuel_usage
  486.     draw_text(13, 15, "efficiency menu", colors.white, colors.black)
  487.   draw_text(5, 5, "Fuel Consumption: ", colors.lime, colors.white)
  488.   draw_text(5, 6, fuel_usage.." mB/t", colors.black, colors.white)
  489.   draw_text(5, 8, "Energy per mB: ", colors.lime, colors.white)
  490.   draw_text(5, 9, rfmb.." RF/mB", colors.black, colors.white)
  491.  
  492.   draw_text(5, 11, "RF/tick:", colors.lime, colors.white)
  493.   draw_text(5, 12, rft.." RF/T", colors.black, colors.white)
  494.  
  495.   draw_text(11, 14, " Okay ", colors.white, colors.black)
  496.  
  497.   local event, side, xPos, yPos = os.pullEvent("monitor_touch")
  498.  
  499.   --Okay button
  500.   if yPos == 14 and xPos >= 11 and xPos <= 17 then
  501.     call_homepage()
  502.   end
  503.  
  504.   --Exit button
  505.   if yPos == 3 and xPos == 25 then
  506.     call_homepage()
  507.   end
  508.  
  509.   efficiency()
  510. end
  511.  
  512.  
  513. function fuel()
  514.   popup_screen(3, "Fuel", 9)
  515.  
  516.   fuel_max = reactor.getFuelAmountMax()
  517.   fuel_level = reactor.getFuelAmount()
  518.   fuel_reactivity = math.floor(reactor.getFuelReactivity())
  519.  
  520.   draw_text(5, 5, "Fuel Level: ", colors.lime, colors.white)
  521.   draw_text(5, 6, fuel_level.."/"..fuel_max, colors.black, colors.white)
  522.  
  523.   draw_text(5, 8, "Reactivity: ", colors.lime, colors.white)
  524.   draw_text(5, 9, fuel_reactivity.."%", colors.black, colors.white)
  525.  
  526.   draw_text(11, 11, " Okay ", colors.white, colors.black)
  527.  
  528.   local event, side, xPos, yPos = os.pullEvent("monitor_touch")
  529.  
  530.  
  531.   --Okay button
  532.   if yPos == 11 and xPos >= 11 and xPos <= 17 then
  533.     call_homepage()
  534.   end
  535.  
  536.   --Exit button
  537.   if yPos == 3 and xPos == 25 then
  538.     call_homepage()
  539.   end
  540.  
  541.   fuel()
  542. end
  543.  
  544. function waste()
  545.   popup_screen(3, "Waste", 8)
  546.  draw_text(13, 15, "waste menu", colors.white, colors.black)
  547.   waste_amount = reactor.getWasteAmount()
  548.   draw_text(5, 5, "Waste Amount: ", colors.lime, colors.white)
  549.   draw_text(5, 6, waste_amount.." mB", colors.black, colors.white)
  550.   draw_text(8, 8, " Eject Waste ", colors.white, colors.red)
  551.   draw_text(11, 10, " Close ", colors.white, colors.black)
  552.  
  553.   local event, side, xPos, yPos = os.pullEvent("monitor_touch")
  554.  
  555.   --eject button
  556.   if yPos == 8 and xPos >= 8 and xPos <= 21 then
  557.     reactor.doEjectWaste()
  558.     popup_screen(5, "Waste Eject", 5)
  559.     draw_text(5, 7, "Waste Ejeceted.", colors.black, colors.white)
  560.     draw_text(11, 9, " Close ", colors.white, colors.black)
  561.     local event, side, xPos, yPos = os.pullEvent("monitor_touch")
  562.     --Okay button
  563.     if yPos == 7 and xPos >= 11 and xPos <= 17 then
  564.       call_homepage()
  565.     end
  566.  
  567.     --Exit button
  568.     if yPos == 3 and xPos == 25 then
  569.       call_homepage()
  570.     end
  571.   end
  572.  
  573.   --Okay button
  574.   if yPos == 10 and xPos >= 11 and xPos <= 17 then
  575.     call_homepage()
  576.   end
  577.  
  578.   --Exit button
  579.   if yPos == 3 and xPos == 25 then
  580.     call_homepage()
  581.   end
  582.   waste()
  583. end
  584.  
  585. function set_auto_rf()
  586.   popup_screen(5, "Auto Adjust", 11)
  587.     draw_text(13, 15, "auto adjust", colors.white, colors.black)
  588.     draw_text(5, 7, "Try to maintain:", colors.black, colors.white)
  589.  
  590.     draw_text(13, 9, " ^ ", colors.white, colors.gray)
  591.     draw_text(10, 11, auto_rf.." RF/t", colors.black, colors.white)
  592.     draw_text(13, 13, " v ", colors.white, colors.gray)
  593.     draw_text(11, 15, " Okay ", colors.white, colors.gray)
  594.  
  595.     local event, side, xPos, yPos = os.pullEvent("monitor_touch")
  596.  
  597.     --increase button
  598.     if yPos == 9 then
  599.       auto_rf = auto_rf + 100
  600.       save_config()
  601.       set_auto_rf()
  602.     end
  603.  
  604.     --decrease button
  605.     if yPos == 13 then
  606.       auto_rf = auto_rf - 100
  607.       if auto_rf < 0 then auto_rf = 0 end
  608.       save_config()
  609.       set_auto_rf()
  610.     end
  611.  
  612.     if yPos == 15 then
  613.       control_rods()
  614.     end
  615.  
  616.     set_auto_rf()
  617. end
  618.  
  619. function control_rods()
  620.  
  621.   --if reactor.isActivelyCooled() then
  622.  
  623.     --popup_screen(3, "Control Rods", 13)
  624.     --insertion_percent = reactor.getControlRodLevel(0)
  625.  
  626.     --draw_text(5, 5, "Inserted: "..insertion_percent.."%", colors.black, colors.white)
  627.     --progress_bar(5, 7, 20, insertion_percent, 100, colors.yellow, colors.gray)
  628.  
  629.     --draw_text(5, 9, " << ", colors.white, colors.black)
  630.     --draw_text(10, 9, " < ", colors.white, colors.black)
  631.     --draw_text(17, 9, " > ", colors.white, colors.black)
  632.     --draw_text(21, 9, " >> ", colors.white, colors.black)
  633.  
  634.     --draw_text(5, 11, "Auto:", colors.black, colors.white)
  635.     --draw_text(5, 13, "unavilable for", colors.red, colors.white)
  636.     --draw_text(5, 14, "active cooling", colors.red, colors.white)
  637.  
  638.     --draw_text(11, 16, " Close ", colors.white, colors.gray)
  639.  
  640.     --local event, side, xPos, yPos = os.pullEvent("monitor_touch")
  641.  
  642.     --if yPos == 9 and xPos >= 5 and xPos <= 15 then
  643.     --  reactor.setAllControlRodLevels(insertion_percent-10)
  644.     --end
  645.  
  646.     --if yPos == 9 and xPos >= 10 and xPos <= 13 then
  647.     --  reactor.setAllControlRodLevels(insertion_percent-1)
  648.     --end
  649.  
  650.     --if yPos == 9 and xPos >= 17 and xPos <= 20 then
  651.     --  reactor.setAllControlRodLevels(insertion_percent+1)
  652.     --end
  653.  
  654.     --if yPos == 9 and xPos >= 21 and xPos <= 25 then
  655.     --  reactor.setAllControlRodLevels(insertion_percent+10)
  656.     --end
  657.  
  658.     ------Close button-------
  659.     --if yPos == 16 and xPos >= 11 and xPos <= 17 then
  660.       call_homepage()
  661.     --end
  662.  
  663.     ------Exit button------------
  664.     --if yPos == 5 and xPos == 25 then
  665.     --call_homepage()
  666.     --end
  667.     --control_rods()
  668.  
  669.   --else
  670.  
  671.     popup_screen(3, "Control Rods", 13)
  672.     insertion_percent = reactor.getControlRodLevel(0)
  673.  
  674.     draw_text(5, 5, "Inserted: "..insertion_percent.."%", colors.black, colors.white)
  675.     progress_bar(5, 7, 20, insertion_percent, 100, colors.yellow, colors.gray)
  676.  
  677.     draw_text(5, 9, " << ", colors.white, colors.black)
  678.     draw_text(10, 9, " < ", colors.white, colors.black)
  679.     draw_text(17, 9, " > ", colors.white, colors.black)
  680.     draw_text(21, 9, " >> ", colors.white, colors.black)
  681.  
  682.     draw_text(5, 11, "Auto:", colors.black, colors.white)
  683.     draw_text(16, 11, " disable ", colors.white, colors.black)
  684.  
  685.     auto_rods_bool = auto_rods == "true"
  686.     if auto_rods_bool then
  687.      
  688.       draw_text(5, 13, "RF/t: "..auto_rf, colors.black, colors.white)
  689.       draw_text(18, 13, " set ", colors.white, colors.black)
  690.     else
  691.       draw_text(16, 11, " enable ", colors.white, colors.black)
  692.       draw_text(5, 13, "disabled", colors.red, colors.white)
  693.     end
  694.  
  695.     draw_text(11, 15, " Close ", colors.white, colors.gray)
  696.  
  697.     local event, side, xPos, yPos = os.pullEvent("monitor_touch")
  698.  
  699.     -----manual adjust buttons------------
  700.     if yPos == 9 and xPos >= 5 and xPos <= 15 then
  701.       reactor.setAllControlRodLevels(insertion_percent-10)
  702.     end
  703.  
  704.     if yPos == 9 and xPos >= 10 and xPos <= 13 then
  705.       reactor.setAllControlRodLevels(insertion_percent-1)
  706.     end
  707.  
  708.     if yPos == 9 and xPos >= 17 and xPos <= 20 then
  709.       reactor.setAllControlRodLevels(insertion_percent+1)
  710.     end
  711.  
  712.     if yPos == 9 and xPos >= 21 and xPos <= 25 then
  713.       reactor.setAllControlRodLevels(insertion_percent+10)
  714.     end
  715.  
  716.  
  717.     ------auto buttons-----------------
  718.     if yPos == 11 and xPos >= 16 then
  719.       if auto_rods_bool then
  720.         auto_rods = "false"
  721.         save_config()
  722.         control_rods()
  723.       else
  724.         auto_rods = "true"
  725.         save_config()
  726.         control_rods()
  727.       end
  728.     end
  729.  
  730.     if yPos == 13 and xPos >= 18 then
  731.       set_auto_rf()
  732.     end
  733.  
  734.     ------Close button-------
  735.     if yPos == 15 and xPos >= 11 and xPos <= 17 then
  736.       call_homepage()
  737.     end
  738.  
  739.     ------Exit button------------
  740.     if yPos == 5 and xPos == 25 then
  741.       call_homepage()
  742.     end
  743.     control_rods()
  744.  
  745.   end
  746. end
  747.  
  748. -----------------------Settings--------------------------------
  749.  
  750.  
  751. function rf_mode()
  752.   wait = read()
  753. end
  754.  
  755. function steam_mode()
  756.   wait = read()
  757. end
  758.  
  759. function install_update(program, pastebin)
  760.     clear()
  761.     draw_line(4, 5, 22, colors.blue)
  762.  
  763.     for counter = 6, 10 do
  764.       draw_line(4, counter, 22, colors.white)
  765.     end
  766.  
  767.     draw_text(5, 5, "Updating...", colors.white, colors.blue)
  768.     draw_text(5, 7, "Open computer", colors.black, colors.white)
  769.     draw_text(5, 8, "terminal.", colors.black, colors.white)
  770.  
  771.     if fs.exists("install") then fs.delete("install") end
  772.     shell.run("pastebin get p4zeq7Ma install")
  773.     shell.run("install")
  774. end
  775.  
  776. function update()
  777.   popup_screen(5, "Updates", 4)
  778.   draw_text(5, 7, "Connecting to", colors.black, colors.white)
  779.   draw_text(5, 8, "pastebin...", colors.black, colors.white)
  780.  
  781.   sleep(0.5)
  782.  
  783.   shell.run("pastebin get MkF2QQjH current_version.txt")
  784.   sr = fs.open("current_version.txt", "r")
  785.   current_version = tonumber(sr.readLine())
  786.   sr.close()
  787.   fs.delete("current_version.txt")
  788.   terminal_screen()
  789.  
  790.   if current_version > version then
  791.  
  792.     popup_screen(5, "Updates", 7)
  793.     draw_text(5, 7, "Update Available!", colors.black, colors.white)
  794.     draw_text(11, 9, " Install ", colors.white, colors.black)
  795.     draw_text(11, 11, " Ignore ", colors.white, colors.black)
  796.  
  797.     local event, side, xPos, yPos = os.pullEvent("monitor_touch")
  798.  
  799.     --Instatll button
  800.     if yPos == 9 and xPos >= 11 and xPos <= 17 then
  801.       install_update()
  802.     end
  803.  
  804.     --Exit button
  805.     if yPos == 5 and xPos == 25 then
  806.       call_homepage()
  807.     end
  808.     call_homepage()
  809.  
  810.   else
  811.     popup_screen(5, "Updates", 5)
  812.     draw_text(5, 7, "You are up to date!", colors.black, colors.white)
  813.     draw_text(11, 9, " Okay ", colors.white, colors.black)
  814.  
  815.     local event, side, xPos, yPos = os.pullEvent("monitor_touch")
  816.  
  817.     --Okay button
  818.     if yPos == 9 and xPos >= 11 and xPos <= 17 then
  819.       call_homepage()
  820.     end
  821.  
  822.     --Exit button
  823.     if yPos == 5 and xPos == 25 then
  824.       call_homepage()
  825.     end
  826.     call_homepage()
  827.   end
  828.  
  829.  
  830.  
  831. end
  832.  
  833. function reset_peripherals()
  834.   clear()
  835.   draw_line(4, 5, 22, colors.blue)
  836.  
  837.   for counter = 6, 10 do
  838.     draw_line(4, counter, 22, colors.white)
  839.   end
  840.  
  841.   draw_text(5, 5, "Reset Peripherals", colors.white, colors.blue)
  842.   draw_text(5, 7, "Open computer", colors.black, colors.white)
  843.   draw_text(5, 8, "terminal.", colors.black, colors.white)
  844.   setup_wizard()
  845.  
  846. end
  847.  
  848. --stop running status screen if monitors was touched
  849. function stop()
  850.   while true do
  851.     local event, side, xPos, yPos = os.pullEvent("monitor_touch")
  852.       x = xPos
  853.       y = yPos
  854.       stop_function = "monitor_touch"
  855.     return
  856.   end
  857. end
  858.  
  859. function mon_touch()
  860.   --when the monitor is touch on the homepage
  861.   if y == 1 then
  862.       if x < monX/3 then
  863.         power_menu()
  864.         local event, side, xPos, yPos = os.pullEvent("monitor_touch")
  865.         if xPos < 9 then
  866.           if yPos == 2 then
  867.             reactor.setActive(true)
  868.             timer = 0 --reset anytime the reactor is turned on/off
  869.             call_homepage()
  870.           elseif yPos == 3 then
  871.             reactor.setActive(false)
  872.             timer = 0 --reset anytime the reactor is turned on/off
  873.             call_homepage()
  874.           elseif yPos == 4 then
  875.             auto_off()
  876.           else
  877.             call_homepage()
  878.           end
  879.           end
  880.           end
  881.         else
  882.           call_homepage()
  883.         end
  884.        
  885.       elseif x < 20 then
  886.         tools_menu()
  887.         local event, side, xPos, yPos = os.pullEvent("monitor_touch")
  888.         if xPos < 25 and xPos > 10 then
  889.           if yPos == 2 then
  890.             control_rods()
  891.           elseif yPos == 3 then
  892.             efficiency()
  893.           elseif yPos == 4 then
  894.             fuel()
  895.           elseif yPos == 5 then
  896.             waste()
  897.           else
  898.             call_homepage()
  899.           end
  900.           end
  901.           end
  902.           end
  903.         else
  904.           call_homepage()
  905.         end
  906.       elseif x < monX then
  907.         settings_menu()
  908.         local event, side, xPos, yPos = os.pullEvent("monitor_touch")
  909.         if xPos > 13 then
  910.           if yPos == 2 then
  911.             update()
  912.           elseif yPos == 3 then
  913.             reset_peripherals()
  914.           else
  915.             call_homepage()
  916.           end
  917.           end
  918.         else
  919.           call_homepage()
  920.         end
  921.       end
  922.       end
  923.       end
  924.     else
  925.       call_homepage()
  926.     end
  927. end
  928.  
  929. function terminal_screen()
  930.   term.clear()
  931.   draw_line_term(1, 1, 55, colors.blue)
  932.   draw_text_term(13, 1, "BDE Reactor Control Program", colors.white, colors.blue)
  933.   draw_line_term(1, 19, 55, colors.blue)
  934.   draw_text_term(13, 19, "Compliments of your mom", colors.white, colors.blue)
  935. end
  936.  
  937. --run both homepage() and stop() until one returns
  938. function call_homepage()
  939.   clear()
  940.   parallel.waitForAny(homepage, stop)
  941.  
  942.   if stop_function == "terminal_screen" then
  943.     stop_function = "nothing"
  944.     setup_wizard()
  945.   elseif stop_function == "monitor_touch" then
  946.     stop_function = "nothing"
  947.     mon_touch()
  948.   end
  949.   end
  950.  
  951. end
  952.  
  953. --test if the entered monitor and reactor can be wrapped
  954.   function test_configs()
  955.   term.clear()
  956.  
  957.   draw_line_term(1, 1, 55, colors.blue)
  958.   draw_text_term(10, 1, "BigReactors Controls", colors.white, colors.blue)
  959.  
  960.   draw_line_term(1, 19, 55, colors.blue)
  961.   draw_text_term(10, 19, "by jaranvil aka jared314", colors.white, colors.blue)
  962.  
  963.   draw_text_term(1, 3, "Searching for a peripherals...", colors.white, colors.black)
  964.   sleep(1)
  965.  
  966.   reactor = reactorSearch()
  967.   mon = monitorSearch()
  968.  
  969.  
  970.   draw_text_term(2, 5, "Connecting to reactor...", colors.white, colors.black)
  971.   sleep(0.5)
  972.   if reactor == null then
  973.       draw_text_term(1, 8, "Error:", colors.red, colors.black)
  974.       draw_text_term(1, 9, "Could not connect to reactor", colors.red, colors.black)
  975.       draw_text_term(1, 10, "Reactor must be connected with networking cable", colors.white, colors.black)
  976.       draw_text_term(1, 11, "and modems or the computer is directly beside", colors.white, colors.black)
  977.        draw_text_term(1, 12,"the reactors computer port.", colors.white, colors.black)
  978.       draw_text_term(1, 14, "Press Enter to continue...", colors.gray, colors.black)
  979.       wait = read()
  980.       setup_wizard()
  981.   else
  982.       draw_text_term(27, 5, "success", colors.lime, colors.black)
  983.       sleep(0.5)
  984.   end
  985.  
  986.   draw_text_term(2, 6, "Connecting to monitor...", colors.white, colors.black)
  987.   sleep(0.5)
  988.   if mon == null then
  989.       draw_text_term(1, 7, "Error:", colors.red, colors.black)
  990.       draw_text_term(1, 8, "Could not connect to a monitor. Place a 3x3 advanced monitor", colors.red, colors.black)
  991.       draw_text_term(1, 11, "Press Enter to continue...", colors.gray, colors.black)
  992.       wait = read()
  993.       setup_wizard()
  994.   else
  995.       monX, monY = mon.getSize()
  996.       draw_text_term(27, 6, "success", colors.lime, colors.black)
  997.       sleep(0.5)
  998.   end
  999.     draw_text_term(2, 7, "saving configuration...", colors.white, colors.black)  
  1000.  
  1001.     save_config()
  1002.  
  1003.     sleep(0.1)
  1004.     draw_text_term(1, 9, "Setup Complete!", colors.lime, colors.black)
  1005.     sleep(1)
  1006.  
  1007.     auto = auto_string == "true"
  1008.     call_homepage()
  1009.  
  1010. end
  1011. ----------------SETUP-------------------------------
  1012.  
  1013. function setup_wizard()
  1014.  
  1015.   term.clear()
  1016.  
  1017.  
  1018.      draw_text_term(1, 1, "BigReactor Controls v"..version, colors.lime, colors.black)
  1019.      draw_text_term(1, 2, "Peripheral setup", colors.white, colors.black)
  1020.      draw_text_term(1, 4, "Step 1:", colors.lime, colors.black)
  1021.      draw_text_term(1, 5, "-Place 3x3 advanced monitors next to computer.", colors.white, colors.black)
  1022.      draw_text_term(1, 7, "Step 2:", colors.lime, colors.black)
  1023.      draw_text_term(1, 8, "-Place a wired modem on this computer and on the ", colors.white, colors.black)
  1024.      draw_text_term(1, 9, " computer port of the reactor.", colors.white, colors.black)
  1025.      draw_text_term(1, 10, "-connect modems with network cable.", colors.white, colors.black)
  1026.      draw_text_term(1, 11, "-right click modems to activate.", colors.white, colors.black)
  1027.      draw_text_term(1, 13, "Press Enter when ready...", colors.gray, colors.black)
  1028.    
  1029.      wait = read()
  1030.       test_configs()
  1031.  
  1032.    
  1033. end
  1034.  
  1035. -- peripheral searching thanks to /u/kla_sch
  1036. -- http://pastebin.com/gTEBHv3D
  1037. function reactorSearch()
  1038.    local names = peripheral.getNames()
  1039.    local i, name
  1040.    for i, name in pairs(names) do
  1041.       if peripheral.getType(name) == "BigReactors-Reactor" then
  1042.          return peripheral.wrap(name)
  1043.       else
  1044.          --return null
  1045.       end
  1046.    end
  1047. end
  1048.  
  1049. function monitorSearch()
  1050.    local names = peripheral.getNames()
  1051.    local i, name
  1052.    for i, name in pairs(names) do
  1053.       if peripheral.getType(name) == "monitor" then
  1054.         test = name
  1055.          return peripheral.wrap(name)
  1056.       else
  1057.          --return null
  1058.       end
  1059.    end
  1060. end
  1061.  
  1062. function start()
  1063.   --if configs exists, load values and test
  1064.   if fs.exists("config.txt") then
  1065.       load_config()
  1066.       test_configs()
  1067.   else
  1068.     setup_wizard()
  1069.   end
  1070. end
  1071.  
  1072. start()
Add Comment
Please, Sign In to add comment