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

Move code to main(), use configparser

parent f7cb5c41
Loading
Loading
Loading
Loading
+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
@@ -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()
+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():
@@ -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)
+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)
@@ -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)
@@ -49,7 +57,6 @@ while True:

        print(topic, messagedata)

#fade out
def endMission():
    pg.mixer.Channel(0).fadeout(5)
    pass

if __name__ == "__main__":
    main()