Advertisement
Guest User

canister_controller

a guest
Apr 30th, 2018
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.84 KB | None | 0 0
  1. local lb,ub=0,4095
  2. local delay=1
  3. if lb<0 then lb=0 end
  4. if ub>4095 then ub=4095 end
  5.  
  6. local cmp=component or require"component"
  7. local comp=computer or require"computer"
  8. local interrupt
  9. local ut=comp.uptime
  10. local sleep=function(secs) dl=ut()+secs;while ut()<dl do local s=comp.pullSignal(dl-ut()); if s=="interrupted" then interrupt(); dl=0 end end end
  11. local et=cmp.proxy(cmp.list("ender_tank")())
  12. local ga=function() return et.getTankInfo()[1].contents.amount end
  13. local gc=function() return et.getTankInfo()[1].capacity end
  14. local gf=function() return et.getFrequency() end
  15. local sf=function(nf) et.setFrequency(nf) end
  16. local chf=function(d) local cf=gf();local nf=cf+d;if nf>=lb and nf<=ub then sf(nf) end end
  17.  
  18. running=true
  19. interrupt=function() running=false end
  20.  
  21. while running do
  22.   if ga()<=0 then chf(-1)
  23.   elseif ga()>=gc() then chf(1)
  24.   end
  25.   sleep(delay)
  26. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement