Lecture de la commande d'affichage couleur + tests
This commit is contained in:
parent
a8c4d3ba64
commit
e40f285438
37
Tests.c
37
Tests.c
@ -4,12 +4,13 @@
|
||||
#include "VL53L1X_Fonctions.h"
|
||||
|
||||
void display_menu();
|
||||
void test_couleur_led();
|
||||
|
||||
#define TEST_TIMEOUT_US 10000000
|
||||
|
||||
void Tests(void){
|
||||
int answer_at_least_once=0;
|
||||
uint8_t VL53L1X_device = 0x29;
|
||||
uint8_t VL53L1X_device = 0x31;
|
||||
while(1){
|
||||
int keycode;
|
||||
display_menu();
|
||||
@ -30,6 +31,16 @@ void Tests(void){
|
||||
change_address(&VL53L1X_device, VL53L1X_device + 3);
|
||||
printf("New address: %d\n", VL53L1X_device);
|
||||
break;
|
||||
case 'c':
|
||||
case 'C':
|
||||
printf("Affichage couleur sur LED\n");
|
||||
test_couleur_led();
|
||||
break;
|
||||
case 'd':
|
||||
case 'D':
|
||||
printf("Reset affichage couleur sur LED\n");
|
||||
reset_affichage_led();
|
||||
break;
|
||||
case 'i':
|
||||
case 'I':
|
||||
printf("Initialisation des capteurs\n");
|
||||
@ -37,7 +48,11 @@ void Tests(void){
|
||||
break;
|
||||
case 'j':
|
||||
case 'J':
|
||||
while(continuous_multiple_reading());
|
||||
printf("Lecture continue des capteurs initilisés.\nAppuyer sur une touche pour quitter");
|
||||
do{
|
||||
keycode = getchar_timeout_us(0);
|
||||
continuous_multiple_reading();
|
||||
}while(keycode == PICO_ERROR_TIMEOUT || keycode == 0);
|
||||
break;
|
||||
case 'k':
|
||||
case 'K':
|
||||
@ -65,10 +80,28 @@ void Tests(void){
|
||||
void display_menu(){
|
||||
printf("Select action :\n");
|
||||
printf("A - Change I2C address\n");
|
||||
printf("C - Couleur Led\n");
|
||||
printf("I - Init I2C address\n");
|
||||
printf("J - Lecture distance multiple\n");
|
||||
printf("K - Arc en ciel\n");
|
||||
printf("L - Lecture distance capteur 1\n");
|
||||
printf("O - Offset Calibration\n");
|
||||
printf("R - Read distance\n");
|
||||
}
|
||||
|
||||
/// @brief Force une couleur sur une led qui ne doit pas être effacée par la distance lue par le capteur.
|
||||
/// A utiliser après l'initialisation des catpeurs et avant la lecture continue
|
||||
void test_couleur_led(){
|
||||
unsigned int couleur, led;
|
||||
int scanf1, scanf2;
|
||||
printf("Choississez la led (0 - 11)\n");
|
||||
scanf1 = scanf("%u", &led);
|
||||
printf("Choississez la couleur (0 - 255)\n");
|
||||
scanf2 = scanf("%u", &couleur);
|
||||
if(scanf1 == 1 && scanf2 == 1){
|
||||
printf("Actualisation de la led %d avec la couleur %d\n", led, couleur);
|
||||
affiche_couleur_sur_led(couleur, led);
|
||||
}else{
|
||||
printf("Erreur scanf...\n");
|
||||
}
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
#include "pico/stdlib.h"
|
||||
#include <stdio.h>
|
||||
#include "VL53L1X_api.h"
|
||||
#include "VL53L1X_calibration.h"
|
||||
#include "VL53L1X_Fonctions.h"
|
||||
#include "SelectionCapteur.h"
|
||||
#include "ws2812.h"
|
||||
@ -8,11 +9,18 @@
|
||||
#define DISTANCE_TRES_LOIN_CM 120
|
||||
#define DISTANCE_LOIN_CM 80
|
||||
#define DISTANCE_PROCHE_CM 14
|
||||
#define NB_CAPTEURS 12
|
||||
|
||||
// Stock les valeurs lues des capteurs
|
||||
uint8_t distance_capteur_cm[12];
|
||||
|
||||
uint8_t statu_capteurs[13];
|
||||
enum {
|
||||
MODE_DISTANCE,
|
||||
MODE_MANUEL
|
||||
} mode_led[NB_CAPTEURS];
|
||||
|
||||
void reset_affichage_led(void);
|
||||
|
||||
void initialise_adresses(void){
|
||||
const uint8_t tmp_i2c_adresse = 0x28;
|
||||
@ -25,8 +33,10 @@ void initialise_adresses(void){
|
||||
Selection_capteur_deselect();
|
||||
change_address(&adresse, tmp_i2c_adresse);
|
||||
|
||||
reset_affichage_led();
|
||||
|
||||
// Pour chaque capteur
|
||||
for(uint capteur=1; capteur<=12; capteur++){
|
||||
for(uint capteur=1; capteur<=NB_CAPTEURS; capteur++){
|
||||
// reset du capteur
|
||||
Selection_capteur_select(capteur);
|
||||
sleep_ms(1);
|
||||
@ -62,6 +72,7 @@ void initialise_adresses(void){
|
||||
ws2812_set_buffer_rgb(0, 0x4, 0, capteur-1);
|
||||
}else{
|
||||
ws2812_set_buffer_rgb(0x2, 0x2, 0, capteur-1);
|
||||
mode_led[capteur-1]=MODE_DISTANCE;
|
||||
}
|
||||
|
||||
|
||||
@ -85,6 +96,9 @@ int change_address(uint8_t *device, uint8_t new_i2c_7bits_address){
|
||||
return status;
|
||||
}
|
||||
|
||||
/// @brief Interroge les capteurs les uns après les autres.
|
||||
/// Nécessite que les capteurs soient en mode lecture continue avec VL53L1X_StartRanging(device)
|
||||
/// @return 1
|
||||
int continuous_multiple_reading(){
|
||||
for(uint8_t device=0x31; device<0x31+12; device++){
|
||||
if(statu_capteurs[device-0x31+1]==0){
|
||||
@ -124,27 +138,81 @@ int continuous_multiple_reading(){
|
||||
return 1;
|
||||
}
|
||||
|
||||
int continuous_special_reading(){
|
||||
for(uint8_t device=0x32; device<0x31+12; device+=6){
|
||||
if(statu_capteurs[device-0x31+1]==0){
|
||||
continue;
|
||||
}
|
||||
int status;
|
||||
uint8_t data_ready = 0;
|
||||
uint16_t distance_mm;
|
||||
while(!data_ready){
|
||||
status=VL53L1X_CheckForDataReady(device, &data_ready);
|
||||
if(status){
|
||||
printf("CheckForDataReady KO, error %d, capteur:%x\n", status, device);
|
||||
}
|
||||
}
|
||||
|
||||
status=VL53L1X_GetDistance(device, &distance_mm);
|
||||
if(status){
|
||||
printf("GetDistance KO, error %d, capteur:%x\n", status, device);
|
||||
return 0;
|
||||
}else{
|
||||
printf(">distance%x:%d\n", device, distance_mm);
|
||||
distance_capteur_cm[device-0x31] = distance_mm / 10;
|
||||
}
|
||||
|
||||
status=VL53L1X_ClearInterrupt(device);
|
||||
if(status){
|
||||
printf("ClearInterrupt KO, error %d, capteur:%x\n", status, device);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int lettre = getchar_timeout_us(0);
|
||||
if(lettre != PICO_ERROR_TIMEOUT && lettre != 0){
|
||||
//return 0;
|
||||
}
|
||||
}
|
||||
affiche_distance_sur_led();
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
void affiche_distance_sur_led(){
|
||||
uint8_t distance_cm;
|
||||
uint32_t couleur;
|
||||
for(uint8_t capteur=0; capteur<12; capteur++){
|
||||
distance_cm = distance_capteur_cm[capteur];
|
||||
if(distance_cm == 0 ||distance_cm > DISTANCE_TRES_LOIN_CM){
|
||||
ws2812_set_buffer_rgb(COULEUR_TRES_LOIN, capteur);
|
||||
}else if(distance_cm > DISTANCE_LOIN_CM){
|
||||
ws2812_set_buffer_rgb(COULEUR_LOIN, capteur);
|
||||
}else if(distance_cm > DISTANCE_PROCHE_CM){
|
||||
ws2812_set_buffer_rgb(COULEUR_PROCHE, capteur);
|
||||
}else{
|
||||
ws2812_set_buffer_rgb(COULEUR_TROP_PROCHE, capteur);
|
||||
if(mode_led[capteur] == MODE_DISTANCE){
|
||||
distance_cm = distance_capteur_cm[capteur];
|
||||
if(distance_cm == 0 ||distance_cm > DISTANCE_TRES_LOIN_CM){
|
||||
ws2812_set_buffer_rgb(COULEUR_TRES_LOIN, capteur);
|
||||
}else if(distance_cm > DISTANCE_LOIN_CM){
|
||||
ws2812_set_buffer_rgb(COULEUR_LOIN, capteur);
|
||||
}else if(distance_cm > DISTANCE_PROCHE_CM){
|
||||
ws2812_set_buffer_rgb(COULEUR_PROCHE, capteur);
|
||||
}else{
|
||||
ws2812_set_buffer_rgb(COULEUR_TROP_PROCHE, capteur);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
ws2812_affiche_buffer();
|
||||
}
|
||||
|
||||
void affiche_couleur_sur_led(uint8_t couleur_8bits, uint8_t led){
|
||||
mode_led[led] = MODE_MANUEL;
|
||||
ws2812_set_buffer_8bits(couleur_8bits, led);
|
||||
}
|
||||
|
||||
void reset_affichage_led(){
|
||||
for(uint8_t capteur=0; capteur<12; capteur++){
|
||||
mode_led[capteur] = MODE_DISTANCE;
|
||||
}
|
||||
}
|
||||
|
||||
int calibration(uint8_t device){
|
||||
uint16_t offset;
|
||||
uint16_t x_talk;
|
||||
int status;
|
||||
uint8_t boot_state=0;
|
||||
printf("Calibration...\n");
|
||||
@ -167,6 +235,18 @@ int calibration(uint8_t device){
|
||||
printf("Offset : %d\n", offset);
|
||||
|
||||
}
|
||||
/*
|
||||
// Renvoie x_talk = 0 si la calibration se passe bien car
|
||||
// nous n'avons pas de vitre de protection devant le capteur
|
||||
status = VL53L1X_CalibrateXtalk(device, 1000, &x_talk);
|
||||
if(status != 0){
|
||||
printf("Error while calibrating : %d\n",status);
|
||||
}else{
|
||||
printf("xTalk : %d\n", x_talk);
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -11,11 +11,15 @@
|
||||
|
||||
|
||||
int continuous_multiple_reading(void);
|
||||
int continuous_special_reading(void);
|
||||
void affiche_distance_sur_led(void);
|
||||
void affiche_couleur_sur_led(uint8_t couleur_8bits, uint8_t led);
|
||||
void reset_affichage_led(void);
|
||||
void initialise_adresses(void);
|
||||
int change_address(uint8_t *device, uint8_t new_i2c_7bits_address);
|
||||
int calibration(uint8_t device);
|
||||
int continuous_reading(uint8_t device);
|
||||
|
||||
extern uint8_t distance_capteur_cm[];
|
||||
|
||||
extern uint8_t statu_capteurs[];
|
||||
|
32
main.c
32
main.c
@ -32,6 +32,10 @@ void init_sensors(void);
|
||||
|
||||
|
||||
#define I2C_SLAVE_ADDRESS 0x18
|
||||
#define ADRESSE_RECEPTION_DATA 0x10
|
||||
#define ADRESSE_COULEUR_LED 0x10
|
||||
#define ADRESSE_MASQUE_LED_1 0x11
|
||||
#define ADRESSE_MASQUE_LED_2 0x12
|
||||
|
||||
static const uint I2C_SLAVE_SDA_PIN = I2C1_SDA_PIN;
|
||||
static const uint I2C_SLAVE_SCL_PIN = I2C1_SCL_PIN;
|
||||
@ -102,6 +106,10 @@ static void setup_slave() {
|
||||
void main(void)
|
||||
{
|
||||
int status;
|
||||
uint8_t tampon_commande_led[3];
|
||||
tampon_commande_led[0]=0;
|
||||
tampon_commande_led[1]=0;
|
||||
tampon_commande_led[2]=0;
|
||||
|
||||
uint8_t VL53L1X_device = 0x29;
|
||||
|
||||
@ -121,10 +129,34 @@ void main(void)
|
||||
while(1){
|
||||
// Lecture des capteurs
|
||||
continuous_multiple_reading();
|
||||
//continuous_special_reading();
|
||||
|
||||
// Envoie des valeurs des capteurs
|
||||
for(uint8_t capteur=0; capteur<12; capteur++){
|
||||
context.mem[capteur] = distance_capteur_cm[capteur];
|
||||
}
|
||||
|
||||
// Reception des données à afficher sur les capteurs
|
||||
// Si nous avons reçu une nouvelle commande
|
||||
if(tampon_commande_led[0] != context.mem[0x10] ||
|
||||
tampon_commande_led[1] != context.mem[0x11] ||
|
||||
tampon_commande_led[2] != context.mem[0x12] ){
|
||||
|
||||
tampon_commande_led[0] = context.mem[0x10];
|
||||
tampon_commande_led[1] = context.mem[0x11];
|
||||
tampon_commande_led[2] = context.mem[0x12];
|
||||
|
||||
uint8_t couleur = tampon_commande_led[0];
|
||||
uint16_t masque_led = (tampon_commande_led[1] << 8) | tampon_commande_led[2];
|
||||
|
||||
for(uint8_t led=0; led < 12; led++){
|
||||
if((masque_led >> led) & 0x01){
|
||||
|
||||
ws2812_set_buffer_8bits(couleur, led);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
6
ws2812.c
6
ws2812.c
@ -110,6 +110,12 @@ void ws2812_set_buffer_rgb(uint8_t rouge, uint8_t vert, uint8_t bleu, uint8_t in
|
||||
ws2812_set_buffer(urgb_u32(rouge, vert,bleu), index_led);
|
||||
}
|
||||
|
||||
//Bit 7 6 5 4 3 2 1 0
|
||||
//Data R R R G G G B B
|
||||
void ws2812_set_buffer_8bits(uint8_t couleur, uint8_t index_led){
|
||||
ws2812_set_buffer(urgb_u32(couleur >> 5, (couleur >> 2) & 0x07, couleur & 0x03), index_led);
|
||||
}
|
||||
|
||||
/// @brief Rempli le buffer à envoyer au LED, necessite d'appeler la fonction ws2812_affiche_buffer() ensuite
|
||||
/// @param couleur : couleur en RVB
|
||||
/// @param index_led : index entre 0 et 11
|
||||
|
Loading…
Reference in New Issue
Block a user