Advertisement
Aixler

Monitor

Nov 4th, 2013
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.88 KB | None | 0 0
  1. --Set params
  2. monitorSide = "top"
  3. modemSide = "right"
  4.  
  5. m = peripheral.wrap(monitorSide)
  6. rednet.open(modemSide)
  7. m.setTextScale(1)
  8. m.setBackgroundColor(colors.black)
  9. m.clear()
  10. oldValues = {}
  11.  
  12. --layout: name, id, loc_x, loc_y, length, storageType, color, displayName
  13. apps = {
  14.         {"lava", 68, 1, 1, 39, "tank", colors.red, "Lava "},
  15.         {"fuel", 54, 1, 2, 39, "tank", colors.yellow, "Fuel "},
  16.         {"oil", 70, 1, 3, 39, "tank", colors.black, "Oil  "},
  17.         {"water", 71, 1, 4, 39, "tank", colors.blue, "Water"},
  18.         {"MFSU", 73, 1, 5, 39, "power", colors.cyan, "Power"},
  19.         {"steam", 140, 1, 6, 39, "tank", colors.gray, "Steam"},
  20.         {"mobessence", 109, 1, 7, 39, "tank", colors.green, "Mob E"},
  21.         {"immibis.liquidxp", 122, 1, 8, 39, "tank", colors.lime, "LXP  "},
  22.         {"seedoil", 141, 1, 9, 39, "tank", colors.brown, "Seed "},
  23.         {"honey", 142, 1, 10, 39, "tank", colors.yellow, "Honey"},
  24.         {"heliumplasma", 147, 1, 11, 39, "tank", colors.lightBlue, "H-Pla"},
  25.         }
  26.  
  27. --fill table with tables
  28. for _,v in ipairs(apps) do
  29.     oldValues[v[1]] = {1,1}
  30. end
  31.  
  32. function screen(loc_x, loc_y, length, storageType, color, displayName, name, amount, capacity)
  33.     m.setTextScale(1.5)
  34.     local space = " "
  35.     m.setCursorPos(loc_x, loc_y)
  36.     space = string.rep(space, length)
  37.     m.write(space)
  38.     m.setCursorPos(loc_x, loc_y)
  39.     m.setBackgroundColor(color)
  40.    
  41.     if storageType == "ERROR" then
  42.         m.write(storageType)
  43.     elseif storageType == "mismatch" then
  44.         m.write("names dont match, recheck computer id")
  45.     else
  46.         local percentage = 0
  47.         local deltaTime, deltaAmount = 0, 0
  48.         percentage = math.floor(amount / capacity * 100)
  49.    
  50.         local change = 0
  51.         deltaTime = os.time() - oldValues[name][2]
  52.         deltaAmount = amount - oldValues[name][1]
  53.         change = deltaAmount / deltaTime
  54.         change = math.floor(change / 1000)
  55.         if change > 0 then
  56.             change = "+"..tostring(change)
  57.         end
  58.        
  59.         if storageType == "tank" then
  60.             change = change.." mB/t"
  61.         elseif storageType == "power" then
  62.             change = change.." eu/t"
  63.         end
  64.        
  65.         m.write(displayName..": "..change.." ("..percentage.."%)")
  66.        
  67.         oldValues[name] = {amount, os.time()}
  68.     end
  69.     m.setBackgroundColor(colors.black)
  70. end
  71.  
  72. function split(msg)
  73.      local values = {}
  74.      number = 1
  75.      for word in string.gmatch(msg, "%S+") do
  76.        values[number] = word
  77.        number = number + 1
  78.      end
  79.      return values[1], values[2], values[3]
  80. end
  81.  
  82. function main()
  83.     for _,j in ipairs(apps) do
  84.         id, msg, distance = nil, nil, nil
  85.         name, amount, capacity = nil, nil, nil
  86.         rednet.send(j[2],"ping")
  87.         id, msg, distance = rednet.receive(5)
  88.         if id == j[2] then
  89.             name, amount, capacity = split(msg)
  90.             if name == j[1] then
  91.                 screen(j[3], j[4], j[5], j[6], j[7], j[8], name, amount, capacity)
  92.             else
  93.                 screen(j[3], j[4], j[5], "mismatch", j[7])
  94.             end
  95.         end
  96.         if id == nil then
  97.             screen(j[3], j[4], j[5], "ERROR", j[7])
  98.         end
  99.         sleep(4)
  100.     end
  101. end
  102.            
  103. while true do
  104.     main()
  105.     sleep(5)
  106. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement