osmarks

basenet energy cell monitor

May 8th, 2020
351
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local basenet;do local function b()local c,d=http.get"https://pastebin.com/raw/QnFKq9pE"if not c then return false,d end;local e=c.readAll()local f,d=load(e)if not f then return false,d end;return pcall(f)end;for g=0,8 do local h,i=b()if not h then printError(i)sleep(math.pow(2,g))else basenet=i;break end end end
  2.  
  3. local low_threshold = settings.get "basenet.low_threshold" or 0.75
  4. local cell = peripheral.wrap(settings.get "basenet.cell" or error "cell name required")
  5.  
  6. local delay = 0.2
  7. local delay_ticks = delay / 0.05
  8. local last
  9. basenet.interval(function()
  10.     local energy = cell.getEnergyStored()
  11.     local diff
  12.     if cell.getAverageChangePerTick then
  13.         diff = cell.getAverageChangePerTick()
  14.     else
  15.         if last then
  16.             diff = (energy - last) / delay_ticks
  17.         end
  18.         last = energy
  19.     end
  20.     local level = energy / (cell.getMaxEnergyStored or cell.getEnergyCapacity)()
  21.     print("IO", diff, "LEVEL", level, "ENERGY", energy)
  22.     basenet.update { level = level, io = diff, low = level < low_threshold }
  23. end, delay)
  24.  
  25. basenet.run()
Add Comment
Please, Sign In to add comment