Advertisement
loepie

BigReactor with wireless (Monitor)

Feb 8th, 2014
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.78 KB | None | 0 0
  1. --Loepie78s Big Reactor Manager v0.1 based on :
  2. --FusionNrg's Big Reactor Manager v1.1
  3. --With wireless
  4. --last revised 2-6-2014
  5. -- designed for reactor to rear of computer with at least a 2x3 monitor on the top of the computer
  6.  
  7. function wrapreactor()
  8. --wrap reactor peripheral
  9.     reactor = peripheral.wrap("back")
  10.     reactor.setActive(true)
  11. end
  12.  
  13. function wrapmonitor()
  14. --applicable monitor variables
  15.     monitor = peripheral.wrap("right")
  16.     monitor.write("System Initialized")
  17.     width, height = monitor.getSize()
  18. end
  19.  
  20. function wrapmodem()
  21. --applicable modem variables
  22.     modem = peripheral.wrap("top")
  23. --  modem.transmit(401, 1, "Big Reactor Manager initializing")
  24. end
  25.  
  26. function configvars()
  27.     pullInfo()
  28.     rods = 99
  29.     target = 5000000 -- adjustable between 0 and 10 million depending how much you want on hand
  30.     full = 10000000 -- full buffer size
  31. end
  32.  
  33. function pullInfo()-- pulling the latest from the reactor
  34.     ReactorTemp = reactor.getTemperature()
  35.     ReactorES = reactor.getEnergyStored()
  36.     ReactorLT = reactor.getEnergyProducedLastTick()
  37.     ReactorCRL = reactor.getControlRodLevel()
  38. end
  39.  
  40. function sendmodeminfo()
  41.     modem.transmit(401, 2, temp)
  42.     modem.transmit(402, 3, energy)
  43.     modem.transmit(403, 4, lastTick)
  44. end
  45.  
  46. function getmodeminfo()
  47.     modem.open(400)--Open channel 400 so that we can listen on it : Reactor Temperature
  48.     local event400, modemSide400, senderChannel400, replyChannel400, Message400, senderDistance400 = os.pullEvent("modem_message")
  49.     modem.open(401)--Open channel 401 so that we can listen on it : Reactor Stored Energy
  50.     local event401, modemSide401, senderChannel401, replyChannel401, Message401, senderDistance401 = os.pullEvent("modem_message")
  51.     modem.open(402)--Open channel 402 so that we can listen on it : Reactor Produced Energy
  52.     local event402, modemSide402, senderChannel402, replyChannel402, Message402, senderDistance402 = os.pullEvent("modem_message")
  53.     modem.open(403)--Open channel 403 so that we can listen on it : : Reactor Control Rod Level
  54.     local event403, modemSide403, senderChannel403, replyChannel403, Message403, senderDistance403 = os.pullEvent("modem_message")
  55.  
  56.     modem.close(400)
  57.     modem.close(401)
  58.     modem.close(402)
  59.     modem.close(403)
  60. end
  61.  
  62. function displayStats() -- display stats to the monitor in 2 columns
  63. --wrap monitor and pull sizing
  64.     monitor.clear()
  65.     monitor.setCursorPos(1, 1)
  66.     monitor.write("Temp")
  67.     monitor.setCursorPos(width / 2, 1)
  68.     monitor.write("Buffer")
  69.     monitor.setCursorPos(1, 2)
  70.     monitor.write(ReactorTemp)
  71.     monitor.write(" Cel. ")
  72.     monitor.setCursorPos(width / 2, 2)
  73.     monitor.write(math.floor(((ReactorES/full) * 100) + 0.5))
  74.     monitor.write(" %")
  75.     monitor.setCursorPos(1, 4)
  76.     monitor.write("Energy Last Tick: ")
  77.     monitor.setCursorPos(1, 5)
  78.     monitor.write(math.floor(ReactorLT+ 0.5))
  79.     monitor.write("RF/t")
  80.     monitor.setCursorPos(1, 7)
  81.     monitor.write("Rod Insertion")
  82.     monitor.setCursorPos(1, 8)
  83.     monitor.write(ReactorCRL)
  84.     monitor.write(" %")
  85. end
  86.  
  87. function decrods()
  88.     rods=rods-1
  89.     if (rods < 0) then
  90.         rods=0
  91.         end
  92.     reactor.setAllControlRodLevels(rods)
  93. end
  94.  
  95. function incrods()
  96.     rods=rods+1
  97.     if (rods > 100) then
  98.         rods=100
  99.         end
  100.     reactor.setAllControlRodLevels(rods)
  101. end
  102.  
  103. function rodManagement()
  104. --if we're losing energy and below half or empty... pull rods out by 1%
  105.     if (reactor.getEnergyStored() < energy) and (energy < target) then
  106.         decrods()
  107.         end
  108. -- if energy is increasing and storage is over half  insert rods by 1%
  109.     if (reactor.getEnergyStored() > energy) and (energy > target) then
  110.         incrods()
  111.         end
  112.     if (reactor.getEnergyStored() == 0) then
  113.         decrods()
  114.         end
  115. end
  116.  
  117. function main()
  118.     while (true) do
  119. --      pullInfo()
  120. --      sendmodeminfo()
  121.         getmodeminfo()
  122.         sleep(1)
  123.         displayStats()
  124. --      rodManagement()
  125.         sleep(1)
  126.     end
  127. end
  128.  
  129. --wrapreactor()
  130. wrapmonitor()
  131. wrapmodem()
  132. --configvars()
  133. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement