Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
X_NUCLEO_COMMON/Board/NoShield53L3.cpp@0:293607457a02, 2020-10-16 (annotated)
- Committer:
- charlesmn
- Date:
- Fri Oct 16 15:04:28 2020 +0000
- Revision:
- 0:293607457a02
Change typo in name
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| charlesmn | 0:293607457a02 | 1 | #include "NoShield53L3.h" |
| charlesmn | 0:293607457a02 | 2 | |
| charlesmn | 0:293607457a02 | 3 | NoShield53L3 *NoShield53L3::_instance = NULL; |
| charlesmn | 0:293607457a02 | 4 | |
| charlesmn | 0:293607457a02 | 5 | |
| charlesmn | 0:293607457a02 | 6 | NoShield53L3 *NoShield53L3::instance(vl53L1X_DevI2C *ext_i2c) |
| charlesmn | 0:293607457a02 | 7 | { |
| charlesmn | 0:293607457a02 | 8 | if (_instance == NULL) { |
| charlesmn | 0:293607457a02 | 9 | _instance = new NoShield53L3(ext_i2c); |
| charlesmn | 0:293607457a02 | 10 | } else { |
| charlesmn | 0:293607457a02 | 11 | printf("Failed to create NoShield53l3 instance\n\r\r\n"); |
| charlesmn | 0:293607457a02 | 12 | } |
| charlesmn | 0:293607457a02 | 13 | return _instance; |
| charlesmn | 0:293607457a02 | 14 | } |
| charlesmn | 0:293607457a02 | 15 | |
| charlesmn | 0:293607457a02 | 16 | NoShield53L3 *NoShield53L3::instance(vl53L1X_DevI2C *ext_i2c, |
| charlesmn | 0:293607457a02 | 17 | PinName gpio1_centre, |
| charlesmn | 0:293607457a02 | 18 | PinName gpio1_left, PinName gpio1_right) |
| charlesmn | 0:293607457a02 | 19 | { |
| charlesmn | 0:293607457a02 | 20 | if (_instance == NULL) { |
| charlesmn | 0:293607457a02 | 21 | // printf("instance %d z\n",ext_i2c); |
| charlesmn | 0:293607457a02 | 22 | _instance = new NoShield53L3(ext_i2c, gpio1_centre, gpio1_left, gpio1_right); |
| charlesmn | 0:293607457a02 | 23 | } else { |
| charlesmn | 0:293607457a02 | 24 | printf("Failed to create XNucleo53L0A1 instance\n\r"); |
| charlesmn | 0:293607457a02 | 25 | } |
| charlesmn | 0:293607457a02 | 26 | return _instance; |
| charlesmn | 0:293607457a02 | 27 | } |
| charlesmn | 0:293607457a02 | 28 | |
| charlesmn | 0:293607457a02 | 29 | |
| charlesmn | 0:293607457a02 | 30 | // no stmpe1600. Shutdown lijnes controlled from pins passed in |
| charlesmn | 0:293607457a02 | 31 | int NoShield53L3::init_board(PinName shut_centre, |
| charlesmn | 0:293607457a02 | 32 | PinName shut_left, PinName shut_right) |
| charlesmn | 0:293607457a02 | 33 | { |
| charlesmn | 0:293607457a02 | 34 | printf("init_board \n"); |
| charlesmn | 0:293607457a02 | 35 | int status, n_dev = 0; |
| charlesmn | 0:293607457a02 | 36 | |
| charlesmn | 0:293607457a02 | 37 | // set the shutdown pins to be outputs ( they are inputs on power up) |
| charlesmn | 0:293607457a02 | 38 | DigitalOut sensor1shut(shut_centre); |
| charlesmn | 0:293607457a02 | 39 | DigitalOut sensor2shut(shut_left); |
| charlesmn | 0:293607457a02 | 40 | DigitalOut sensor3shut(shut_right); |
| charlesmn | 0:293607457a02 | 41 | |
| charlesmn | 0:293607457a02 | 42 | // On startup or on the shutdown pin going high the VL53l1 devices have a i2c address of 0x52. |
| charlesmn | 0:293607457a02 | 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:293607457a02 | 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:293607457a02 | 45 | |
| charlesmn | 0:293607457a02 | 46 | // set the shutdown pins to low, this will reset the VL53l1 |
| charlesmn | 0:293607457a02 | 47 | sensor1shut =0; |
| charlesmn | 0:293607457a02 | 48 | sensor2shut =0; |
| charlesmn | 0:293607457a02 | 49 | sensor3shut =0; |
| charlesmn | 0:293607457a02 | 50 | // select the first VL53l1. It will have i2c address of 0x52. Set the i2c address to |
| charlesmn | 0:293607457a02 | 51 | //NEW_SENSOR_CENTRE_ADDRESS |
| charlesmn | 0:293607457a02 | 52 | |
| charlesmn | 0:293607457a02 | 53 | sensor1shut =1; |
| charlesmn | 0:293607457a02 | 54 | printf("InitSensor \n"); |
| charlesmn | 0:293607457a02 | 55 | status = sensor_centre->InitSensor(NEW_SENSOR_CENTRE_ADDRESS); |
| charlesmn | 0:293607457a02 | 56 | if (status) { |
| charlesmn | 0:293607457a02 | 57 | delete sensor_centre; |
| charlesmn | 0:293607457a02 | 58 | sensor_centre = NULL; |
| charlesmn | 0:293607457a02 | 59 | printf("Sensor centre not present\n\r"); |
| charlesmn | 0:293607457a02 | 60 | } else { |
| charlesmn | 0:293607457a02 | 61 | printf("Sensor centre present\n\r"); |
| charlesmn | 0:293607457a02 | 62 | n_dev++; |
| charlesmn | 0:293607457a02 | 63 | } |
| charlesmn | 0:293607457a02 | 64 | |
| charlesmn | 0:293607457a02 | 65 | // select the second VL53l1. It will have i2c address of 0x52. Set the i2c address to |
| charlesmn | 0:293607457a02 | 66 | //NEW_SENSOR_LEFT_ADDRESS |
| charlesmn | 0:293607457a02 | 67 | sensor2shut =1; |
| charlesmn | 0:293607457a02 | 68 | status = sensor_left->InitSensor(NEW_SENSOR_LEFT_ADDRESS); |
| charlesmn | 0:293607457a02 | 69 | if (status) { |
| charlesmn | 0:293607457a02 | 70 | delete sensor_left; |
| charlesmn | 0:293607457a02 | 71 | sensor_left = NULL; |
| charlesmn | 0:293607457a02 | 72 | printf("Sensor left not present\n\r"); |
| charlesmn | 0:293607457a02 | 73 | } else { |
| charlesmn | 0:293607457a02 | 74 | printf("Sensor left present\n\r"); |
| charlesmn | 0:293607457a02 | 75 | n_dev++; |
| charlesmn | 0:293607457a02 | 76 | } |
| charlesmn | 0:293607457a02 | 77 | |
| charlesmn | 0:293607457a02 | 78 | // select the 3rd VL53l1. It will have i2c address of 0x52. Set the i2c address to |
| charlesmn | 0:293607457a02 | 79 | //NEW_SENSOR_RIGHT_ADDRESS |
| charlesmn | 0:293607457a02 | 80 | sensor3shut =1; |
| charlesmn | 0:293607457a02 | 81 | status = sensor_right->InitSensor(NEW_SENSOR_RIGHT_ADDRESS); |
| charlesmn | 0:293607457a02 | 82 | if (status) { |
| charlesmn | 0:293607457a02 | 83 | delete sensor_right; |
| charlesmn | 0:293607457a02 | 84 | sensor_right = NULL; |
| charlesmn | 0:293607457a02 | 85 | printf("Sensor right not present\n\r"); |
| charlesmn | 0:293607457a02 | 86 | } else { |
| charlesmn | 0:293607457a02 | 87 | printf("Sensor right present\n\r"); |
| charlesmn | 0:293607457a02 | 88 | n_dev++; |
| charlesmn | 0:293607457a02 | 89 | } |
| charlesmn | 0:293607457a02 | 90 | |
| charlesmn | 0:293607457a02 | 91 | return 0; |
| charlesmn | 0:293607457a02 | 92 | if (n_dev == 0) { |
| charlesmn | 0:293607457a02 | 93 | return 1; |
| charlesmn | 0:293607457a02 | 94 | } else { |
| charlesmn | 0:293607457a02 | 95 | return 0; |
| charlesmn | 0:293607457a02 | 96 | } |
| charlesmn | 0:293607457a02 | 97 | } |