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

Tried to add some communication between the esp and the hepialight

parent af042c53
Branches
No related tags found
1 merge request!1merge Nico
id = [0,0]
matsize = [0, 0]
def color16_to_32(color):
color = int(color)
r = ((color >> 11) & 0xFF) * 2**3
g = ((color >> 5) & 0xFF) * 2**2
b = (color & 0xFF) * 2**3
return r << 16 | g << 8 | b
def disp_img_data(data):
for i in range(NBR_LIGNES):
for j in range(NBR_COLONNES):
allumer_led(i, j, data[i * NBR_LIGNES + j])
def data_to_color16(data):
d_color16 = []
for i in range(0, len(data), 2):
d_color16.append(data[i] << 8 | data[i+1])
return list(map(color16_to_32, d_color16))
def display_id():
afficher_texte("{}, {}".format(id[0], id[1]), speed=0.01)
......@@ -53,12 +73,12 @@ def update_id(new_id):
envoyer_msg(E, "SET_ID:{},{}".format(id[0] + 1, id[1]))
if not check_presence(N) and not check_presence(E):
send_xy(0, 0, "MATSIZE:{},{}".format(id[0], id[1]))
send_xy(0, 0, "MATSIZE;{},{}".format(id[0], id[1]))
display_id()
def handle_receive(msg, d):
def handle_receive(msg, msg_bytes, d):
print("Received from {} : {}".format(d, msg))
......@@ -82,13 +102,14 @@ def handle_receive(msg, d):
y = int(y)
if x == id[0] and y == id[1]:
handle_receive(m, d)
handle_receive(m, msg_bytes[7:], d)
return
print("sending passthrough to {},{}: {}".format(x,y,m))
send_passthrough(m, x, y)
elif msg.startswith("MATSIZE"):
x, y = msg.split(":")[-1].split(",")
x, y = msg.split(";")[-1].split(",")
print("Matsize : {} {}".format(x, y))
matsize = [int(x), int(y)]
......@@ -108,6 +129,10 @@ def handle_receive(msg, d):
send_moving_xy(id[0] - 1, id[1], text, color=color, speed=speed)
afficher_texte(text, color, speed)
elif msg.startswith("IMAGE"):
print("IMAGE LEN : {}".format(len(msg_bytes[6:])))
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)
......@@ -119,9 +144,9 @@ afficher_texte("Ready", VERT, speed=0.01)
while True:
for d in [N, S, E, O]:
msg = recevoir_msg(d)
msg_bytes = recevoir_msg(d)
if msg == b"": continue
if msg_bytes == b"": continue
msg = msg_to_str(msg)
handle_receive(msg, d)
msg = msg_to_str(msg_bytes)
handle_receive(msg, msg_bytes, d)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment