Advertisement
pitrey

house > hub

Nov 14th, 2019
265
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.30 KB | None | 0 0
  1. modemC = peripheral.wrap('top') --cable
  2. modemW = peripheral.wrap('left')--wifi
  3.  
  4.  
  5. modemW.open(51)
  6.  
  7.  
  8. EUn1 = 0
  9. EUn2 = 0
  10. RFn1 = 0
  11. RFn2 = 0
  12. EU2n1 = 0
  13. EU2n2 = 0
  14. RF2n1 = 0
  15. RF2n2 = 0
  16. moni = peripheral.wrap("monitor_4")
  17. moni.setBackgroundColor(colors.black)
  18. moni.setTextScale(1)
  19. mfe = nil
  20. mfe2 = nil
  21. mfeMax = nil
  22. mfe2Max = nil
  23. cube2 = nil
  24. cube = nil
  25. cubeMax = nil
  26.  
  27. function recevoir()
  28.  
  29. e, s, frequency, reply, m, d = os.pullEvent("modem_message")
  30. if frequency == 51 then
  31. if reply == 52 then
  32. RFStored = m
  33. elseif reply == 53 then
  34. RF2Stored = m
  35. elseif reply == 54 then
  36. EUStored = m
  37. elseif reply == 55 then
  38. EU2Stored = m
  39. elseif reply == 56 then
  40. cubeMax = m
  41. elseif reply == 57 then
  42. cube2Max = m
  43. elseif reply == 58 then
  44. mfeMax = m
  45. elseif reply == 59 then
  46. mfe2Max = m
  47. end
  48.  
  49. end
  50.  
  51. end
  52.  
  53.  
  54. function quelColor(energy)
  55. if energy < 20 then c = colors.red end
  56. if energy >20 and energy < 70 then c = colors.yellow end
  57. if energy > 70 then c = colors.green  end
  58. return(c)
  59. end
  60.  
  61. function titre (x,y,titre,c)
  62. moni.setTextColor(c)
  63. moni.setCursorPos(x,y)
  64. moni.write (titre)
  65. end
  66.  
  67. function etat (x,y,n1,n2)
  68. e = (n1 - n2)/100
  69. e = math.floor (e)/10
  70. if e < 0 then c = colors.red
  71. else c = colors.green end
  72. moni.setTextColor(c)
  73. moni.setCursorPos(x,y)
  74. moni.write (e)
  75. moni.write ('K')
  76. end
  77.  
  78. function barre (x,y,ener,col)
  79. moni.setCursorPos(x,y)
  80. I = ener /8
  81. for i =1,I do
  82. moni.setBackgroundColor(col)
  83. moni.write(" ")
  84. end
  85. moni.setBackgroundColor(colors.black)
  86. end
  87.  
  88.  
  89. while true do
  90. recevoir()
  91. if EUStored ~= nil and mfeMax ~= nil then
  92. EU = math.floor(((EUStored ) / mfeMax ) *1000)/10
  93. EUn1 = EUStored
  94. end
  95. if EU2Stored ~= nil and mfe2Max ~= nil then
  96. EU2 = math.floor(((EU2Stored ) / mfe2Max ) *1000)/10
  97. EU2n1 = EU2Stored
  98. end
  99. if RFStored ~= nil and cubeMax ~= nil then
  100. RF = math.floor((RFStored / cubeMax ) *1000)/10
  101. RFn1 = RFStored
  102. end
  103. if RF2Stored ~= nil and cube2Max ~= nil then
  104. RF2 = math.floor((RF2Stored / cube2Max ) *1000)/10
  105. RF2n1 = RF2Stored
  106. end
  107.  
  108. moni.clear()
  109. titre(8,1,"Monitoring -> le Porc",colors.yellow)
  110. titre(2,3,"RF Principal",colors.white)
  111. titre(2,8,"RF Secondaire",colors.white)
  112. titre(16,3,"EU Principal",colors.white)
  113. titre (16,8,"EU Secondaire",colors.white)
  114.  
  115.  
  116. if EU ~= nil then
  117. titre(20,4,EU,quelColor(EU))
  118. moni.write("%")
  119. barre(16,5,EU,quelColor(EU))
  120. etat(19,6,EUn1,EUn2)
  121. else
  122. titre (20,4,"indisponible",colors.red)
  123. titre (20,5,"indisponible",colors.red)
  124. titre (20,6,"indisponible",colors.red)
  125. end
  126.  
  127. if EU2 ~= nil then
  128. titre(20,9,EU2,quelColor(EU2))
  129. moni.write("%")
  130. barre(16,10,EU2,quelColor(EU2))
  131. etat(19,11,EU2n1,EU2n2)
  132. else
  133. titre (20,9,"indisponible",colors.red)
  134. titre (20,10,"indisponible",colors.red)
  135. titre (20,11,"indisponible",colors.red)
  136. end
  137.  
  138. if RF ~= nil then
  139. titre(6,4,RF,quelColor(RF))
  140. moni.write("%")
  141. barre(2,5,RF,quelColor(RF))
  142. etat(5,6,RFn1,RFn2)
  143. else
  144. titre (20,4,"indisponible",colors.red)
  145. titre (20,5,"indisponible",colors.red)
  146. titre (20,6,"indisponible",colors.red)
  147. end
  148.  
  149. if RF2 ~= nil then
  150. titre(6,9,RF2,quelColor(RF2))
  151. moni.write("%")
  152. barre(2,10,RF2,quelColor(RF2))
  153. etat(5,11,RF2n1,RF2n2)
  154. else
  155. titre (20,9,"indisponible",colors.red)
  156. titre (20,10,"indisponible",colors.red)
  157. titre (20,11,"indisponible",colors.red)
  158. end
  159.  
  160. moni.setBackgroundColor(colors.black)
  161. EUn2 = EUn1
  162. EU2n2 = EU2n1
  163. RFn2 = RFn1
  164. RF2n2 = RF2n1
  165.  
  166.  
  167. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement