VL53L3 Shield specific functions.
Dependents: 53L3A2_Ranging X_NUCLEO_53L3CX
NoShield53L3.h@2:81763ffd2222, 2021-07-14 (annotated)
- Committer:
- charlesmn
- Date:
- Wed Jul 14 15:07:09 2021 +0000
- Revision:
- 2:81763ffd2222
- Parent:
- 1:8afec488fa83
- Child:
- 3:6747fdb48f95
VL53L3CX is te same as VL53L3 except it uses the VL53L3CX class
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
charlesmn | 0:ba15439f45dd | 1 | /** |
charlesmn | 0:ba15439f45dd | 2 | ****************************************************************************** |
charlesmn | 0:ba15439f45dd | 3 | * @file NoShield53l3.h |
charlesmn | 0:ba15439f45dd | 4 | * @author JS |
charlesmn | 0:ba15439f45dd | 5 | * @version V0.0.1 |
charlesmn | 0:ba15439f45dd | 6 | * @date 15-January-2019 |
charlesmn | 0:ba15439f45dd | 7 | * @brief Header file for component XNucleo53L1A1 |
charlesmn | 0:ba15439f45dd | 8 | ****************************************************************************** |
charlesmn | 0:ba15439f45dd | 9 | * @attention |
charlesmn | 0:ba15439f45dd | 10 | * |
charlesmn | 0:ba15439f45dd | 11 | * <h2><center>© COPYRIGHT(c) 2019 STMicroelectronics</center></h2> |
charlesmn | 0:ba15439f45dd | 12 | * |
charlesmn | 0:ba15439f45dd | 13 | * Redistribution and use in source and binary forms, with or without modification, |
charlesmn | 0:ba15439f45dd | 14 | * are permitted provided that the following conditions are met: |
charlesmn | 0:ba15439f45dd | 15 | * 1. Redistributions of source code must retain the above copyright notice, |
charlesmn | 0:ba15439f45dd | 16 | * this list of conditions and the following disclaimer. |
charlesmn | 0:ba15439f45dd | 17 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
charlesmn | 0:ba15439f45dd | 18 | * this list of conditions and the following disclaimer in the documentation |
charlesmn | 0:ba15439f45dd | 19 | * and/or other materials provided with the distribution. |
charlesmn | 0:ba15439f45dd | 20 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
charlesmn | 0:ba15439f45dd | 21 | * may be used to endorse or promote products derived from this software |
charlesmn | 0:ba15439f45dd | 22 | * without specific prior written permission. |
charlesmn | 0:ba15439f45dd | 23 | * |
charlesmn | 0:ba15439f45dd | 24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
charlesmn | 0:ba15439f45dd | 25 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
charlesmn | 0:ba15439f45dd | 26 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
charlesmn | 0:ba15439f45dd | 27 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
charlesmn | 0:ba15439f45dd | 28 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
charlesmn | 0:ba15439f45dd | 29 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
charlesmn | 0:ba15439f45dd | 30 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
charlesmn | 0:ba15439f45dd | 31 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
charlesmn | 0:ba15439f45dd | 32 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
charlesmn | 0:ba15439f45dd | 33 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
charlesmn | 0:ba15439f45dd | 34 | * |
charlesmn | 0:ba15439f45dd | 35 | ****************************************************************************** |
charlesmn | 0:ba15439f45dd | 36 | */ |
charlesmn | 0:ba15439f45dd | 37 | |
charlesmn | 0:ba15439f45dd | 38 | #ifndef __VL53L1_NO_SHIELD_CLASS_H |
charlesmn | 0:ba15439f45dd | 39 | #define __VL53L1_NO_SHIELD_CLASS_H |
charlesmn | 0:ba15439f45dd | 40 | |
charlesmn | 0:ba15439f45dd | 41 | |
charlesmn | 0:ba15439f45dd | 42 | /* Includes ------------------------------------------------------------------*/ |
charlesmn | 0:ba15439f45dd | 43 | #include "mbed.h" |
charlesmn | 0:ba15439f45dd | 44 | #include "PinNames.h" |
charlesmn | 2:81763ffd2222 | 45 | #include "vl53l3cx_class.h" |
charlesmn | 0:ba15439f45dd | 46 | //#include "Stmpe1600.h" |
charlesmn | 0:ba15439f45dd | 47 | //#include "DevI2C.h" |
charlesmn | 1:8afec488fa83 | 48 | #include "vl53L3_I2c.h" |
charlesmn | 0:ba15439f45dd | 49 | |
charlesmn | 0:ba15439f45dd | 50 | |
charlesmn | 0:ba15439f45dd | 51 | #define NEW_SENSOR_CENTRE_ADDRESS 0x56 |
charlesmn | 0:ba15439f45dd | 52 | #define NEW_SENSOR_LEFT_ADDRESS 0x58 |
charlesmn | 0:ba15439f45dd | 53 | #define NEW_SENSOR_RIGHT_ADDRESS 0x5a |
charlesmn | 0:ba15439f45dd | 54 | |
charlesmn | 0:ba15439f45dd | 55 | |
charlesmn | 0:ba15439f45dd | 56 | /* Classes--------------------------------------------------------------------*/ |
charlesmn | 0:ba15439f45dd | 57 | |
charlesmn | 0:ba15439f45dd | 58 | /* Classes -------------------------------------------------------------------*/ |
charlesmn | 0:ba15439f45dd | 59 | /** Class representing the X-NUCLEO-VL53L1A1 expansion board |
charlesmn | 0:ba15439f45dd | 60 | */ |
charlesmn | 0:ba15439f45dd | 61 | class NoShield53L3 |
charlesmn | 0:ba15439f45dd | 62 | { |
charlesmn | 0:ba15439f45dd | 63 | public: |
charlesmn | 0:ba15439f45dd | 64 | /** Constructor 1 |
charlesmn | 0:ba15439f45dd | 65 | * @param[in] &i2c device I2C to be used for communication |
charlesmn | 0:ba15439f45dd | 66 | */ |
charlesmn | 1:8afec488fa83 | 67 | NoShield53L3(vl53L3_DevI2C *ext_i2c) : dev_i2c(ext_i2c) |
charlesmn | 0:ba15439f45dd | 68 | { |
charlesmn | 2:81763ffd2222 | 69 | sensor_centre = new VL53L3CX(ext_i2c, 0, A2); |
charlesmn | 2:81763ffd2222 | 70 | sensor_left = new VL53L3CX(dev_i2c, 0, D8); |
charlesmn | 2:81763ffd2222 | 71 | sensor_right = new VL53L3CX(dev_i2c, 0, D2); |
charlesmn | 0:ba15439f45dd | 72 | } |
charlesmn | 0:ba15439f45dd | 73 | |
charlesmn | 0:ba15439f45dd | 74 | /** Constructor 2 |
charlesmn | 0:ba15439f45dd | 75 | * @param[in] &i2c device I2C to be used for communication |
charlesmn | 0:ba15439f45dd | 76 | * @param[in] PinName gpio1_top Mbed DigitalOut pin name to be used as a top sensor GPIO_1 INT |
charlesmn | 0:ba15439f45dd | 77 | * @param[in] PinName gpio1_bottom Mbed DigitalOut pin name to be used as a bottom sensor GPIO_1 INT |
charlesmn | 0:ba15439f45dd | 78 | * @param[in] PinName gpio1_left Mbed DigitalOut pin name to be used as a left sensor GPIO_1 INT |
charlesmn | 0:ba15439f45dd | 79 | * @param[in] PinName gpio1_right Mbed DigitalOut pin name to be used as a right sensor GPIO_1 INT |
charlesmn | 0:ba15439f45dd | 80 | */ |
charlesmn | 1:8afec488fa83 | 81 | NoShield53L3(vl53L3_DevI2C *ext_i2c, PinName gpio1_centre, |
charlesmn | 0:ba15439f45dd | 82 | PinName gpio1_left, PinName gpio1_right) : dev_i2c(ext_i2c) |
charlesmn | 0:ba15439f45dd | 83 | { |
charlesmn | 1:8afec488fa83 | 84 | printf("NoShield53L3 constructor %d %d %d %d\n",ext_i2c,gpio1_centre,gpio1_left,gpio1_right); |
charlesmn | 0:ba15439f45dd | 85 | |
charlesmn | 2:81763ffd2222 | 86 | sensor_centre = new VL53L3CX(dev_i2c, 0, gpio1_centre); |
charlesmn | 2:81763ffd2222 | 87 | sensor_left = new VL53L3CX(dev_i2c, 0, gpio1_left); |
charlesmn | 2:81763ffd2222 | 88 | sensor_right = new VL53L3CX(dev_i2c, 0, gpio1_right); |
charlesmn | 0:ba15439f45dd | 89 | } |
charlesmn | 0:ba15439f45dd | 90 | |
charlesmn | 0:ba15439f45dd | 91 | |
charlesmn | 0:ba15439f45dd | 92 | /** Destructor |
charlesmn | 0:ba15439f45dd | 93 | */ |
charlesmn | 0:ba15439f45dd | 94 | ~NoShield53L3() |
charlesmn | 0:ba15439f45dd | 95 | { |
charlesmn | 0:ba15439f45dd | 96 | |
charlesmn | 0:ba15439f45dd | 97 | if (sensor_centre != NULL) { |
charlesmn | 0:ba15439f45dd | 98 | delete sensor_centre; |
charlesmn | 0:ba15439f45dd | 99 | sensor_centre = NULL; |
charlesmn | 0:ba15439f45dd | 100 | } |
charlesmn | 0:ba15439f45dd | 101 | |
charlesmn | 0:ba15439f45dd | 102 | if (sensor_left != NULL) { |
charlesmn | 0:ba15439f45dd | 103 | delete sensor_left; |
charlesmn | 0:ba15439f45dd | 104 | sensor_left = NULL; |
charlesmn | 0:ba15439f45dd | 105 | } |
charlesmn | 0:ba15439f45dd | 106 | |
charlesmn | 0:ba15439f45dd | 107 | if (sensor_right != NULL) { |
charlesmn | 0:ba15439f45dd | 108 | delete sensor_right; |
charlesmn | 0:ba15439f45dd | 109 | sensor_right = NULL; |
charlesmn | 0:ba15439f45dd | 110 | } |
charlesmn | 0:ba15439f45dd | 111 | |
charlesmn | 0:ba15439f45dd | 112 | _instance = NULL; |
charlesmn | 0:ba15439f45dd | 113 | } |
charlesmn | 0:ba15439f45dd | 114 | |
charlesmn | 0:ba15439f45dd | 115 | |
charlesmn | 0:ba15439f45dd | 116 | /** |
charlesmn | 0:ba15439f45dd | 117 | * @brief Creates a singleton object instance |
charlesmn | 0:ba15439f45dd | 118 | * @param[in] &i2c device I2C to be used for communication |
charlesmn | 0:ba15439f45dd | 119 | * @return Pointer to the object instance |
charlesmn | 0:ba15439f45dd | 120 | */ |
charlesmn | 1:8afec488fa83 | 121 | static NoShield53L3 *instance(vl53L3_DevI2C *ext_i2c); |
charlesmn | 0:ba15439f45dd | 122 | |
charlesmn | 0:ba15439f45dd | 123 | /** |
charlesmn | 0:ba15439f45dd | 124 | * @brief Creates a singleton object instance |
charlesmn | 0:ba15439f45dd | 125 | * @param[in] &i2c device I2C to be used for communication |
charlesmn | 0:ba15439f45dd | 126 | * @param[in] PinName gpio1_centre the pin connected to top sensor INT |
charlesmn | 0:ba15439f45dd | 127 | * @param[in] PinName gpio1_left the pin connected to left sensor INT |
charlesmn | 0:ba15439f45dd | 128 | * @param[in] PinName gpio1_right the pin connected to right sensor INT |
charlesmn | 0:ba15439f45dd | 129 | * @return Pointer to the object instance |
charlesmn | 0:ba15439f45dd | 130 | */ |
charlesmn | 1:8afec488fa83 | 131 | static NoShield53L3 *instance(vl53L3_DevI2C *ext_i2c, PinName gpio1_centre, |
charlesmn | 0:ba15439f45dd | 132 | PinName gpio1_left, PinName gpio1_right); |
charlesmn | 0:ba15439f45dd | 133 | |
charlesmn | 0:ba15439f45dd | 134 | /** |
charlesmn | 0:ba15439f45dd | 135 | * @brief Initialize the board and sensors with deft values |
charlesmn | 0:ba15439f45dd | 136 | * @return 0 on success |
charlesmn | 0:ba15439f45dd | 137 | */ |
charlesmn | 0:ba15439f45dd | 138 | int init_board(); |
charlesmn | 0:ba15439f45dd | 139 | int init_board(PinName shut_centre, PinName shut_left, PinName shut_right); |
charlesmn | 0:ba15439f45dd | 140 | |
charlesmn | 1:8afec488fa83 | 141 | vl53L3_DevI2C *dev_i2c; |
charlesmn | 2:81763ffd2222 | 142 | VL53L3CX *sensor_centre; |
charlesmn | 2:81763ffd2222 | 143 | VL53L3CX *sensor_left; |
charlesmn | 2:81763ffd2222 | 144 | VL53L3CX *sensor_right; |
charlesmn | 0:ba15439f45dd | 145 | |
charlesmn | 0:ba15439f45dd | 146 | private: |
charlesmn | 0:ba15439f45dd | 147 | static NoShield53L3 *_instance; |
charlesmn | 0:ba15439f45dd | 148 | }; |
charlesmn | 0:ba15439f45dd | 149 | |
charlesmn | 0:ba15439f45dd | 150 | |
charlesmn | 0:ba15439f45dd | 151 | #endif /* __VL53L1_NO_SHIELD_CLASS_H */ |