Advertisement
ccraftersanonmoose

Power Station ComputerCraft

Mar 7th, 2023 (edited)
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.27 KB | Gaming | 0 0
  1. -- Power Station Controller and Monitor
  2. -- Test script by ccraftersanonmoose
  3. ----------------------------------------
  4. -- Version History
  5. -- Version 0.1 - 2/5/23
  6. -- added buttons to activate and scram reactor
  7. -- Version 0.2 2/13/23
  8. -- added monitoring of actual burn rate and temp
  9. -- adjusted temp to show absolute number in celsius
  10. -- would like to add buttons to increment and decrement the burn rate
  11. -- version 0.2.2 2/16/23
  12. -- added status monitoring
  13. -- added set burn rate monitoring
  14. -- added buttons for burn rate
  15. -- version 0.3 3/7/2023
  16. -- adding monitoring of SPS and battery bank
  17. -- would like button to turn SPS on and off
  18.  
  19. ----------------------------------------
  20.  
  21. os.loadAPI("button")
  22. mon = peripheral.find("monitor")
  23. reactor = peripheral.find("fissionReactorLogicAdapter")
  24. sps = peripheral.find("spsPort")
  25. mon.clear()
  26.  
  27. function fillTable()
  28.     -- Reactor Section
  29.     button.setTable("Acivate", activateReactor, 1,11,5,7)
  30.     button.setTable("SCRAM", scramReactor, 1,11,9,11)
  31.     button.setTable("+", incrementBurnRate, 5,6,13,14)
  32.     button.setTable("-", decrementBurnRate, 8,9,13,14)
  33.     -- SPS Section
  34.     button.setTable("On", spsOn, 13,15,5,7)
  35.     button.setTable("Off", spsOff, 17,19,5,7)
  36.     button.screen()
  37. end
  38.  
  39. function getClick()
  40.     event,side,x,y = os.pullEvent("monitor_touch")
  41.     button.checkxy(x,y)
  42. end
  43.  
  44. function activateReactor()
  45.     button.flash("Activate")
  46.     reactor.activate()
  47. end
  48.  
  49. function scramReactor()
  50.     button.flash("SCRAM")
  51.     reactor.scram()
  52. end
  53.  
  54. function incrementBurnRate()
  55.     button.flash("+")
  56.     reactor.setBurnRate(reactor.getBurnRate() + 1)
  57. end
  58.  
  59. function decrementBurnRate()
  60.     button.flash("+")
  61.     reactor.setBurnRate(reactor.getBurnRate() - 1)
  62. end
  63. --function getInfo()
  64.   --reactor.getActualBurnRate()
  65.   --reactor.getCoolantFilledPercentage()
  66.   --reactor.getFuelFilledPercentage()
  67.   --reactor.getTemperature()
  68.   --reactor.getStatus()
  69. --end
  70.  
  71. function spsOn()
  72.     button.flash("+")
  73.     sps.setMode(true)
  74. end
  75.  
  76. function spsOff()
  77.     button.flash("+")
  78.     sps.setMode(false)
  79. end
  80.  
  81. function displayInfo()
  82.   mon.setTextScale(1)
  83.   -- Reactor Section
  84.   mon.setCursorPos(1,2)
  85.   mon.write("Reactor")
  86.   if reactor.getStatus() == true then
  87.     mon.setCursorPos(1,3)
  88.     mon.write("Status:")
  89.     mon.setCursorPos(1,4)
  90.    -- mon.clearLine()
  91.     mon.write("Active  ")
  92.   else
  93.     mon.setCursorPos(1,3)
  94.     mon.write("Status:")
  95.     mon.setCursorPos(1,4)
  96.   --  mon.clearLine()
  97.     mon.write("Disabled")
  98.   end  
  99.   mon.setCursorPos(1,12)
  100.   mon.write("Burn Rate")
  101.   mon.setCursorPos(1,13)
  102.   mon.write(reactor.getBurnRate())    
  103.  -- mon.setCursorPos(1,8)
  104.  -- mon.write("Current Burn Rate: ")
  105.  -- mon.setCursorPos(1,10)
  106.  -- mon.write(reactor.getActualBurnRate())
  107.   mon.setCursorPos(1,16)
  108.   mon.write("Current Temp:")
  109.   mon.setCursorPos(1,17)
  110.   mon.write(math.floor(reactor.getTemperature() - 273.15).."C ")
  111.   -- SPS Section
  112.   mon.setCursorPos(13,2)
  113.   mon.write("SPS")
  114.   mon.setCursorPos(13,3)
  115.   mon.write("Status:")
  116.   if sps.getMode() == true then
  117.     mon.setCursorPos(13,4)
  118.     mon.write("Active  ")
  119.   else
  120.     mon.setCursorPos(13,4)
  121.   --  mon.clearLine()
  122.     mon.write("Disabled")
  123.   end
  124. end
  125.  
  126. fillTable()
  127. button.heading("Power Station")
  128.  
  129. while true do
  130.     displayInfo()
  131.     getClick()
  132. end
  133.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement