mm

Dependencies:   VL53L0X

Committer:
junno
Date:
Tue Mar 22 13:12:13 2022 +0000
Revision:
22:7f503d16048b
Parent:
19:1727c86ac63b
m

Who changed what in which revision?

UserRevisionLine numberNew contents of line
johnAlexander 0:c523920bcc09 1 /**
johnAlexander 0:c523920bcc09 2 ******************************************************************************
Davidroid 16:27d3d95c8593 3 * @file XNucleo53L0A1.cpp
johnAlexander 0:c523920bcc09 4 * @author IMG
johnAlexander 1:01b8004bc0a7 5 * @version V1.0.0
johnAlexander 1:01b8004bc0a7 6 * @date 28-November-2016
johnAlexander 0:c523920bcc09 7 * @brief Implementation file for the X_NUCLEO_VL53L0A1 singleton class
johnAlexander 0:c523920bcc09 8 ******************************************************************************
johnAlexander 0:c523920bcc09 9 * @attention
johnAlexander 0:c523920bcc09 10 *
johnAlexander 0:c523920bcc09 11 * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
johnAlexander 0:c523920bcc09 12 *
johnAlexander 0:c523920bcc09 13 * Redistribution and use in source and binary forms, with or without modification,
johnAlexander 0:c523920bcc09 14 * are permitted provided that the following conditions are met:
johnAlexander 0:c523920bcc09 15 * 1. Redistributions of source code must retain the above copyright notice,
johnAlexander 0:c523920bcc09 16 * this list of conditions and the following disclaimer.
johnAlexander 0:c523920bcc09 17 * 2. Redistributions in binary form must reproduce the above copyright notice,
johnAlexander 0:c523920bcc09 18 * this list of conditions and the following disclaimer in the documentation
johnAlexander 0:c523920bcc09 19 * and/or other materials provided with the distribution.
johnAlexander 0:c523920bcc09 20 * 3. Neither the name of STMicroelectronics nor the names of its contributors
johnAlexander 0:c523920bcc09 21 * may be used to endorse or promote products derived from this software
johnAlexander 0:c523920bcc09 22 * without specific prior written permission.
johnAlexander 0:c523920bcc09 23 *
johnAlexander 0:c523920bcc09 24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
johnAlexander 0:c523920bcc09 25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
johnAlexander 0:c523920bcc09 26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
johnAlexander 0:c523920bcc09 27 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
johnAlexander 0:c523920bcc09 28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
johnAlexander 0:c523920bcc09 29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
johnAlexander 0:c523920bcc09 30 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
johnAlexander 0:c523920bcc09 31 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
johnAlexander 0:c523920bcc09 32 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
johnAlexander 0:c523920bcc09 33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
johnAlexander 0:c523920bcc09 34 *
johnAlexander 0:c523920bcc09 35 ******************************************************************************
johnAlexander 0:c523920bcc09 36 */
johnAlexander 0:c523920bcc09 37
johnAlexander 0:c523920bcc09 38
johnAlexander 0:c523920bcc09 39 /* Includes ------------------------------------------------------------------*/
Davidroid 16:27d3d95c8593 40 #include "XNucleo53L0A1.h"
Davidroid 16:27d3d95c8593 41 #include "VL53L0X_platform_log.h"
johnAlexander 0:c523920bcc09 42
johnAlexander 0:c523920bcc09 43 /* Static variables ----------------------------------------------------------*/
Davidroid 16:27d3d95c8593 44 XNucleo53L0A1 *XNucleo53L0A1::_instance = NULL;
johnAlexander 0:c523920bcc09 45
Davidroid 16:27d3d95c8593 46 XNucleo53L0A1 *XNucleo53L0A1::instance(DevI2C *ext_i2c)
johnAlexander 0:c523920bcc09 47 {
Davidroid 19:1727c86ac63b 48 if (_instance == NULL) {
Davidroid 16:27d3d95c8593 49 _instance = new XNucleo53L0A1(ext_i2c);
Davidroid 19:1727c86ac63b 50 } else {
Davidroid 16:27d3d95c8593 51 VL53L0X_ErrLog("Failed to create XNucleo53L0A1 instance\n\r");
Davidroid 19:1727c86ac63b 52 }
johnAlexander 14:8320b5ff96fa 53 return _instance;
johnAlexander 0:c523920bcc09 54 }
johnAlexander 0:c523920bcc09 55
Davidroid 16:27d3d95c8593 56 XNucleo53L0A1 *XNucleo53L0A1::instance(DevI2C *ext_i2c,
Davidroid 18:2413acea538f 57 PinName gpio1_centre,
Davidroid 18:2413acea538f 58 PinName gpio1_left, PinName gpio1_right)
johnAlexander 0:c523920bcc09 59 {
Davidroid 19:1727c86ac63b 60 if (_instance == NULL) {
Davidroid 16:27d3d95c8593 61 _instance = new XNucleo53L0A1(ext_i2c, gpio1_centre, gpio1_left, gpio1_right);
Davidroid 19:1727c86ac63b 62 } else {
Davidroid 16:27d3d95c8593 63 VL53L0X_ErrLog("Failed to create XNucleo53L0A1 instance\n\r");
Davidroid 19:1727c86ac63b 64 }
johnAlexander 14:8320b5ff96fa 65 return _instance;
johnAlexander 0:c523920bcc09 66 }
johnAlexander 0:c523920bcc09 67
johnAlexander 0:c523920bcc09 68
Davidroid 16:27d3d95c8593 69 int XNucleo53L0A1::init_board()
johnAlexander 14:8320b5ff96fa 70 {
johnAlexander 14:8320b5ff96fa 71 int status, n_dev = 0;
johnAlexander 14:8320b5ff96fa 72
Davidroid 18:2413acea538f 73
Davidroid 18:2413acea538f 74
Davidroid 18:2413acea538f 75
Davidroid 18:2413acea538f 76
Davidroid 16:27d3d95c8593 77 sensor_centre->VL53L0X_off();
Davidroid 16:27d3d95c8593 78 sensor_left->VL53L0X_off();
Davidroid 16:27d3d95c8593 79 sensor_right->VL53L0X_off();
johnAlexander 14:8320b5ff96fa 80 status = sensor_centre->init_sensor(NEW_SENSOR_CENTRE_ADDRESS);
johnAlexander 14:8320b5ff96fa 81 if (status) {
Davidroid 18:2413acea538f 82
johnAlexander 14:8320b5ff96fa 83 delete sensor_centre;
johnAlexander 14:8320b5ff96fa 84 delete xshutdown_centre;
johnAlexander 14:8320b5ff96fa 85 sensor_centre = NULL;
johnAlexander 14:8320b5ff96fa 86 xshutdown_centre = NULL;
johnAlexander 14:8320b5ff96fa 87 printf("Sensor centre not present\n\r");
Davidroid 18:2413acea538f 88
johnAlexander 14:8320b5ff96fa 89 } else {
Davidroid 18:2413acea538f 90
johnAlexander 14:8320b5ff96fa 91 printf("Sensor centre present\n\r");
johnAlexander 14:8320b5ff96fa 92 n_dev++;
johnAlexander 14:8320b5ff96fa 93 }
johnAlexander 14:8320b5ff96fa 94 status = sensor_left->init_sensor(NEW_SENSOR_LEFT_ADDRESS);
johnAlexander 14:8320b5ff96fa 95 if (status) {
Davidroid 18:2413acea538f 96
johnAlexander 14:8320b5ff96fa 97 delete sensor_left;
johnAlexander 14:8320b5ff96fa 98 delete xshutdown_left;
johnAlexander 14:8320b5ff96fa 99 sensor_left = NULL;
johnAlexander 14:8320b5ff96fa 100 xshutdown_left = NULL;
johnAlexander 14:8320b5ff96fa 101 printf("Sensor left not present\n\r");
Davidroid 18:2413acea538f 102
johnAlexander 14:8320b5ff96fa 103 } else {
Davidroid 18:2413acea538f 104
johnAlexander 14:8320b5ff96fa 105 printf("Sensor left present\n\r");
johnAlexander 14:8320b5ff96fa 106 n_dev++;
johnAlexander 14:8320b5ff96fa 107 }
johnAlexander 9:367d1f390cb2 108
johnAlexander 14:8320b5ff96fa 109 status = sensor_right->init_sensor(NEW_SENSOR_RIGHT_ADDRESS);
johnAlexander 14:8320b5ff96fa 110 if (status) {
Davidroid 18:2413acea538f 111
johnAlexander 14:8320b5ff96fa 112 delete sensor_right;
johnAlexander 14:8320b5ff96fa 113 delete xshutdown_right;
johnAlexander 14:8320b5ff96fa 114 sensor_right = NULL;
johnAlexander 14:8320b5ff96fa 115 xshutdown_right = NULL;
johnAlexander 14:8320b5ff96fa 116 printf("Sensor right not present\n\r");
Davidroid 18:2413acea538f 117
johnAlexander 14:8320b5ff96fa 118 } else {
Davidroid 18:2413acea538f 119
johnAlexander 14:8320b5ff96fa 120 printf("Sensor right present\n\r");
johnAlexander 14:8320b5ff96fa 121 n_dev++;
johnAlexander 14:8320b5ff96fa 122 }
johnAlexander 9:367d1f390cb2 123
Davidroid 16:27d3d95c8593 124 if (n_dev == 0) {
johnAlexander 14:8320b5ff96fa 125 return 1;
Davidroid 16:27d3d95c8593 126 } else {
johnAlexander 14:8320b5ff96fa 127 return 0;
Davidroid 16:27d3d95c8593 128 }
johnAlexander 0:c523920bcc09 129 }