Advertisement
osmarks

OC Fusion Control

Aug 2nd, 2020 (edited)
1,942
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local component, computer = component, computer
  2. if require then component = require "component" computer = require "computer" end
  3. local wlan = component.proxy(component.list "modem"())
  4. local computer_peripheral = component.proxy(component.list "computer"())
  5. local reactor = component.proxy(component.list "nc_fusion_reactor"())
  6. local gpu = component.proxy(component.list "gpu"())
  7. local screen = component.list "screen"()
  8. gpu.bind(screen)
  9. wlan.setWakeMessage("poweron", true)
  10.  
  11. local function display(txt)
  12.     local w, h = gpu.getResolution()
  13.     gpu.set(1, 1, txt .. (" "):rep(w - #txt))
  14. end
  15.  
  16. local function sleep(timeout)
  17.     local deadline = computer.uptime() + (timeout or 0)
  18.     repeat
  19.         computer.pullSignal(deadline - computer.uptime())
  20.     until computer.uptime() >= deadline
  21. end
  22.  
  23. computer_peripheral.beep(400)
  24. display "Initialized"
  25.  
  26. local NC_HEAT_CONSTANT = 1218.76
  27.  
  28. local last = nil
  29.  
  30. while true do
  31.     local target_temp = reactor.getFusionComboHeatVariable() * NC_HEAT_CONSTANT * 1000
  32.     local temp = reactor.getTemperature()
  33.     display(("%f %f"):format(temp / target_temp, reactor.getEfficiency()))
  34.     local too_high = temp > target_temp
  35.     if too_high then
  36.         if too_high ~= last then computer_peripheral.beep(800) end
  37.         reactor.deactivate()
  38.     else
  39.         if too_high ~= last then computer_peripheral.beep(500) end
  40.         reactor.activate()
  41.     end
  42.     last = too_high
  43.     wlan.broadcast(1111, "poweron")
  44.     sleep(0.5)
  45. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement