VL53L3 Shield specific functions.

Dependents:   53L3A2_Ranging X_NUCLEO_53L3CX

Committer:
charlesmn
Date:
Fri Oct 16 15:43:08 2020 +0000
Revision:
1:8afec488fa83
Parent:
0:ba15439f45dd
No functional change. Names changed from vL53l1 TO vl53l3

Who changed what in which revision?

UserRevisionLine numberNew contents of line
charlesmn 0:ba15439f45dd 1 #include "NoShield53L3.h"
charlesmn 0:ba15439f45dd 2
charlesmn 0:ba15439f45dd 3 NoShield53L3 *NoShield53L3::_instance = NULL;
charlesmn 0:ba15439f45dd 4
charlesmn 0:ba15439f45dd 5
charlesmn 1:8afec488fa83 6 NoShield53L3 *NoShield53L3::instance(vl53L3_DevI2C *ext_i2c)
charlesmn 0:ba15439f45dd 7 {
charlesmn 0:ba15439f45dd 8 if (_instance == NULL) {
charlesmn 0:ba15439f45dd 9 _instance = new NoShield53L3(ext_i2c);
charlesmn 0:ba15439f45dd 10 } else {
charlesmn 0:ba15439f45dd 11 printf("Failed to create NoShield53l3 instance\n\r\r\n");
charlesmn 0:ba15439f45dd 12 }
charlesmn 0:ba15439f45dd 13 return _instance;
charlesmn 0:ba15439f45dd 14 }
charlesmn 0:ba15439f45dd 15
charlesmn 1:8afec488fa83 16 NoShield53L3 *NoShield53L3::instance(vl53L3_DevI2C *ext_i2c,
charlesmn 0:ba15439f45dd 17 PinName gpio1_centre,
charlesmn 0:ba15439f45dd 18 PinName gpio1_left, PinName gpio1_right)
charlesmn 0:ba15439f45dd 19 {
charlesmn 0:ba15439f45dd 20 if (_instance == NULL) {
charlesmn 0:ba15439f45dd 21 // printf("instance %d z\n",ext_i2c);
charlesmn 0:ba15439f45dd 22 _instance = new NoShield53L3(ext_i2c, gpio1_centre, gpio1_left, gpio1_right);
charlesmn 0:ba15439f45dd 23 } else {
charlesmn 0:ba15439f45dd 24 printf("Failed to create XNucleo53L0A1 instance\n\r");
charlesmn 0:ba15439f45dd 25 }
charlesmn 0:ba15439f45dd 26 return _instance;
charlesmn 0:ba15439f45dd 27 }
charlesmn 0:ba15439f45dd 28
charlesmn 0:ba15439f45dd 29
charlesmn 0:ba15439f45dd 30 // no stmpe1600. Shutdown lijnes controlled from pins passed in
charlesmn 0:ba15439f45dd 31 int NoShield53L3::init_board(PinName shut_centre,
charlesmn 0:ba15439f45dd 32 PinName shut_left, PinName shut_right)
charlesmn 0:ba15439f45dd 33 {
charlesmn 0:ba15439f45dd 34 printf("init_board \n");
charlesmn 0:ba15439f45dd 35 int status, n_dev = 0;
charlesmn 0:ba15439f45dd 36
charlesmn 0:ba15439f45dd 37 // set the shutdown pins to be outputs ( they are inputs on power up)
charlesmn 0:ba15439f45dd 38 DigitalOut sensor1shut(shut_centre);
charlesmn 0:ba15439f45dd 39 DigitalOut sensor2shut(shut_left);
charlesmn 0:ba15439f45dd 40 DigitalOut sensor3shut(shut_right);
charlesmn 0:ba15439f45dd 41
charlesmn 0:ba15439f45dd 42 // On startup or on the shutdown pin going high the VL53l1 devices have a i2c address of 0x52.
charlesmn 0:ba15439f45dd 43 // To initialise then we have to bring up one device at a time This involves raising the shutdown pin for that device,
charlesmn 0:ba15439f45dd 44 // initialising then setting the i2c address to a unique value. Once that is done the shutdown pins don't need to be touched.
charlesmn 0:ba15439f45dd 45
charlesmn 0:ba15439f45dd 46 // set the shutdown pins to low, this will reset the VL53l1
charlesmn 0:ba15439f45dd 47 sensor1shut =0;
charlesmn 0:ba15439f45dd 48 sensor2shut =0;
charlesmn 0:ba15439f45dd 49 sensor3shut =0;
charlesmn 0:ba15439f45dd 50 // select the first VL53l1. It will have i2c address of 0x52. Set the i2c address to
charlesmn 0:ba15439f45dd 51 //NEW_SENSOR_CENTRE_ADDRESS
charlesmn 0:ba15439f45dd 52
charlesmn 0:ba15439f45dd 53 sensor1shut =1;
charlesmn 0:ba15439f45dd 54 printf("InitSensor \n");
charlesmn 0:ba15439f45dd 55 status = sensor_centre->InitSensor(NEW_SENSOR_CENTRE_ADDRESS);
charlesmn 0:ba15439f45dd 56 if (status) {
charlesmn 0:ba15439f45dd 57 delete sensor_centre;
charlesmn 0:ba15439f45dd 58 sensor_centre = NULL;
charlesmn 0:ba15439f45dd 59 printf("Sensor centre not present\n\r");
charlesmn 0:ba15439f45dd 60 } else {
charlesmn 0:ba15439f45dd 61 printf("Sensor centre present\n\r");
charlesmn 0:ba15439f45dd 62 n_dev++;
charlesmn 0:ba15439f45dd 63 }
charlesmn 0:ba15439f45dd 64
charlesmn 0:ba15439f45dd 65 // select the second VL53l1. It will have i2c address of 0x52. Set the i2c address to
charlesmn 0:ba15439f45dd 66 //NEW_SENSOR_LEFT_ADDRESS
charlesmn 0:ba15439f45dd 67 sensor2shut =1;
charlesmn 0:ba15439f45dd 68 status = sensor_left->InitSensor(NEW_SENSOR_LEFT_ADDRESS);
charlesmn 0:ba15439f45dd 69 if (status) {
charlesmn 0:ba15439f45dd 70 delete sensor_left;
charlesmn 0:ba15439f45dd 71 sensor_left = NULL;
charlesmn 0:ba15439f45dd 72 printf("Sensor left not present\n\r");
charlesmn 0:ba15439f45dd 73 } else {
charlesmn 0:ba15439f45dd 74 printf("Sensor left present\n\r");
charlesmn 0:ba15439f45dd 75 n_dev++;
charlesmn 0:ba15439f45dd 76 }
charlesmn 0:ba15439f45dd 77
charlesmn 0:ba15439f45dd 78 // select the 3rd VL53l1. It will have i2c address of 0x52. Set the i2c address to
charlesmn 0:ba15439f45dd 79 //NEW_SENSOR_RIGHT_ADDRESS
charlesmn 0:ba15439f45dd 80 sensor3shut =1;
charlesmn 0:ba15439f45dd 81 status = sensor_right->InitSensor(NEW_SENSOR_RIGHT_ADDRESS);
charlesmn 0:ba15439f45dd 82 if (status) {
charlesmn 0:ba15439f45dd 83 delete sensor_right;
charlesmn 0:ba15439f45dd 84 sensor_right = NULL;
charlesmn 0:ba15439f45dd 85 printf("Sensor right not present\n\r");
charlesmn 0:ba15439f45dd 86 } else {
charlesmn 0:ba15439f45dd 87 printf("Sensor right present\n\r");
charlesmn 0:ba15439f45dd 88 n_dev++;
charlesmn 0:ba15439f45dd 89 }
charlesmn 0:ba15439f45dd 90
charlesmn 0:ba15439f45dd 91 return 0;
charlesmn 0:ba15439f45dd 92 if (n_dev == 0) {
charlesmn 0:ba15439f45dd 93 return 1;
charlesmn 0:ba15439f45dd 94 } else {
charlesmn 0:ba15439f45dd 95 return 0;
charlesmn 0:ba15439f45dd 96 }
charlesmn 0:ba15439f45dd 97 }