Advertisement
Guest User

control.lua

a guest
Oct 11th, 2015
309
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.69 KB | None | 0 0
  1. local component=require("component")
  2. local serial=require("serialization")
  3. local reactor=component.br_reactor
  4. local modem=component.modem
  5. local event=require("event")
  6. modem.open(1)
  7. local send_addr=nil
  8. local this_addr=nil
  9. local testing=true
  10. while testing do
  11.   local _,addr,from,port,_,msg=event.pull("modem_message")
  12.   print(from..":"..msg)
  13.   if msg=="test" then
  14.     testing=false
  15.     send_addr=from
  16.     this_addr=addr
  17.   end
  18. end
  19. local function update()
  20.   modem.send(send_addr,1,serial.serialize({
  21.   ["energy"]=reactor.getEnergyStored()/100000,
  22.   ["rodLevel"]=reactor.getControlRodLevel(1),
  23.   ["auto"]=automatic}))
  24. end
  25. local ended=false
  26. modem.send(send_addr,1,"test")
  27. local automatic=false
  28. function listen()
  29.   local evt,_,from,port,_,msg=event.pull(5,"modem_message")
  30.   if not evt==nil then
  31.     print(from..":"..msg)
  32.     if msg=="on" then
  33.       reactor.setActive(true)
  34.       automatic=false
  35.     end
  36.     if msg=="off" then
  37.       reactor.setActive(false)
  38.       automatic=false
  39.     end
  40.     if msg=="end" then
  41.       reactor.setActive(false)
  42.       ended=true
  43.     end
  44.     if msg=="auto" then
  45.       automatic=true
  46.     end
  47.     if msg=="man" then
  48.       automatic=false
  49.     end
  50.     if string.sub(msg,1,2)=="up" then
  51.       automatic=false
  52.       reactor.setAllControlRodLevels(min(100,reactor.getControlRodLevel(1)+string.sub(msg,3,string.len(msg))))
  53.     end
  54.     if string.sub(msg,1,4)=="down" then
  55.       automatic=false
  56.       reactor.setAllControlRodLevels(max(0,reactor.getControlRodLevel(1)-string.sub(msg,5,string.len(msg))))
  57.     end
  58.   end
  59. end
  60. coroutine.create(listen)
  61. while not ended do
  62.   if automatic then
  63.     reactor.setAllControlRodLevels(reactor.getEnergyStored()/10000)
  64.   end
  65. --  update()
  66. --  coroutine.create(listen)
  67.   os.sleep(1)
  68. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement