From 502999b159603ae423e282f45a7be589091bced0 Mon Sep 17 00:00:00 2001 From: Gamenight77 Date: Wed, 28 May 2025 09:26:09 +0200 Subject: [PATCH] Refactor LED handling in fpga_wifi_led module and remove obsolete readSerial.py script --- .../leds_commands/src/verilog/fpga_wifi_led.v | 10 ++++--- .../leds_commands/tests/pyhton/connectESP.py | 28 +++++++++++++++++ .../leds_commands/tests/pyhton/readSerial.py | 30 ------------------- 3 files changed, 34 insertions(+), 34 deletions(-) create mode 100644 Semaine_7/ESP32/leds_commands/tests/pyhton/connectESP.py delete mode 100644 Semaine_7/ESP32/leds_commands/tests/pyhton/readSerial.py diff --git a/Semaine_7/ESP32/leds_commands/src/verilog/fpga_wifi_led.v b/Semaine_7/ESP32/leds_commands/src/verilog/fpga_wifi_led.v index c9eb27c..cab7c11 100644 --- a/Semaine_7/ESP32/leds_commands/src/verilog/fpga_wifi_led.v +++ b/Semaine_7/ESP32/leds_commands/src/verilog/fpga_wifi_led.v @@ -22,7 +22,7 @@ module fpga_wifi_led ( wire tx_fifo_full; // === SIGNAUX INTERNES === - reg [5:0] leds_reg; + reg [3:0] leds_reg; reg [1:0] state; reg [7:0] received_byte; @@ -59,11 +59,13 @@ module fpga_wifi_led ( ); // === ASSIGNATION DES LEDS === - assign o_leds = ~leds_reg; + assign o_leds [3:0] = ~leds_reg; + assign o_leds[5] = o_tx; + assign o_leds[4] = i_rx; // === INITIALISATION === initial begin - leds_reg = 6'b000000; + leds_reg = 4'b0000; state = IDLE; rx_rd_en = 0; tx_wr_en = 0; @@ -110,7 +112,7 @@ module fpga_wifi_led ( state <= SEND_RESPONSE; end else begin // Commande non reconnue, éteindre toutes les LEDs - leds_reg <= 6'b000000; + leds_reg[2:0] <= 3'b111; state <= IDLE; end end diff --git a/Semaine_7/ESP32/leds_commands/tests/pyhton/connectESP.py b/Semaine_7/ESP32/leds_commands/tests/pyhton/connectESP.py new file mode 100644 index 0000000..f426200 --- /dev/null +++ b/Semaine_7/ESP32/leds_commands/tests/pyhton/connectESP.py @@ -0,0 +1,28 @@ +import socket +import time + +# Remplace cette IP par celle affichée par l'ESP32 dans le terminal série +ESP32_IP = "192.168.1.105" +ESP32_PORT = 1234 + +def send_bytes(commands): + try: + with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: + print(f"Connexion a {ESP32_IP}:{ESP32_PORT}...") + s.connect((ESP32_IP, ESP32_PORT)) + print("Connecté.") + + for cmd in commands: + if isinstance(cmd, str): + cmd = int(cmd, 16) # Exemple : "0x01" + print(f"Envoi : 0x{cmd:02X}") + s.send(bytes([cmd])) + time.sleep(0.1) # Petite pause pour laisser respirer le FPGA + + print("Tous les octets ont été envoyés.") + except Exception as e: + print("Erreur :", e) + +# Exemple d'envoi +commands = [0x02] # Tu peux aussi faire ["0x01", "0x96", "0xA4"] +send_bytes(commands) diff --git a/Semaine_7/ESP32/leds_commands/tests/pyhton/readSerial.py b/Semaine_7/ESP32/leds_commands/tests/pyhton/readSerial.py deleted file mode 100644 index 8851635..0000000 --- a/Semaine_7/ESP32/leds_commands/tests/pyhton/readSerial.py +++ /dev/null @@ -1,30 +0,0 @@ -import serial -import time - -# Configuration du port série -ser = serial.Serial( - port='/dev/ttyUSB0', # Remplace par ton port (ex : COM3 sous Windows) - baudrate=115200, - timeout=1 # En secondes -) - -print("Lecture du port série... (Ctrl+C pour quitter)") - -try: - while True: - # Lire 2 octets - data = ser.read(2) - - if len(data) == 2: - temperature = data[0] - humidite = data[1] - print(f"Température: {temperature}°C, Humidité: {humidite}%") - else: - print("Pas assez de données reçues.") - - time.sleep(1) - -except KeyboardInterrupt: - print("\nArrêt du script.") -finally: - ser.close()