Guest User

Untitled

a guest
Dec 4th, 2013
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.42 KB | None | 0 0
  1. mfsu = {}
  2. mfsu["1"] = peripheral.wrap("mfsu_3")
  3. mfsu["2"] = peripheral.wrap("mfsu_4")
  4. mfsu["3"] = peripheral.wrap("mfsu_5")
  5. mfsu["4"] = peripheral.wrap("mfsu_6")
  6. mfsu["5"] = peripheral.wrap("mfsu_7")
  7. mfsu["6"] = peripheral.wrap("mfsu_8")
  8. mfsu["7"] = peripheral.wrap("mfsu_9")
  9. mfsu["8"] = peripheral.wrap("mfsu_10")
  10. mfsu["9"] = peripheral.wrap("mfsu_11")
  11. m = peripheral.wrap("monitor_13")
  12. m.clear()
  13. storedEU = {}
  14. storedPerc = {}
  15. plotter = {}
  16. printer = {}
  17. energyTotals = 0
  18. energyFlow = 0
  19.  
  20. function storedTotal()
  21.  energyTotal = 0
  22.  for i = 1,9 do
  23.    energyTotal = energyTotal + mfsu[tostring(i)].getEUStored()
  24.  end
  25.  energyFlow = (energyTotal - energyTotals) / 20
  26.  energyTotals = energyTotal
  27.  energyPercentage = shorten(tostring(energyTotal / 360000000 * 100))
  28.  m.setCursorPos(3,3)
  29.  m.write("Total Energy Stored: "..energyTotal.." EU")
  30.  m.setCursorPos(9,4)
  31.  m.write("Total Capacity: ")
  32.  colorPerc(energyPercentage)
  33. end
  34.  
  35. function storedEach()
  36.  for i = 1,9 do
  37.    storedEU[i] = mfsu[tostring(i)].getEUStored()
  38.    storedPerc[i] = shorten(tostring(storedEU[i] / 40000000 * 100))
  39.  end
  40.  m.setCursorPos(1,6)
  41.  for i = 1,3 do
  42.   m.write("MFSU"..i..": ")
  43.   colorPerc(storedPerc[i])
  44.   xPos = i * 14
  45.   m.setCursorPos(xPos,6)
  46.  end
  47.  m.setCursorPos(1,7)
  48.  for i = 4,6 do
  49.   m.write("MFSU"..i..": ")
  50.   colorPerc(storedPerc[i])
  51.   xPos = (i-3) * 14
  52.   m.setCursorPos(xPos,7)
  53.  end
  54.  m.setCursorPos(1,8)
  55. for i = 7,9 do
  56.   m.write("MFSU"..i..": ")
  57.   colorPerc(storedPerc[i])
  58.   xPos = (i-6) * 14
  59.   m.setCursorPos(xPos,8)
  60.  end
  61. end
  62.  
  63. function shorten(num)
  64.  if num ~= nil then
  65.   dec = string.find(tostring(num),".",1,true)
  66.   if dec ~= nil then
  67.    dec = dec + 1
  68.    return (string.sub(num,1,dec))
  69.   end
  70.   else
  71.  return ("0")
  72.  end
  73. end
  74.  
  75. function percRound(num)
  76.  subW,subR,whole,remainder = 0,0,0,0
  77.  subW,subR = string.len(num) - 2 , string.len(num)
  78.  whole = tonumber(string.sub(num,1,subW))
  79.  remainder = tonumber(string.sub(num,subR,subR))
  80.  if remainder >= 5 then
  81.   whole = whole + 1
  82.   end
  83.  return whole
  84. end
  85.  
  86. function colorPerc(num)
  87.  num = tonumber(num)
  88.  if num ~= nil then
  89.   if num >= 0 then
  90.     m.setTextColor(colors.red)
  91.   end
  92.   if num > 30 then
  93.     m.setTextColor(colors.orange)
  94.   end
  95.   if num > 60 then
  96.     m.setTextColor(colors.yellow)
  97.   end
  98.   if num > 90 then
  99.     m.setTextColor(colors.lime)
  100.   end
  101.    m.write(num.."%")
  102.    space = string.len(tostring(num)) - 5 * (-1)
  103.   for i = 1,space do
  104.    m.write(" ")
  105.   end
  106.   m.setTextColor(colors.white)
  107.  end
  108. end
  109.  
  110. function flowChart()
  111.  for i = 1,15 do
  112.   m.setCursorPos(6,(i + 10))
  113.   m.write("|")
  114.  end
  115.  for i = 1,39 do
  116.   m.setCursorPos(i,26)
  117.   m.write("-")
  118.  end
  119.  for i = 1,15 do
  120.   m.setCursorPos(34,(i + 10))
  121.   m.write("|")
  122.  end
  123.  for i = 1,2 do
  124.   if i == 1 then
  125.     yP = 1
  126.     else
  127.     yP = 35
  128.   end
  129.   m.setCursorPos(yP,11)
  130.   m.write("2.1k ")
  131.   m.setCursorPos(yP,13)
  132.   m.write("1.5k ")
  133.   m.setCursorPos(yP,15)
  134.   m.write(" 900 ")
  135.   m.setCursorPos(yP,17)
  136.   m.write(" 300 ")
  137.   m.setCursorPos(yP,19)
  138.   m.write("-300 ")
  139.   m.setCursorPos(yP,21)
  140.   m.write("-900 ")
  141.   m.setCursorPos(yP,23)
  142.   m.write("-1.5k")
  143.   m.setCursorPos(yP,25)
  144.   m.write("-2.1k")
  145.  end
  146. end
  147.  
  148. function drawPlots()
  149.  m.setCursorPos(12,26)
  150.  m.write("--("..energyFlow.." EU/t)--------")
  151.  yPos = plotPos(energyFlow) + 18
  152.  printer[34] = yPos
  153.  for i = 7,33 do
  154.   j = i + 1
  155.   h = i
  156.   printer[i] = printer[j]
  157.   for i = 11,25 do
  158.    m.setCursorPos(h,i)
  159.    if i == printer[h] then
  160.     if i < 18 then
  161.      m.setBackgroundColor(colors.cyan)
  162.      else
  163.      m.setBackgroundColor(colors.blue)
  164.     end
  165.    else
  166.     m.setBackgroundColor(colors.black)
  167.    end
  168.    m.write(" ")
  169.    m.setBackgroundColor(colors.black)
  170.   end
  171.  end
  172. end
  173.  
  174. function plotPos(num)
  175.  plotter,plotW,plotR = 0,0,0
  176.  plotter = energyFlow / 300
  177.  if plotter < 0 then
  178.   plotW = tonumber(string.sub(tostring(plotter),2,2))
  179.   plotR = tonumber(string.sub(tostring(plotter),4,4))
  180.   negative = true
  181.  else
  182.   plotW = tonumber(string.sub(tostring(plotter),1,1))
  183.   plotR = tonumber(string.sub(tostring(plotter),3,3))
  184.   negative = false
  185.  end
  186.  if plotR ~= nil then
  187.   if plotR >= 5 then
  188.    plotW = plotW + 1
  189.   end
  190.  end
  191.  if negative == false then
  192.   plotW = plotW * (-1)
  193.  end
  194.  return plotW
  195. end
  196.  
  197. function label()
  198.  m.setCursorPos(13,1)
  199.  m.write("Energy Monitor")
  200.  m.setCursorPos(1,10)
  201.  m.write("---------- Energy Flow (EU/t)----------")
  202. end
  203.  
  204. label()
  205. flowChart()
  206.  
  207. while true do
  208. storedTotal()
  209. storedEach()
  210. drawPlots()
  211. sleep(1)
  212. end
Advertisement
Add Comment
Please, Sign In to add comment