2023-03-16 22:27:08 +00:00
|
|
|
#include "i2c_annexe.h"
|
|
|
|
#include "i2c_maitre.h"
|
|
|
|
#include "stdio.h"
|
|
|
|
|
|
|
|
#define ADRESSE_PICO_ANNEXE 0x17
|
2023-04-17 14:36:35 +00:00
|
|
|
#define ADRESSE_DEBUT_W 0x05
|
2023-03-16 22:27:08 +00:00
|
|
|
#define ADRESSE_DEBUT_R 0x0A
|
2023-04-23 13:55:55 +00:00
|
|
|
#define ADRESSE_SCORE 0x09
|
2023-03-16 22:27:08 +00:00
|
|
|
#define ADRESSE_TURBINE_PORTE 0x0A
|
|
|
|
#define ADRESSE_CONTACTEURS 0x0B
|
2023-03-31 18:39:12 +00:00
|
|
|
#define ADRESSE_VL53L1X 0x0C
|
2023-05-13 18:27:44 +00:00
|
|
|
#define ADRESSE_TENSION_BATTERIE 0x18
|
2023-04-17 14:36:35 +00:00
|
|
|
#define ADRESSE_COULEUR 0x05
|
|
|
|
#define ADRESSE_MASQUE_LED_1 0x06
|
|
|
|
#define ADRESSE_MASQUE_LED_2 0x07
|
|
|
|
#define TAILLE_DONNEES_EMISSION 6
|
2023-05-13 18:27:44 +00:00
|
|
|
#define TAILLE_DONNEES_RECEPTION 15
|
2023-03-16 22:27:08 +00:00
|
|
|
|
2023-03-29 19:18:20 +00:00
|
|
|
|
2023-03-16 22:27:08 +00:00
|
|
|
|
|
|
|
uint8_t donnees_emission[TAILLE_DONNEES_EMISSION];
|
|
|
|
uint8_t donnees_reception[TAILLE_DONNEES_RECEPTION];
|
|
|
|
|
2023-03-29 19:18:20 +00:00
|
|
|
uint donnees_a_envoyer=0;
|
|
|
|
|
2023-03-16 22:27:08 +00:00
|
|
|
void i2c_annexe_gestion(){
|
|
|
|
static enum {
|
|
|
|
EMISSION_DONNEES,
|
2023-03-29 19:18:20 +00:00
|
|
|
EMISSION_TEMPO,
|
2023-03-16 22:27:08 +00:00
|
|
|
RECEPTION_DONNEES
|
|
|
|
} etat_i2c_annexe=EMISSION_DONNEES;
|
2023-03-29 19:18:20 +00:00
|
|
|
|
2023-03-16 22:27:08 +00:00
|
|
|
enum i2c_resultat_t retour_i2c;
|
2023-03-29 19:18:20 +00:00
|
|
|
static uint32_t temps;
|
|
|
|
const uint32_t tempo = 1000;
|
2023-03-16 22:27:08 +00:00
|
|
|
|
|
|
|
switch(etat_i2c_annexe){
|
|
|
|
case EMISSION_DONNEES:
|
|
|
|
if(donnees_a_envoyer){
|
|
|
|
retour_i2c = i2c_ecrire_registre_nb(ADRESSE_PICO_ANNEXE, ADRESSE_DEBUT_W, donnees_emission, TAILLE_DONNEES_EMISSION);
|
|
|
|
if(retour_i2c == I2C_SUCCES){
|
2023-03-29 19:18:20 +00:00
|
|
|
etat_i2c_annexe = EMISSION_TEMPO;
|
2023-03-16 22:27:08 +00:00
|
|
|
donnees_a_envoyer=0;
|
2023-03-29 19:18:20 +00:00
|
|
|
temps = time_us_32();
|
2023-03-16 22:27:08 +00:00
|
|
|
}
|
|
|
|
}else{
|
2023-03-29 19:18:20 +00:00
|
|
|
etat_i2c_annexe = EMISSION_TEMPO;
|
|
|
|
temps = time_us_32();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case EMISSION_TEMPO:
|
|
|
|
if(temps + tempo < time_us_32() ){
|
2023-03-16 22:27:08 +00:00
|
|
|
etat_i2c_annexe = RECEPTION_DONNEES;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RECEPTION_DONNEES:
|
|
|
|
retour_i2c = i2c_lire_registre_nb(ADRESSE_PICO_ANNEXE, ADRESSE_DEBUT_R, donnees_reception, TAILLE_DONNEES_RECEPTION);
|
|
|
|
if(retour_i2c == I2C_SUCCES){
|
|
|
|
etat_i2c_annexe = EMISSION_DONNEES;
|
2023-03-29 19:18:20 +00:00
|
|
|
temps = time_us_32();
|
2023-03-16 22:27:08 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2023-04-17 14:36:35 +00:00
|
|
|
void i2c_annexe_couleur_balise(uint8_t couleur, uint16_t masque_led){
|
|
|
|
donnees_emission[ADRESSE_COULEUR - ADRESSE_DEBUT_W] = couleur;
|
|
|
|
donnees_emission[ADRESSE_MASQUE_LED_1 - ADRESSE_DEBUT_W] = (masque_led >> 8) & 0xFF;
|
|
|
|
donnees_emission[ADRESSE_MASQUE_LED_2 - ADRESSE_DEBUT_W] = masque_led & 0xFF;
|
|
|
|
donnees_a_envoyer=1;
|
|
|
|
}
|
|
|
|
|
2023-03-16 22:27:08 +00:00
|
|
|
void i2c_annexe_active_turbine(void){
|
2023-05-13 15:35:27 +00:00
|
|
|
donnees_emission[ADRESSE_TURBINE_PORTE - ADRESSE_DEBUT_W] |= 0x01;
|
|
|
|
donnees_a_envoyer=1;
|
2023-03-16 22:27:08 +00:00
|
|
|
}
|
|
|
|
void i2c_annexe_desactive_turbine(void){
|
|
|
|
donnees_emission[ADRESSE_TURBINE_PORTE - ADRESSE_DEBUT_W] &= 0xFE;
|
|
|
|
donnees_a_envoyer=1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void i2c_annexe_ouvre_porte(void){
|
2023-04-24 19:51:19 +00:00
|
|
|
donnees_emission[ADRESSE_TURBINE_PORTE - ADRESSE_DEBUT_W] &= 0xF9;
|
2023-03-16 22:27:08 +00:00
|
|
|
donnees_a_envoyer=1;
|
|
|
|
}
|
|
|
|
void i2c_annexe_ferme_porte(void){
|
2023-04-24 19:51:19 +00:00
|
|
|
donnees_emission[ADRESSE_TURBINE_PORTE - ADRESSE_DEBUT_W] &= 0xF9;
|
|
|
|
donnees_emission[ADRESSE_TURBINE_PORTE - ADRESSE_DEBUT_W] |= (1 << 1);
|
|
|
|
donnees_a_envoyer=1;
|
|
|
|
}
|
|
|
|
void i2c_annexe_mi_ferme_porte(void){
|
|
|
|
donnees_emission[ADRESSE_TURBINE_PORTE - ADRESSE_DEBUT_W] &= 0xF9;
|
|
|
|
donnees_emission[ADRESSE_TURBINE_PORTE - ADRESSE_DEBUT_W] |= (2 << 1);
|
2023-03-16 22:27:08 +00:00
|
|
|
donnees_a_envoyer=1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void i2c_annexe_active_propulseur(void){
|
2023-04-24 19:51:19 +00:00
|
|
|
donnees_emission[ADRESSE_TURBINE_PORTE - ADRESSE_DEBUT_W] |= 0x08;
|
|
|
|
donnees_a_envoyer=1;
|
2023-03-16 22:27:08 +00:00
|
|
|
}
|
|
|
|
void i2c_annexe_desactive_propulseur(void){
|
2023-04-24 20:06:45 +00:00
|
|
|
donnees_emission[ADRESSE_TURBINE_PORTE - ADRESSE_DEBUT_W] &= 0xF7;
|
2023-03-16 22:27:08 +00:00
|
|
|
donnees_a_envoyer=1;
|
|
|
|
}
|
|
|
|
|
2023-05-01 19:02:08 +00:00
|
|
|
void i2c_annexe_active_deguisement(void){
|
|
|
|
donnees_emission[ADRESSE_TURBINE_PORTE - ADRESSE_DEBUT_W] |= 0x10;
|
|
|
|
donnees_a_envoyer=1;
|
|
|
|
}
|
|
|
|
void i2c_annexe_desactive_deguisement(void){
|
|
|
|
donnees_emission[ADRESSE_TURBINE_PORTE - ADRESSE_DEBUT_W] &= 0xEF;
|
|
|
|
donnees_a_envoyer=1;
|
|
|
|
}
|
|
|
|
|
2023-05-19 22:15:08 +00:00
|
|
|
void i2c_annexe_deplie_bras(void){
|
|
|
|
donnees_emission[ADRESSE_TURBINE_PORTE - ADRESSE_DEBUT_W] |= 0x20;
|
|
|
|
donnees_a_envoyer=1;
|
|
|
|
}
|
|
|
|
void i2c_annexe_plie_bras(void){
|
|
|
|
donnees_emission[ADRESSE_TURBINE_PORTE - ADRESSE_DEBUT_W] &= 0xDF;
|
|
|
|
donnees_a_envoyer=1;
|
|
|
|
}
|
|
|
|
|
2023-04-23 13:55:55 +00:00
|
|
|
void i2c_annexe_envoie_score(uint8_t score){
|
|
|
|
donnees_emission[ADRESSE_SCORE - ADRESSE_DEBUT_W] = score;
|
|
|
|
donnees_a_envoyer=1;
|
|
|
|
}
|
|
|
|
|
2023-03-16 22:27:08 +00:00
|
|
|
uint8_t i2c_annexe_get_contacteur_butee_A(void){
|
|
|
|
return (donnees_reception[ADRESSE_CONTACTEURS - ADRESSE_DEBUT_R] >> 3) & 0x01;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t i2c_annexe_get_contacteur_butee_C(void){
|
|
|
|
return (donnees_reception[ADRESSE_CONTACTEURS - ADRESSE_DEBUT_R] & 0x01);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t i2c_annexe_get_contacteur_longer_A(void){
|
|
|
|
return (donnees_reception[ADRESSE_CONTACTEURS - ADRESSE_DEBUT_R] >> 2) & 0x01;
|
|
|
|
}
|
|
|
|
uint8_t i2c_annexe_get_contacteur_longer_C(void){
|
|
|
|
return (donnees_reception[ADRESSE_CONTACTEURS - ADRESSE_DEBUT_R] >> 1) & 0x01;
|
2023-03-31 18:39:12 +00:00
|
|
|
}
|
|
|
|
|
2023-05-13 18:27:44 +00:00
|
|
|
uint8_t i2c_annexe_get_tension_batterie(void){
|
|
|
|
return donnees_reception[ADRESSE_TENSION_BATTERIE - ADRESSE_DEBUT_R];
|
|
|
|
}
|
|
|
|
|
2023-03-31 18:39:12 +00:00
|
|
|
void i2c_annexe_get_distances(uint8_t *distance_capteur_cm){
|
|
|
|
for (uint8_t capteur = 0; capteur < 12; capteur++){
|
|
|
|
distance_capteur_cm[capteur] = donnees_reception[capteur + ADRESSE_VL53L1X - ADRESSE_DEBUT_R];
|
|
|
|
}
|
2023-03-16 22:27:08 +00:00
|
|
|
}
|