Loading lighting.py +12 −7 Original line number Diff line number Diff line #!/usr/bin/env python3 import sys from time import sleep from random import randint import configparser import zmq import spidev Loading @@ -28,22 +28,23 @@ def light_flame(): spi.open(1, 0) while True: ws2812.write2812(spi, [get_color()]) ws2812.write2812(spi, [get_color() * 4]) sleep(0.2) def main(): port = "5556" if len(sys.argv) > 1: port = sys.argv[1] int(port) config = configparser.ConfigParser({'host': '10.10.10.1', 'port': '5556'}) config.read('config.cfg') port = config['port'] host = config['host'] # Socket to talk to server context = zmq.Context() socket = context.socket(zmq.SUB) print("Connecting to coordinator...") socket.connect(f"tcp://localhost:{port}") socket.connect(f"tcp://{host}:{port}") topicfilter = "events" socket.setsockopt(zmq.SUBSCRIBE, topicfilter) Loading @@ -59,3 +60,7 @@ def main(): light_flame() else: print("Unhandled message") if __name__ == "__main__": main() servo.py +7 −7 Original line number Diff line number Diff line #!/usr/bin/env python3 import zmq import sys import subprocess import configparser def prime_stages(): Loading @@ -20,17 +19,18 @@ def separate_stage_two(): def main(): port = "5556" if len(sys.argv) > 1: port = sys.argv[1] int(port) config = configparser.ConfigParser({'host': '10.10.10.1', 'port': '5556'}) config.read('config.cfg') port = config['port'] host = config['host'] # Socket to talk to server context = zmq.Context() socket = context.socket(zmq.SUB) print("Connecting to coordinator...") socket.connect(f"tcp://localhost:{port}") socket.connect(f"tcp://{host}:{port}") topicfilter = "events" socket.setsockopt(zmq.SUBSCRIBE, topicfilter) Loading sound.py +46 −39 Original line number Diff line number Diff line #!/usr/bin/env python3 import pygame as pg import time from threading import Timer import zmq import sys import configparser # fade out def endMission(): pg.mixer.Channel(0).fadeout(5) pass def main(): config = configparser.ConfigParser({'host': '10.10.10.1', 'port': '5556'}) config.read('config.cfg') port = config['port'] host = config['host'] pg.mixer.init() pg.init(44100, size=-16, channels=2, buffer=4096) Loading @@ -18,17 +31,12 @@ stageTwo = pg.mixer.Sound('sounds/stageTwo.wav') # tempo di fine suono dopo secondo modulo t = Timer(30.0, endMission) port = "5556" if len(sys.argv) > 1: port = sys.argv[1] int(port) # Socket to talk to server context = zmq.Context() socket = context.socket(zmq.SUB) print("Connecting to coordinator...") socket.connect(f"tcp://localhost:{port}") socket.connect(f"tcp://{host}:{port}") topicfilter = "events" socket.setsockopt(zmq.SUBSCRIBE, topicfilter) Loading @@ -49,7 +57,6 @@ while True: print(topic, messagedata) #fade out def endMission(): pg.mixer.Channel(0).fadeout(5) pass if __name__ == "__main__": main() Loading
lighting.py +12 −7 Original line number Diff line number Diff line #!/usr/bin/env python3 import sys from time import sleep from random import randint import configparser import zmq import spidev Loading @@ -28,22 +28,23 @@ def light_flame(): spi.open(1, 0) while True: ws2812.write2812(spi, [get_color()]) ws2812.write2812(spi, [get_color() * 4]) sleep(0.2) def main(): port = "5556" if len(sys.argv) > 1: port = sys.argv[1] int(port) config = configparser.ConfigParser({'host': '10.10.10.1', 'port': '5556'}) config.read('config.cfg') port = config['port'] host = config['host'] # Socket to talk to server context = zmq.Context() socket = context.socket(zmq.SUB) print("Connecting to coordinator...") socket.connect(f"tcp://localhost:{port}") socket.connect(f"tcp://{host}:{port}") topicfilter = "events" socket.setsockopt(zmq.SUBSCRIBE, topicfilter) Loading @@ -59,3 +60,7 @@ def main(): light_flame() else: print("Unhandled message") if __name__ == "__main__": main()
servo.py +7 −7 Original line number Diff line number Diff line #!/usr/bin/env python3 import zmq import sys import subprocess import configparser def prime_stages(): Loading @@ -20,17 +19,18 @@ def separate_stage_two(): def main(): port = "5556" if len(sys.argv) > 1: port = sys.argv[1] int(port) config = configparser.ConfigParser({'host': '10.10.10.1', 'port': '5556'}) config.read('config.cfg') port = config['port'] host = config['host'] # Socket to talk to server context = zmq.Context() socket = context.socket(zmq.SUB) print("Connecting to coordinator...") socket.connect(f"tcp://localhost:{port}") socket.connect(f"tcp://{host}:{port}") topicfilter = "events" socket.setsockopt(zmq.SUBSCRIBE, topicfilter) Loading
sound.py +46 −39 Original line number Diff line number Diff line #!/usr/bin/env python3 import pygame as pg import time from threading import Timer import zmq import sys import configparser # fade out def endMission(): pg.mixer.Channel(0).fadeout(5) pass def main(): config = configparser.ConfigParser({'host': '10.10.10.1', 'port': '5556'}) config.read('config.cfg') port = config['port'] host = config['host'] pg.mixer.init() pg.init(44100, size=-16, channels=2, buffer=4096) Loading @@ -18,17 +31,12 @@ stageTwo = pg.mixer.Sound('sounds/stageTwo.wav') # tempo di fine suono dopo secondo modulo t = Timer(30.0, endMission) port = "5556" if len(sys.argv) > 1: port = sys.argv[1] int(port) # Socket to talk to server context = zmq.Context() socket = context.socket(zmq.SUB) print("Connecting to coordinator...") socket.connect(f"tcp://localhost:{port}") socket.connect(f"tcp://{host}:{port}") topicfilter = "events" socket.setsockopt(zmq.SUBSCRIBE, topicfilter) Loading @@ -49,7 +57,6 @@ while True: print(topic, messagedata) #fade out def endMission(): pg.mixer.Channel(0).fadeout(5) pass if __name__ == "__main__": main()