bigtwisty

SigNet

Apr 28th, 2013
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. --signet
  2. --version 1.0a
  3.  
  4. local function version()
  5. return "1.0a"
  6. end
  7.  
  8. local sigAvailable = tonumber("8000",16)
  9. local sigAcknowledge = tonumber("4000",16)
  10. local sigFilter = tonumber("2FFF",16)
  11. local sides = {"top", "bottom", "left", "right", "front", "back"}
  12.  
  13. -- returns true if there is a valid signal coming in on side
  14. local function available(side)
  15. return colors.test(redstone.getBundledInput(side), sigAvailable)
  16. end
  17.  
  18. -- returns true if a tx'd sig has been acknowldged
  19. local function acknowledged(side)
  20. return colors.test(redstone.getBundledInput(side), sigAcknowledge)
  21. end
  22.  
  23. -- returns the first side with a valid signal
  24. local function scan()
  25. for side in sides do
  26. if available(side) then
  27. return side
  28. end
  29. end
  30. return nil
  31. end
  32.  
  33. -- removes overhead bits from the signal coming in on side
  34. local function getSig(side)
  35. if not available(side) then
  36. return nil
  37. end
  38. return bit.band(redstone.getBundledInput(side), sigFilter)
  39. end
  40.  
  41. function rx(side)
  42. if not available(side) then
  43. return nil
  44. end
  45. sig = getSig(side)
  46. redstone.setBundledOutput(side, sigAcknowledge)
  47. while available(side) do
  48. os.sleep(0.05)
  49. end
  50. redstone.setBundledOutput(side, 0)
  51. return sig
  52. end
  53.  
  54. function tx(side, sig)
  55. redstone.setBundledOutput(side, sig + sigAvailable)
  56. while not colors.test(redstone.getBundled
  57. redstone.setBundledOutput(side, 0)
  58. signal.waitWhile(side, signal.commandReceived)
  59. end
Advertisement
Add Comment
Please, Sign In to add comment