From 37b1b75d5f7d2d760823ea8e59dff4c599603900 Mon Sep 17 00:00:00 2001 From: Samuel Date: Wed, 19 Mar 2025 11:57:26 +0100 Subject: [PATCH] =?UTF-8?q?Ajout=20de=20la=20communicatio=20vers=20la=20de?= =?UTF-8?q?tection=20de=20l'adversaire.=20Fonction=20d=C3=A9mo=20uniquemen?= =?UTF-8?q?t=20pour=20l'instant?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Cerveau/Cerveau.ino | 11 +++++++++++ Cerveau/Communication_detection_adversaire.h | 12 ++++++++++++ Cerveau/Communication_detection_adversaire.ino | 18 ++++++++++++++++++ Cerveau/I2C_Master_lib.ino | 4 +++- 4 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 Cerveau/Communication_detection_adversaire.h create mode 100644 Cerveau/Communication_detection_adversaire.ino diff --git a/Cerveau/Cerveau.ino b/Cerveau/Cerveau.ino index 0ffd0fb..b9ac582 100644 --- a/Cerveau/Cerveau.ino +++ b/Cerveau/Cerveau.ino @@ -4,6 +4,7 @@ #include #include "Communication_chassis.h" +#include "Communication_detection_adversaire.h" #include "ServerWeb.h" @@ -107,6 +108,16 @@ void setup() { //} // MemPosition_X = 800; // MemPosition_Y = 800; + struct detect_adv_reception_t detect_adv_reception; + + while(1){ + Detect_adv_lire(&detect_adv_reception); + char chaine[40]; + sprintf(chaine, "Distance: %d cm\n Distance: %d cm\n", detect_adv_reception.distance_cm[0], + detect_adv_reception.distance_cm[11]); + affiche_msg("Scan_Detect_adversaire", chaine); + } + affichage_standard_init(); //M5.Lcd.setCursor(10, 200);M5.Lcd.print("cmd :"); diff --git a/Cerveau/Communication_detection_adversaire.h b/Cerveau/Communication_detection_adversaire.h new file mode 100644 index 0000000..2be81b1 --- /dev/null +++ b/Cerveau/Communication_detection_adversaire.h @@ -0,0 +1,12 @@ +#ifndef DETEC_ADV_H +#define DETEC_ADV_H + +#define I2C_SLAVE_detect_adv 0x18 + +struct detect_adv_reception_t { + unsigned char distance_cm[12]; +}; + +void Detect_adv_lire(struct detect_adv_reception_t * detect_adv_reception); + +#endif diff --git a/Cerveau/Communication_detection_adversaire.ino b/Cerveau/Communication_detection_adversaire.ino new file mode 100644 index 0000000..baa86b4 --- /dev/null +++ b/Cerveau/Communication_detection_adversaire.ino @@ -0,0 +1,18 @@ +//#include "Chassis.h" +#include +#include + + +/// @brief Lit les capteurs VL53L1X +void Detect_adv_lire(struct detect_adv_reception_t * detect_adv_reception){ + unsigned char tampon2[14]; + //(Adresse I2c, Adresse dans le registre, tampon, longueur de donnée) + error = I2C_lire_registre(I2C_SLAVE_detect_adv, 0, detect_adv_reception->distance_cm, 12); + if (error !=0){ + affiche_erreur("Scan_Detect_adversaire", "Erreur I2C"); + while(1); + }else{ + Serial.println("I2C OK"); + + } +} diff --git a/Cerveau/I2C_Master_lib.ino b/Cerveau/I2C_Master_lib.ino index 44654a2..7662822 100644 --- a/Cerveau/I2C_Master_lib.ino +++ b/Cerveau/I2C_Master_lib.ino @@ -26,7 +26,9 @@ uint8_t I2C_lire_registre(int adresse_i2c, uint adresse_registre, unsigned char WIRE.requestFrom(adresse_i2c, taille_donnees + 1); // ceci contient l'adresse - Wire.readBytes(&temp, 1); + if(adresse_i2c == I2C_SLAVE_chassi){ + Wire.readBytes(&temp, 1); + } // Et ceci les données Wire.readBytes(donnees_recues, taille_donnees); return status;