Elgskred

CCRecieve

Feb 19th, 2016
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.74 KB | None | 0 0
  1. --Power controller
  2.  
  3.  
  4. function Reduce(num)
  5.     local temp = 0
  6.     local a = ""
  7.     if num > 1000 then
  8.         temp = round(num / 1000, 2)
  9.         a = temp .. "KRF"
  10.  
  11.     end
  12.     if num > 1000000 then
  13.         temp = round(num / 1000000, 2)
  14.         a = temp .. "MRF"
  15.  
  16.     end
  17.     if num > 1000000000 then
  18.         temp = round(num / 1000000000, 2)
  19.         a = temp .. "GRF"
  20.  
  21.     end
  22.    
  23.     return a
  24. end
  25.  
  26. function round(number, decimal)
  27.     local multiplier = 10^(decimal or 0)
  28.     return math.floor(number * multiplier + 0.5) / multiplier
  29. end
  30.  
  31. local modem = peripheral.wrap("back")
  32. modem.open(1)
  33. --=Chanel 1 is used for recieving all transmissions
  34.  
  35. local monitor = peripheral.wrap("right")
  36. local w, h = monitor.getSize()
  37. --Prints header to monitor
  38. local header = "Power monitor"
  39. local sLenght = string.len(header)
  40. monitor.clear()
  41. monitor.setCursorPos((w / 2) - (sLenght / 2), 1)
  42. monitor.write(header)
  43.  
  44.  
  45. local numberOfReactors = 2
  46.  
  47. while true do
  48.  
  49. local event, modemSide, recieveChan, replyChan, msg, senderDistance = os.pullEvent("modem_message")
  50. print(msg)
  51. local t = textutils.unserialize(msg)
  52.  
  53. for i = 0, numberOfReactors - 1 do
  54.     if t[1] == (i + 1) then
  55.        
  56.         if t[2] == true then
  57.             monitor.setTextColor(colors.green)
  58.             monitor.setCursorPos(1, 3 + (5 * i))
  59.             monitor.clearLine()
  60.             monitor.write("Reactor " .. i .. ": ")
  61.             local x, y = monitor.getCursorPos()
  62.             monitor.setCursorPos(x + 2, y)
  63.             monitor.write("Online")
  64.             monitor.setTextColor(colors.white)
  65.            
  66.         else
  67.             monitor.setTextColor(colors.red)
  68.             monitor.setCursorPos(1, 3 + (5 * i))
  69.             monitor.clearLine()
  70.             monitor.write("Reactor " .. i .. ": ")
  71.             local x, y = monitor.getCursorPos()
  72.             monitor.setCursorPos(x + 2, y)
  73.             monitor.write("Offline")
  74.             monitor.setTextColor(colors.white)
  75.  
  76.         end
  77.         monitor.setCursorPos(1, 4 + (5 * i))
  78.         monitor.clearLine()
  79.         monitor.write("Energy stored: ".. round(t[4], 2) .."%")
  80.         monitor.setCursorPos(1, 5 + (5 * i))
  81.         monitor.clearLine()
  82.         local temp = Reduce(t[3])
  83.         monitor.write("Energy last tick: ".. temp)
  84.     end
  85. end
  86.     if t[1] == 3 then
  87.         monitor.setCursorPos(1, (numberOfReactors * 5) + 3)
  88.         monitor.clearLine()
  89.         monitor.setTextColor(colors.green)
  90.         monitor.write("Induction Matrix: ")
  91.         local x,y = monitor.getCursorPos()
  92.         monitor.setCursorPos(x + 2, y)
  93.         monitor.write(reduce(t[5]))
  94.         monitor.setTextColor(colors.white)
  95.         monitor.setCursorPos(1, (numberOfReactors * 5) + 4)
  96.         monitor.clearLine()
  97.         monitor.write("Energy stored: " .. round(t[2], 2) .. "%")
  98.         monitor.setCursorPos(1, (numberOfReactors * 5) + 5)
  99.         monitor.clearLine()
  100.         local temp = Reduce(t[3])
  101.         monitor.write("Input: " .. temp)
  102.         monitor.setCursorPos(1, (numberOfReactors * 5) + 6)
  103.         monitor.clearLine()
  104.         temp = Reduce(t[4])
  105.         monitor.write("Output: " .. temp)
  106.     end
  107. end
Advertisement
Add Comment
Please, Sign In to add comment