LivioBrunner

Energy Control Monitor

Nov 15th, 2013
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.61 KB | None | 0 0
  1. local nb = peripheral.wrap("top")
  2. local mon = peripheral.wrap("bottom")
  3. local all = 0
  4. local mfsu = {11,12}
  5. local strom = {}
  6. local length = 30
  7. local function printCenter(mon, txt)
  8.   local w, h = mon.getSize()
  9.   local x = math.floor((w / 2) - (#txt / 2))
  10.   local y = math.floor((h / 2))
  11.   mon.setCursorPos(x, y)
  12.   mon.write(txt)
  13. end
  14.  
  15. function createBox(x,y,width,height,color,mon)
  16.     mon.setCursorPos(x,y)
  17.         for j = 0, height do
  18.         mon.setCursorPos(x,y+j)
  19.         for i = 0,width do
  20.             mon.setBackgroundColor(color)
  21.             mon.write(" ")
  22.         end
  23.     end
  24. end
  25. function clear(mon)
  26.     local w,h = mon.getSize()
  27.     for i = 0,h do
  28.         for j = 0, w do
  29.             mon.setCursorPos(1+j,1+i)
  30.             mon.setBackgroundColor(colors.black)
  31.             mon.write(" ")
  32.         end
  33.     end
  34. end
  35. clear(mon)
  36. function getAllEU()
  37.         local all = 0
  38.     for i = mfsu[1], tablelength(mfsu)+mfsu[1]-1 do
  39.         all = all + strom[i]
  40.     end
  41.     return all
  42. end
  43. function tablelength(T)
  44.   local count = 0
  45.   for _ in pairs(T) do count = count + 1 end
  46.   return count
  47. end
  48.    
  49. while true do
  50.   for i = mfsu[1], tablelength(mfsu)+mfsu[1]-1 do
  51.     EU = nb.callRemote("batbox_"..i, "getStored")
  52.     print(EU)
  53.     strom[i] = EU
  54.   end
  55.    red =  length / (tablelength(mfsu) * 10000000) * getAllEU()
  56.    clear(mon)
  57.    createBox(6,3,length,2,colors.blue,mon)
  58.    createBox(6 + red - 2,0,1,7,colors.red,mon)
  59.    mon.setTextColor(colors.white)
  60.    mon.setCursorPos(0,9)
  61.    mon.setBackgroundColor(colors.black)
  62.    printCenter(mon, getAllEU() .."/".. (tablelength(mfsu) * 10000000).."EU")
  63.    --text = p.addText(3,3 , getAllEU() .."/".. (tablelength(mfsu) * 10000000).."EU", 0x000000)
  64.    sleep(1)
  65. end
Advertisement
Add Comment
Please, Sign In to add comment