Commit e5687a91 authored by Aljaž Srebrnič's avatar Aljaž Srebrnič

Move code to main(), use configparser

parent f7cb5c41
#!/usr/bin/env python3
import sys
from time import sleep
from random import randint
import configparser
import zmq
import spidev
......@@ -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)
......@@ -59,3 +60,7 @@ def main():
light_flame()
else:
print("Unhandled message")
if __name__ == "__main__":
main()
#!/usr/bin/env python3
import zmq
import sys
import subprocess
import configparser
def prime_stages():
......@@ -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)
......
#!/usr/bin/env python3
import pygame as pg
import time
from threading import Timer
import zmq
import sys
import configparser
pg.mixer.init()
pg.init(44100, size=-16, channels=2, buffer=4096)
pg.mixer.set_num_channels(3) # default is 8
#carico i file audio
lancio = pg.mixer.Sound('sounds/lancio.wav')
stageOne = pg.mixer.Sound('sounds/stageOne.wav')
stageTwo = pg.mixer.Sound('sounds/stageTwo.wav')
# fade out
def endMission():
pg.mixer.Channel(0).fadeout(5)
pass
#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)
def main():
config = configparser.ConfigParser({'host': '10.10.10.1', 'port': '5556'})
config.read('config.cfg')
# Socket to talk to server
context = zmq.Context()
socket = context.socket(zmq.SUB)
port = config['port']
host = config['host']
print("Connecting to coordinator...")
socket.connect(f"tcp://localhost:{port}")
pg.mixer.init()
pg.init(44100, size=-16, channels=2, buffer=4096)
pg.mixer.set_num_channels(3) # default is 8
topicfilter = "events"
socket.setsockopt(zmq.SUBSCRIBE, topicfilter)
# carico i file audio
lancio = pg.mixer.Sound('sounds/lancio.wav')
stageOne = pg.mixer.Sound('sounds/stageOne.wav')
stageTwo = pg.mixer.Sound('sounds/stageTwo.wav')
while True:
string = socket.recv()
topic, messagedata = string.split()
# tempo di fine suono dopo secondo modulo
t = Timer(30.0, endMission)
if messagedata == "pre_launch":
pg.mixer.Channel(0).play(lancio)
elif messagedata == "stage_1_separation":
pg.mixer.Channel(1).play(stageOne)
elif messagedata == "stage_2_separation":
pg.mixer.Channel(2).play(stageTwo)
t.start()
else:
print("Unhandled message")
# Socket to talk to server
context = zmq.Context()
socket = context.socket(zmq.SUB)
print(topic, messagedata)
print("Connecting to coordinator...")
socket.connect(f"tcp://{host}:{port}")
#fade out
def endMission():
pg.mixer.Channel(0).fadeout(5)
pass
topicfilter = "events"
socket.setsockopt(zmq.SUBSCRIBE, topicfilter)
while True:
string = socket.recv()
topic, messagedata = string.split()
if messagedata == "pre_launch":
pg.mixer.Channel(0).play(lancio)
elif messagedata == "stage_1_separation":
pg.mixer.Channel(1).play(stageOne)
elif messagedata == "stage_2_separation":
pg.mixer.Channel(2).play(stageTwo)
t.start()
else:
print("Unhandled message")
print(topic, messagedata)
if __name__ == "__main__":
main()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment