Advertisement
Chaos_Cash

Printer Control Program

Aug 27th, 2024 (edited)
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.21 KB | None | 0 0
  1. function startup()
  2. rednet.open("top")
  3.  
  4. file = fs.open("printerStatus","r")
  5. printerStatus = file.readLine()
  6. file.close()
  7.  
  8. file = fs.open("actionCount","r")
  9. actionCount = file.readLine()
  10. file.close()
  11.  
  12. rednet.send(928,{["action"]="sendingInfo",["infoType"]="printerStatus",["info"]=printerStatus})
  13. rednet.send(928,{["action"]="sendingInfo",["infoType"]="actionCount",["info"]=actionCount})
  14.  
  15. if printerStatus ~= "moving" and printerStatus ~= "stopped" and (not fs.exists("stop")) then
  16. multishell.launch({},"printerController")
  17. end
  18. end
  19.  
  20.  
  21.  
  22. function main()
  23.  
  24. while true do
  25. info1,info2,info3,info4 = os.pullEvent()
  26.  
  27. if info1 == "rednet_message" and info2 == 928 then
  28.  
  29. if info3 == "heartbeat" then
  30. rednet.send(928,"heartbeat")
  31.  
  32.  
  33. file = fs.open("printerStatus","r")
  34. printerStatus = file.readLine()
  35. file.close()
  36.  
  37. file = fs.open("actionCount","r")
  38. actionCount = file.readLine()
  39. file.close()
  40.  
  41. rednet.send(928,{["action"]="sendingInfo",["infoType"]="printerStatus",["info"]=printerStatus})
  42. rednet.send(928,{["action"]="sendingInfo",["infoType"]="actionCount",["info"]=actionCount})
  43. end
  44.  
  45.  
  46. if info3 == "stop" then
  47. file = fs.open("stop","w")
  48. file.flush()
  49. file.close()
  50. end
  51.  
  52.  
  53. if info3 == "start" and (printerStatus == "stopped" or printerStatus == "standby") then
  54. if fs.exists("stop") then
  55. fs.delete("stop")
  56. end
  57. multishell.launch({},"printerController")
  58. end
  59.  
  60.  
  61. if type(info3) == "number" then
  62. file = fs.open("actionCount","w")
  63. file.write(info3)
  64. file.flush()
  65. file.close()
  66. end
  67.  
  68.  
  69. if info3 == "clear" then
  70. shell.run("clear")
  71. end
  72.  
  73.  
  74. if info3 == "turtleTurn" then
  75. shell.run("turtleTurn")
  76. end
  77.  
  78. if info3 == "turtleForward" then
  79. shell.run("turtleForward")
  80. end
  81.  
  82.  
  83. if info3 == "turtleUp" then
  84. shell.run("turtleUp")
  85. end
  86.  
  87. if info3 == "machineForward" then
  88. multishell.launch({},"machineForward")
  89. end
  90.  
  91. if info3 == "refuel" then
  92. multishell.launch({},"turtleRefuel")
  93. end
  94.  
  95. if info3 == "print" then
  96. multishell.launch({},"printer")
  97. end
  98.  
  99. end
  100.  
  101.  
  102. end
  103.  
  104. end
  105.  
  106.  
  107. startup()
  108. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement