From 08b22fcf65ede1e8f4a80baaee46c5b3e05a1449 Mon Sep 17 00:00:00 2001 From: "nicolas.albanesi" <nicolas.albanesi@etu.hesge.ch> Date: Thu, 29 Jun 2023 15:17:21 +0200 Subject: [PATCH] modified the discovery method --- hepialight/main.py | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/hepialight/main.py b/hepialight/main.py index b5274daf..4384b2ff 100644 --- a/hepialight/main.py +++ b/hepialight/main.py @@ -1,6 +1,8 @@ id = [0,0] matsize = [0, 0] + +# Display and images functions def color16_to_32(color): color = int(color) r = ((color >> 11) & 0x1F) * 2**3 @@ -27,6 +29,7 @@ def display_id(): def msg_to_str(msg): return str(msg)[2:-1] +# Used by the send_xy functions def send_passthrough_str(msg, x, y): x = int(x) y = int(y) @@ -42,6 +45,7 @@ def send_passthrough_str(msg, x, y): envoyer_msg(d, "PT;{},{};{}".format(x, y, msg)) +# Not meant to be used by the user def send_passthrough_bytes(msg, x, y): x = int(x) y = int(y) @@ -57,6 +61,7 @@ def send_passthrough_bytes(msg, x, y): envoyer_msg(d, msg) +# Send commands to a specific matrix def send_xy(x, y, msg): send_passthrough_str(msg, x, y) @@ -67,6 +72,7 @@ def send_moving_xy(x, y, text, color=ROUGE, speed=0.1): send_xy(x, y, "MOVING;{};{};{}".format(color, speed, text)) +# Check if there is a connected matrix in the d direction def check_presence(d): envoyer_msg(d, "PING") @@ -78,13 +84,18 @@ def check_presence(d): return False - +# Update the ID of the current matrix, and update the id of the neighbours def update_id(new_id): global id id[0] = int(new_id[0]) id[1] = int(new_id[1]) - envoyer_msg(N, "SET_ID:{},{}".format(id[0], id[1] + 1)) + + # The matrices which are in the x = 0 pos, update the id North and East. + # The others only broadcast East. + if (id[0] == 0): + envoyer_msg(N, "SET_ID:{},{}".format(id[0], id[1] + 1)) + envoyer_msg(E, "SET_ID:{},{}".format(id[0] + 1, id[1])) if not check_presence(N) and not check_presence(E): @@ -93,6 +104,8 @@ def update_id(new_id): display_id() + +# Handle the commands received via UART def handle_receive(msg, msg_bytes, d): print("Received from {} : {}".format(d, msg)) @@ -149,8 +162,8 @@ def handle_receive(msg, msg_bytes, d): img = data_to_color16(msg_bytes[6:]) disp_img_data(img) -# send_text_xy(1,0,text,speed=speed);time.sleep(speed*13);afficher_texte(text,speed=speed) - + elif msg == "OK": + update_id(id) # Main -- GitLab