Stravides

RednetReceive4.0

Nov 29th, 2014
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.88 KB | None | 0 0
  1. os.unloadAPI("ProgressBar")
  2. os.loadAPI("ProgressBar")
  3.  
  4. os.unloadAPI("button")
  5. os.loadAPI("button")
  6.  
  7. button.setMon("top")
  8.  
  9. function setbuttons()
  10.   button.add("status", "On/Off","toggle",2,4,15,6,colors.red,colors.green,colors.white,function() prepMsg() end)
  11.   button.setState("status",false)
  12.   button.draw()
  13. end
  14.  
  15. rednet.open("bottom")
  16. ProgressBar.SetPeripheral("top")
  17.  
  18. function showColours()
  19. for i=1,16 do
  20. writeColAt(2+i,23,i,"H")
  21. end
  22. end  
  23.  
  24. m=peripheral.wrap("top")
  25. m.setTextScale(1)
  26. m.setTextColor(5)
  27.  
  28. function split(str, delim, maxNb)  
  29.   if string.find(str, delim) == nil then
  30.     return { str }
  31.   end
  32.   if maxNb == nil or maxNb <1 then
  33.     maxNb = 0
  34.   end
  35.   local result = {}
  36.   local pat = "(.-)"..delim.."()"
  37.   local nb = 0
  38.   local lastPos
  39.   for part, pos in string.gmatch(str,pat) do
  40.     nb = nb+1
  41.     result[nb]=part
  42.     lastPos=pos
  43.     if nb==maxNb then break end
  44.   end
  45.   if nb ~= maxNb then
  46.     result[nb+1] = string.sub(str,lastPos)
  47.   end
  48.   return result
  49. end
  50.  
  51. function round(val, decimal)
  52.   if (decimal) then
  53.     return math.floor( (val * 10^decimal) + 0.5) / (10^decimal)
  54.   else
  55.     return math.floor(val+0.5)
  56.   end
  57. end
  58.  
  59.  
  60. function writeAt(x,y,text)
  61.   m.setCursorPos(x,y)
  62.   m.write(text)
  63. end
  64.  
  65. function writeColAt(x,y,colour,text)
  66.    m.setTextColor(colour)
  67.    m.setCursorPos(x,y)
  68.   m.write(text)
  69. end
  70.  
  71.  function white()
  72.         m.setTextColor(colors.white)
  73. end
  74.  
  75. function orange()
  76.         m.setTextColor(colors.orange)
  77. end
  78.  
  79. function magenta()
  80.         m.setTextColor(colors.magenta)
  81. end
  82.  
  83. function lightblue()
  84.         m.setTextColor(colors.lightBlue)
  85. end
  86. function yellow()
  87.         m.setTextColor(colors.yellow)
  88. end
  89. function lime()
  90.         m.setTextColor(colors.lime)
  91. end
  92. function pink()
  93.         m.setTextColor(colors.pink)
  94. end
  95. function gray()
  96.         m.setTextColor(colors.gray)
  97. end
  98. function lightgray()
  99.         m.setTextColor(colors.lightGray)
  100. end
  101. function cyan()
  102.         m.setTextColor(colors.cyan)
  103. end
  104. function purple()
  105.         m.setTextColor(colors.purple)
  106. end
  107. function blue()
  108.         m.setTextColor(colors.blue)
  109. end
  110. function brown()
  111.         m.setTextColor(colors.brown)
  112. end
  113. function green()
  114.         m.setTextColor(colors.green)
  115. end
  116. function red()
  117.         m.setTextColor(colors.red)
  118. end
  119. function black()
  120.         m.setTextColor(colors.black)
  121. end
  122.  
  123. while true do
  124.   local time= os.time()
  125.   local fTime = textutils.formatTime(time,false)
  126.   local event, id, msg = os.pullEvent("rednet_message")
  127.   local Tab = split(msg,"|",32)
  128.   local pc = round(Tab[27]*100,0)
  129.   local es = round(Tab[2]/100000,0)
  130.   local fpc = round(Tab[31]*100,0)
  131.   m.clear()
  132.   white()
  133.   writeAt(22,25,fTime)
  134.   blue()
  135.   writeAt(2,1,"Reactor Info")
  136.   white()
  137.   writeAt(2,3,"Status:           "..Tab[13])
  138.   writeAt(2,4,"Energy Stored")
  139.   ProgressBar.SetTable("Energy",100,es,20,45,4)
  140.   writeAt(2,5,"Fuel Level: ")
  141.   ProgressBar.SetTable("Fuel",100,fpc,20,45,5)
  142.   writeAt(2,6,"Core Temp:        "..round(Tab[16],1).."C")
  143.   writeAt(2,7,"Case Temp:        "..round(Tab[19],1).."C")
  144.   writeAt(2,8,"Coolant Type:     "..Tab[20])
  145.   writeAt(2,9,"Coolant Level:    ")
  146.   ProgressBar.SetTable("Coolant",100,pc,20,45,9)
  147.   writeAt(2,10,"Waste Level:      "..Tab[31])
  148.    
  149.   writeAt(2,12,"Turbine Info")
  150.   writeAt(2,14,"Status:           "..Tab[13])
  151.   writeAt(2,15,"Energy Stored     "..Tab[2])
  152.   writeAt(2,16,"Rotor Speed:      "..round(Tab[3],0).." RPM")
  153.   writeAt(2,17,"Input Type:       "..Tab[5])
  154.   writeAt(2,18,"Input Amount:     "..Tab[4].." MB")
  155.   writeAt(2,19,"Output Type:      "..Tab[7])
  156.   writeAt(2,20,"Output Amount:    "..Tab[6].." MB")
  157.   writeAt(2,21,"Coil Status:      ")
  158.   red()
  159.   writeAt(20,21,Tab[12])
  160.   white()
  161.   ProgressBar.DrawToPeripheral()
  162.   sleep(1)
  163. --  ProgressBar.SetCurValue("Test",pc)
  164. --  ProgressBar.DrawToPeripheral()
  165. --  sleep(1)
  166. --  button.check() -- This goes into a wait loop and does not come out again....
  167. end
Advertisement
Add Comment
Please, Sign In to add comment