Advertisement
PlowmanPlow

BigReactor Monitor and Aux Control

Jan 16th, 2017
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.42 KB | None | 0 0
  1. local cellSideBigReactor = "right"
  2. local cellSideSolar = "tile_thermalexpansion_cell_resonant_name_0"
  3. local statusChannelID = 5
  4. local reactorActivateP = 5
  5. local reactorTriggerP = 5
  6.  
  7. -- Find Modem
  8. local modem = peripheral.find("modem", function(n, o) return o.isWireless() end)
  9.  
  10. -- Find Reactor
  11. local reactor = peripheral.find("BigReactors-Reactor")
  12. if reactor == nil then
  13.    error("Could not bind to reactor. Is one attached?")
  14. end
  15.  
  16. -- Bind the Solar charged Energy Cell
  17. local solarCell = peripheral.wrap(cellSideSolar)
  18. if solarCell == nil then
  19.    error("Could not bind to solar charged Energy Cell. Is one attached?")
  20. end
  21.  
  22. term.clear()
  23. term.setCursorPos(1,1)
  24. print("BigReactor Monitor...")
  25. print()
  26. print("Reactor Output: Disabled")
  27. print("Reactor Status: Inactive")
  28. print("Reactor Buffer: ")
  29. print("Reactor Fuel: ")
  30. print("Reactor Generation: ")
  31. print("Solar Buffer: ")
  32. print()
  33. print("Press 'q' to quit.")
  34. print()
  35.  
  36. rs.setOutput(cellSideBigReactor, false)
  37. local reactorEnabled = false
  38. reactor.setActive(false)
  39. local rActive = reactor.getActive()
  40. local pollTimer = os.startTimer(0)
  41. local status = {}
  42. while true do
  43.    local event, p1, p2, p3, p4 = os.pullEvent()
  44.    if event == "key" then
  45.       if p1 == 16 then -- 'q'
  46.          term.setCursorPos(1, 6)
  47.          return
  48.       end
  49.    elseif event == "timer" and p1 == pollTimer then
  50.       -- Check the Solar charged energy cell to determine if the
  51.       -- reactor output should be enabled.
  52.       local sEnergyP = (solarCell.getEnergyStored() / solarCell.getMaxEnergyStored()) * 100
  53.       if sEnergyP <= reactorTriggerP then reactorEnabled = true end
  54.       if sEnergyP >= 98 then reactorEnabled = false end
  55.       rs.setOutput(cellSideBigReactor, reactorEnabled)
  56.       local rEnergyP = (reactor.getEnergyStored() / 10000000) * 100
  57.       if rActive == false and rEnergyP <= reactorActivateP then
  58.          reactor.setActive(true)
  59.       end
  60.       if rActive == true and rEnergyP >= 98 then
  61.          reactor.setActive(false)
  62.       end
  63.       if reactorEnabled == true then
  64.          status["Reactor Output"] = "Enabled"
  65.       else
  66.          status["Reactor Output"] = "Disabled"
  67.       end
  68.       rActive = reactor.getActive()
  69.       if rActive == true then
  70.          status["Reactor Status"] = "Active"
  71.       else
  72.          status["Reactor Status"] = "Inactive"
  73.       end
  74.       term.setCursorPos(1,3)
  75.       term.write("Reactor Output: " .. status["Reactor Output"] .. "   ")
  76.       term.setCursorPos(1,4)
  77.       term.write("Reactor Status: " .. status["Reactor Status"] .. "   ")
  78.       status["Reactor Buffer"] = math.floor(rEnergyP) .. "%"
  79.       status["Solar Buffer"] = math.floor(sEnergyP) .. "%"
  80.       term.setCursorPos(1,5)
  81.       term.write("Reactor Buffer: " .. status["Reactor Buffer"] .. "   ")
  82.       status["Reactor Fuel"] = math.floor((reactor.getFuelAmount() / reactor.getFuelAmountMax()) * 100) .. "%"
  83.       term.setCursorPos(1,6)
  84.       term.write("Reactor Fuel: " .. status["Reactor Fuel"] .. "   ")
  85.       status["Reactor Generation"] = math.floor(reactor.getEnergyProducedLastTick()) .. " RF/t"
  86.       term.setCursorPos(1,7)
  87.       term.write("Reactor Generation: " .. status["Reactor Generation"] .. "          ")
  88.       term.setCursorPos(1,8)
  89.       term.write("Solar Buffer: " .. status["Solar Buffer"] .. "         ")
  90.       if modem ~= nil then modem.transmit(statusChannelID, 0, textutils.serialize(status)) end
  91.       pollTimer = os.startTimer(5)
  92.    end
  93. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement