Advertisement
Guest User

monitor

a guest
Sep 3rd, 2015
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.28 KB | None | 0 0
  1. ----------------------------------------------------------------
  2. -- Railcraft Steam Turbine Monitor v1.0
  3. ----------------------------------------------------------------
  4. -- Written by AmigaLink (http://www.youtube.com/user/AmigaLink)
  5. ----------------------------------------------------------------
  6.  
  7.  
  8. mon = peripheral.wrap("monitor_9")
  9. mfsu = peripheral.wrap("chargepad.mfsu_4")
  10. rednet.open("right")
  11. scale = .5
  12.  
  13. --
  14.  
  15. function writeLeft(text)
  16.   local x,y = mon.getCursorPos()
  17.   x = math.floor((monWidth /3 - string.len(text))/2 )
  18. --  mon.clearLine()
  19.   mon.setCursorPos(x+1,y)
  20.   mon.write(text)
  21. end
  22.  
  23. function writeCenter(text)
  24.   local x,y = mon.getCursorPos()
  25.   x = math.floor(((monWidth /3 -string.len(text))/2)+(monWidth /3))
  26. --  mon.clearLine()
  27.   mon.setCursorPos(x+1,y)
  28.   mon.write(text)
  29. end
  30.  
  31.  
  32. function newLine(lines)
  33.   if lines == nil then lines = 1 end
  34.   local x,y = mon.getCursorPos()
  35.   mon.setCursorPos(1,y+lines)
  36. end
  37.  
  38. mon.setBackgroundColor(colors.black)
  39. mon.setTextColor(colors.white)
  40. mon.clear()
  41. mon.setTextScale(scale)
  42. monWidth, monHeight = mon.getSize()
  43. --print(monWidth)
  44.  
  45. mon.setCursorPos(1,2)
  46. writeLeft("Steam Turbine Monitor")
  47. writeCenter("MFSU Charge Monitor")
  48. newLine()
  49. writeLeft("-----------------------")
  50. writeCenter("-----------------------")
  51.  
  52.  
  53. while true do
  54.   peripherals = peripheral.getNames()
  55.   mon.setCursorPos(1,3)
  56.   turbines = 0
  57.   for i,p in ipairs(peripherals) do
  58.     if peripheral.getType(p) == "rcsteamturbinetile" then
  59.       turbines = turbines + 1
  60.       if turbines > 1 then
  61.         mon.setTextColor(colors.gray)
  62.         newLine("2")
  63.         for i = 1,monWidth do
  64.        --   mon.write("_")
  65.         end
  66.         mon.setTextColor(colors.white)
  67.       end
  68.       TurbineOutput = peripheral.call(p, "getTurbineOutput")
  69.       RotorStatus = peripheral.call(p, "getTurbineRotorStatus")
  70.       newLine("2")
  71.       writeLeft("Output: " .. math.floor(TurbineOutput + 0.5) * 2 .. " EU")
  72.       newLine("2")
  73.       if RotorStatus == nil then
  74.         mon.setTextColor(colors.red)
  75.         RotorStatus = 0
  76.         writeLeft("No rotor available!")
  77.         mon.setTextColor(colors.white)
  78.       else
  79.         writeLeft("Rotor Status: " .. RotorStatus .. " %")
  80.       end
  81.       newLine("2")
  82.       mon.write(" ")
  83.       x,y = mon.getCursorPos()
  84.       barLenght = math.floor((monWidth - 2)/3)
  85.       barWidth = (barLenght / 100) * RotorStatus
  86.       mon.setBackgroundColor(colors.white)
  87.       mon.setTextColor(colors.gray)
  88.       for i = 1,barLenght do
  89.         mon.write("|")
  90.       end
  91.       mon.setBackgroundColor(colors.black)
  92.       mon.setTextColor(colors.white)
  93.       mon.write(" ")
  94.       mon.setCursorPos(x,y)
  95.       if RotorStatus < 41 then
  96.         barColor = colors.red
  97.       elseif RotorStatus > 40 and RotorStatus < 51 then
  98.         barColor = colors.orange
  99.       elseif RotorStatus > 50 and RotorStatus < 61 then
  100.         barColor = colors.yellow
  101.       elseif RotorStatus > 60 and RotorStatus < 81 then
  102.         barColor = colors.lime  
  103.       else
  104.         barColor = colors.green
  105.       end
  106.       mon.setBackgroundColor(barColor)
  107.       mon.setTextColor(colors.black)
  108.       for i = 1,barWidth do
  109.         mon.write("|")
  110.       end
  111.       mon.setBackgroundColor(colors.black)
  112.       mon.setTextColor(colors.white)
  113.      
  114.     end
  115.   end
  116.   sleep(1)
  117. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement