Advertisement
magnasiefr

MFSU receiver

Oct 25th, 2016
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.21 KB | None | 0 0
  1. local mon = peripheral.wrap("back")
  2. local glass = peripheral.wrap("left")
  3. local total = 0
  4. monX, monY = mon.getSize()
  5.  
  6. --Fonction
  7.  
  8. function clear()
  9.   mon.setBackgroundColor(colors.black)
  10.   mon.clear()
  11.   mon.setCursorPos(1,1)
  12. end
  13.  
  14. function drawText(x, y, text, color_txt, color_bg)
  15.   mon.setBackgroundColor(color_bg)
  16.   mon.setTextColor(color_txt)
  17.   mon.setCursorPos(x,y)
  18.   mon.write(text)
  19. end
  20.  
  21. function drawLine(x, y, length, size, color_bar)
  22.   for yPos = y, y+size-1 do
  23.     mon.setBackgroundColor(color_bar)
  24.     mon.setCursorPos(x, yPos)
  25.     mon.write(string.rep(" ", length))
  26.   end
  27. end
  28.  
  29. function drawProg(x, y, name, length, size, minVal, maxVal, color_bar, color_bg)
  30.   drawLine(x, y, length, size, color_bg)
  31.   local barSize = math.floor((minVal/maxVal)*length)
  32.   drawLine(x, y, barSize, size, color_bar)
  33.   local text = name.." "..math.floor((minVal/maxVal)*100).."%"
  34.   if barSize > length/2+#text/2 then
  35.     drawText(x+length/2-#text/2, y+size/2, text, colors.black, color_bar)
  36.   elseif barSize > #text then
  37.     drawText((x+barSize)-#text, y+size/2, text, colors.black, color_bar)
  38.   else
  39.     drawText(x+length/2-#text/2, y+size/2, text, colors.black, color_bg)
  40.   end
  41. end
  42.  
  43. --End fonction
  44.  
  45. mon.setBackgroundColor(colors.black)
  46.  
  47. while true do
  48. mon.clear()
  49. glass.clear()
  50.  
  51. mon.setTextColor(colors.white)
  52. glass.addText(5,20,"Monitor ..",0xF7F7F7)
  53. mon.setCursorPos(1,1)
  54. mon.setTextScale(1)
  55. mon.write("Monitor ..")
  56. sleep(1)
  57.  
  58. local mon = peripheral.wrap("back")
  59. if mon then
  60. mon.setTextColor(colors.green)
  61. mon.write(" Ok")
  62. glass.addText(50,20,"Ok",0x15ff00)
  63.  
  64. else
  65. mon.setTextColor(colors.red)
  66. mon.write(" Failed")
  67. glass.addText(50,20,"Failed",0xff0000)
  68. stop()
  69. end
  70.  
  71. sleep(1)
  72. mon.setTextColor(colors.white)
  73. mon.setCursorPos(1,2)
  74. mon.setTextScale(1)
  75. mon.write("Modem ..")
  76. glass.clear()
  77. glass.addText(5,20,"Modem ..",0xF7F7F7)
  78. sleep(1)
  79.  
  80. local modem = peripheral.wrap("bottom")
  81. if modem then
  82. mon.setTextColor(colors.green)
  83. mon.write(" Ok")
  84. glass.addText(50,20,"Ok",0x15ff00)
  85.  
  86. else
  87. mon.setTextColor(colors.red)
  88. mon.write(" Failed")
  89. glass.addText(50,20,"Failed",0xff0000)
  90. stop()
  91. end
  92.  
  93. sleep(1)
  94. mon.setTextColor(colors.white)
  95. mon.setCursorPos(1,3)
  96. mon.setTextScale(1)
  97. mon.write("Terminal Glasses Bridge ..")
  98. glass.clear()
  99. glass.addText(5,20,"Terminal Glasses Bridge ..",0xF7F7F7)
  100. sleep(1)
  101.  
  102. local glass = peripheral.wrap("left")
  103. if modem then
  104. mon.setTextColor(colors.green)
  105. mon.write(" Ok")
  106. glass.addText(150,20,"Ok",0x15ff00)
  107.  
  108. else
  109. mon.setTextColor(colors.red)
  110. mon.write(" Failed")
  111. glass.addText(150,20,"Failed",0xff0000)
  112. stop()
  113. end
  114.  
  115. sleep(1)
  116.  
  117. mon.setTextColor(colors.white)
  118. mon.setCursorPos(1,4)
  119. glass.clear()
  120. mon.write("Waiting for a signal ..")
  121. glass.addText(5,20,"Waiting for a signal ..",0xF7F7F7)
  122.  
  123. while modem do
  124. modem.open(7)
  125. local event, modemSide, senderChannel, replyChannel, mfsu, senderDistance = os.pullEvent("modem_message")
  126. total = mfsu / 4000000 * 100
  127.  
  128. clear()
  129. drawProg(0,0, "MFE", 40, 6, total, 100, colors.green, colors.gray)
  130.  
  131. mon.setBackgroundColor(colors.black)
  132. mon.setCursorPos(1,6)
  133. mon.setTextColor(colors.white)
  134.  
  135. glass.clear()
  136. glasstot = math.floor(total)
  137. glass.addText(5,20,"MFSU = "..glasstot.."%",0xF7F7F7)
  138. sleep(0.2)
  139.  
  140.  
  141. end
  142. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement