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

modified the discovery method

parent 52749dbb
No related branches found
No related tags found
1 merge request!1merge Nico
id = [0,0] id = [0,0]
matsize = [0, 0] matsize = [0, 0]
# Display and images functions
def color16_to_32(color): def color16_to_32(color):
color = int(color) color = int(color)
r = ((color >> 11) & 0x1F) * 2**3 r = ((color >> 11) & 0x1F) * 2**3
...@@ -27,6 +29,7 @@ def display_id(): ...@@ -27,6 +29,7 @@ def display_id():
def msg_to_str(msg): def msg_to_str(msg):
return str(msg)[2:-1] return str(msg)[2:-1]
# Used by the send_xy functions
def send_passthrough_str(msg, x, y): def send_passthrough_str(msg, x, y):
x = int(x) x = int(x)
y = int(y) y = int(y)
...@@ -42,6 +45,7 @@ def send_passthrough_str(msg, x, y): ...@@ -42,6 +45,7 @@ def send_passthrough_str(msg, x, y):
envoyer_msg(d, "PT;{},{};{}".format(x, y, msg)) envoyer_msg(d, "PT;{},{};{}".format(x, y, msg))
# Not meant to be used by the user
def send_passthrough_bytes(msg, x, y): def send_passthrough_bytes(msg, x, y):
x = int(x) x = int(x)
y = int(y) y = int(y)
...@@ -57,6 +61,7 @@ def send_passthrough_bytes(msg, x, y): ...@@ -57,6 +61,7 @@ def send_passthrough_bytes(msg, x, y):
envoyer_msg(d, msg) envoyer_msg(d, msg)
# Send commands to a specific matrix
def send_xy(x, y, msg): def send_xy(x, y, msg):
send_passthrough_str(msg, x, y) send_passthrough_str(msg, x, y)
...@@ -67,6 +72,7 @@ def send_moving_xy(x, y, text, color=ROUGE, speed=0.1): ...@@ -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)) send_xy(x, y, "MOVING;{};{};{}".format(color, speed, text))
# Check if there is a connected matrix in the d direction
def check_presence(d): def check_presence(d):
envoyer_msg(d, "PING") envoyer_msg(d, "PING")
...@@ -78,13 +84,18 @@ def check_presence(d): ...@@ -78,13 +84,18 @@ def check_presence(d):
return False return False
# Update the ID of the current matrix, and update the id of the neighbours
def update_id(new_id): def update_id(new_id):
global id global id
id[0] = int(new_id[0]) id[0] = int(new_id[0])
id[1] = int(new_id[1]) 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])) envoyer_msg(E, "SET_ID:{},{}".format(id[0] + 1, id[1]))
if not check_presence(N) and not check_presence(E): if not check_presence(N) and not check_presence(E):
...@@ -93,6 +104,8 @@ def update_id(new_id): ...@@ -93,6 +104,8 @@ def update_id(new_id):
display_id() display_id()
# Handle the commands received via UART
def handle_receive(msg, msg_bytes, d): def handle_receive(msg, msg_bytes, d):
print("Received from {} : {}".format(d, msg)) print("Received from {} : {}".format(d, msg))
...@@ -149,8 +162,8 @@ def handle_receive(msg, msg_bytes, d): ...@@ -149,8 +162,8 @@ def handle_receive(msg, msg_bytes, d):
img = data_to_color16(msg_bytes[6:]) img = data_to_color16(msg_bytes[6:])
disp_img_data(img) 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 # Main
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment