Commit 04e86098 authored by Tom Pillot's avatar Tom Pillot
Browse files

Stop broadcasting start message after MAX_START_SENT message are sent

parent 21e8d12a
...@@ -11,6 +11,7 @@ class ScoreWindow(ScoreWindowUi): ...@@ -11,6 +11,7 @@ class ScoreWindow(ScoreWindowUi):
SEND_TIME = 500 SEND_TIME = 500
WEBCAM_REFRESH_TIME = 50 WEBCAM_REFRESH_TIME = 50
PORT = 42563 PORT = 42563
MAX_START_SENT = 5
def __init__(self, teams): def __init__(self, teams):
super().__init__() super().__init__()
...@@ -29,6 +30,7 @@ class ScoreWindow(ScoreWindowUi): ...@@ -29,6 +30,7 @@ class ScoreWindow(ScoreWindowUi):
self.scoreboard_timer = qtc.QTimer() self.scoreboard_timer = qtc.QTimer()
self.webcam_timer = qtc.QTimer() self.webcam_timer = qtc.QTimer()
self.send_timer = qtc.QTimer() self.send_timer = qtc.QTimer()
self.start_sent = 0 # Number of start message sent
self.start_join_button.clicked.connect(self.start_stop_activity) self.start_join_button.clicked.connect(self.start_stop_activity)
...@@ -157,6 +159,7 @@ class ScoreWindow(ScoreWindowUi): ...@@ -157,6 +159,7 @@ class ScoreWindow(ScoreWindowUi):
self.join_started = False self.join_started = False
# Run all Thymios at the same time # Run all Thymios at the same time
self.start_sent = 0
reconnect(self.send_timer.timeout, self.send_start_broadcast) reconnect(self.send_timer.timeout, self.send_start_broadcast)
self.send_timer.start(self.SEND_TIME) self.send_timer.start(self.SEND_TIME)
...@@ -170,13 +173,20 @@ class ScoreWindow(ScoreWindowUi): ...@@ -170,13 +173,20 @@ class ScoreWindow(ScoreWindowUi):
def send_join_broadcast(self): def send_join_broadcast(self):
""" Send a message to all Thymios so they can join the activity """ """ Send a message to all Thymios so they can join the activity """
print("Broadcasting join message ...")
self.socket.sendto("join".encode(), self.socket_dest) self.socket.sendto("join".encode(), self.socket_dest)
self.send_timer.start(self.SEND_TIME) self.send_timer.start(self.SEND_TIME)
def send_start_broadcast(self): def send_start_broadcast(self):
""" Send a message to all Thymios to run at the same time """ """ Send a message to all Thymios to run at the same time. After MAX_START_SENT, stop sending these message """
self.socket.sendto("start".encode(), self.socket_dest) if self.start_sent < self.MAX_START_SENT:
self.send_timer.start(self.SEND_TIME) print("Broadcasting start message ...")
self.start_sent += 1
self.socket.sendto("start".encode(), self.socket_dest)
self.send_timer.start(self.SEND_TIME)
else:
self.start_sent = 0
self.send_timer.stop()
def reconnect(signal, new_handler=None, old_handler=None): def reconnect(signal, new_handler=None, old_handler=None):
......
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