Skip to content
Snippets Groups Projects
Commit af042c53 authored by nicolas.albanesi's avatar nicolas.albanesi
Browse files

moving text working when the hepialight is not broken

parent 29296157
No related branches found
No related tags found
1 merge request!1merge Nico
id = [0,0] id = [0,0]
matsize = [0, 0]
def display_id(): def display_id():
afficher_texte("{}, {}".format(id[0], id[1]), speed=0.01) afficher_texte("{}, {}".format(id[0], id[1]), speed=0.01)
...@@ -24,16 +25,23 @@ def send_passthrough(msg, x, y): ...@@ -24,16 +25,23 @@ def send_passthrough(msg, x, y):
def send_xy(x, y, msg): def send_xy(x, y, msg):
send_passthrough(msg, x, y) send_passthrough(msg, x, y)
def send_text_xy(x, y, text, color=ROUGE, speed=0.1):
send_xy(x, y, "TEXT;{};{};{}".format(color, speed, text))
def send_moving_xy(x, y, text, color=ROUGE, speed=0.1):
send_xy(x, y, "MOVING;{};{};{}".format(color, speed, text))
def check_presence(d): def check_presence(d):
envoyer_msg(d, "PING") envoyer_msg(d, "PING")
time.sleep(0.05)
ret = recevoir_msg(d)
print("checking pres for {} : {}".format(d, ret)) for x in range(10):
time.sleep(0.1)
ret = recevoir_msg(d)
if ret == b"": return False if ret == b"PONG": return True
return True return False
def update_id(new_id): def update_id(new_id):
...@@ -52,6 +60,8 @@ def update_id(new_id): ...@@ -52,6 +60,8 @@ def update_id(new_id):
def handle_receive(msg, d): def handle_receive(msg, d):
print("Received from {} : {}".format(d, msg))
if msg.startswith("SET_ID"): if msg.startswith("SET_ID"):
tmp_id = msg[7:].split(",") tmp_id = msg[7:].split(",")
update_id(tmp_id) update_id(tmp_id)
...@@ -63,9 +73,9 @@ def handle_receive(msg, d): ...@@ -63,9 +73,9 @@ def handle_receive(msg, d):
display_id() display_id()
elif msg.startswith("PT;"): elif msg.startswith("PT;"):
print(msg)
msgs = msg.split(";") msgs = msg.split(";")
m = msgs[2] m = msgs[2:]
m = ";".join(m)
x, y = msgs[1].split(",") x, y = msgs[1].split(",")
x = int(x) x = int(x)
...@@ -77,12 +87,33 @@ def handle_receive(msg, d): ...@@ -77,12 +87,33 @@ def handle_receive(msg, d):
send_passthrough(m, x, y) send_passthrough(m, x, y)
elif msg.startswith("MATSIZE"):
x, y = msg.split(":")[-1].split(",")
print("Matsize : {} {}".format(x, y))
matsize = [int(x), int(y)]
elif msg.startswith("TEXT"):
msgs = msg.split(";")
color = int(msgs[1])
speed = float(msgs[2])
afficher_texte(msgs[3], color, speed)
elif msg.startswith("MOVING"):
msgs = msg.split(";")
color = int(msgs[1])
speed = float(msgs[2])
text = msgs[3]
time.sleep(speed * 11)
send_moving_xy(id[0] - 1, id[1], text, color=color, speed=speed)
afficher_texte(text, color, speed)
# Main
# send_text_xy(1,0,text,speed=speed);time.sleep(speed*13);afficher_texte(text,speed=speed)
# Main
afficher_texte("Ready", VERT, speed=0.01) afficher_texte("Ready", VERT, speed=0.01)
while True: while True:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment