marko_rus

SATcom base control

Oct 10th, 2021 (edited)
435
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.34 KB | None | 0 0
  1. local red = redstone
  2. local modemWire = peripheral.wrap("left")
  3. local monitor = peripheral.wrap("back")
  4. local green = 32
  5. local red = 16384
  6. local defColor = 1
  7. local basePort = 228
  8. local status = {farm = false, ME = false, security = false, dataStorage = false, enigma = false, RAD2 = false, GPSRadar = false, GPSRadarStat = "GPS    "}
  9.  
  10. if monitor.isColor() == false then
  11.  
  12. print("Kupi sebe novui monitor, bomzhara")
  13. return 0
  14. end
  15.  
  16. monitor.setTextScale(1)
  17. monitor.setCursorBlink(false)
  18.  
  19. function recv (timeout)
  20.  
  21. os.startTimer(timeout)
  22. while true do
  23.  
  24. local sEvent, p1, p2, p3, p4, p5 = os.pullEvent()
  25. if sEvent == "modem_message" then return p1, p2, p3, p4, p5
  26. else return nil end
  27. end
  28. end
  29.  
  30. function writeState(text, state, ifTrue, ifFalse)
  31.     monitor.setTextColor(defColor)
  32.     monitor.write(text .. ": ")
  33.    
  34.     if state then
  35.     monitor.setTextColor(green)
  36.     monitor.write(ifTrue)
  37.    
  38.     else
  39.     monitor.setTextColor(red)
  40.     monitor.write(ifFalse)
  41.     end
  42. end
  43.  
  44. function updateStatus ()
  45. monitor.setCursorPos(1,1)
  46.     writeState("Farm", status.farm, "online ", "offline")
  47.    
  48.     monitor.setCursorPos(1,2)
  49.     writeState("ME storage", status.ME , "online ", "offline")
  50.    
  51.     monitor.setCursorPos(1,3)
  52.     writeState("Security", status.security , "online ", "offline")
  53.    
  54.     monitor.setCursorPos(1,4)
  55.     writeState("Data storage", status.dataStorage, "online ", "offline")
  56.    
  57.     monitor.setCursorPos(1,5)
  58.     writeState("Enigma", status.enigma, "online ", "offline")
  59.    
  60.     monitor.setCursorPos(1,6)
  61.     writeState("Radar RAD2", status.RAD2, "online ", "offline")
  62.    
  63.     monitor.setCursorPos(1,7)
  64.     writeState("GPS radar", status.GPSRadar , status.GPSRadarStat, "offline")
  65. end
  66.  
  67. modemWire.open(basePort)
  68. local i = 1
  69. while true do
  70.    
  71.     i = 1
  72.     while i < 7 do
  73.         status[i] = false
  74.         i = i + 1
  75.     end
  76.     i = 0
  77.     while i < 60 do
  78.         local p1, p2, p3, p4, p5 = recv(5)
  79.         if p4 == "farm" then status.farm = true
  80.         elseif p4 == "ME" then status.ME = true
  81.         elseif p4 == "security" then status.security = true
  82.         elseif p4 == "dataStorage" then status.dataStorage = true
  83.         elseif p4 == "enigma" then status.enigma = true
  84.         elseif p4 == "RAD-2" then status.RAD2 = true
  85.         elseif p4 == "GPSRadar" then status.GPSRadar = true status.GPSRadarStat = "GPS radar"
  86.         elseif p4 == "RAD-5" then status.GPSRadar = true status.GPSRadarStat = "RAD5"
  87.         end
  88.         i = i + 5
  89.     end
  90.    
  91.     i = 0
  92.     updateStatus()
  93.     os.sleep(1)
  94. end
Add Comment
Please, Sign In to add comment