loccode

Wi-Fi Init

Jan 29th, 2021 (edited)
402
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.90 KB | None | 0 0
  1. function showMenu()
  2.     -- set up monitor
  3.     term.setBackgroundColor(colors.black)
  4.     term.setTextColor(colors.white)
  5.     term.clear()
  6.  
  7.     -- Display the button
  8.     term.setBackgroundColor(colors.blue)
  9.     term.setCursorPos(3, 2)
  10.     term.write(string.rep(" ", 10)) -- 10 spaces
  11.  
  12.     --Display the label
  13.     term.setTextColor(colors.white)
  14.     term.setCursorPos(3 + 2, 2) -- remember 2 columns more for centering here
  15.     term.write("Test")
  16. end
  17.  
  18. function sendTurtle()
  19.     local sendTurtleByGPS = require("sendTurtleByGPS")
  20.  
  21.     sendTurtleByGPS.send()
  22. end
  23.  
  24. function doAction(action)
  25.     if action == "showMenu" then
  26.         showMenu()
  27.     elseif action == "sendTurtle" then
  28.         sendTurtle()
  29.     else
  30.         print("Net dannoy komandi")
  31.     end
  32. end
  33.  
  34. function getResult(senderId, protocol, typeTurtle)
  35.     if (senderId) then
  36.         senderId = tostring(senderId)
  37.  
  38.         if (protocol) then
  39.             print(senderId, " is online.", "Protocol: ", protocol)
  40.         else
  41.             print(senderId, " is online.", "No protocol.")
  42.         end
  43.     else
  44.         if (typeTurtle == "razgruzchik") then
  45.             print("Razgruzchikov net v seti.")
  46.         else
  47.             print("Pogruzchikov net v seti.")
  48.         end
  49.     end
  50. end
  51.  
  52. print("Wi-fi modem side? (back/top/left/right/bottom)")
  53. modemSide = read()
  54.  
  55. rednet.open(modemSide)
  56.  
  57. if (rednet.isOpen(modemSide)) then
  58.     print("[OK] Wi-fi activated")
  59.  
  60.     rednet.broadcast("Who is online?", "loaders")
  61.  
  62.     senderId, message, protocol = rednet.receive("LoadersOnlineResult",5)
  63.     getResult(senderId, protocol, "pogruzchik")
  64.  
  65.     rednet.broadcast("Who is online?", "unloaders")
  66.  
  67.     senderId, message, protocol = rednet.receive("unLoadersOnlineResult",5)
  68.  
  69.     getResult(senderId, protocol, "razgruzchik")
  70.    
  71.     doAction("showMenu")
  72.    
  73. else
  74.     print("Wi-fi activation error. Maybe wrong side?")
  75.     return false
  76. end
  77.  
Add Comment
Please, Sign In to add comment