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.
Fork of X_NUCLEO_53L0A1 by
XNucleo53L0A1.cpp
00001 /** 00002 ****************************************************************************** 00003 * @file XNucleo53L0A1.cpp 00004 * @author IMG 00005 * @version V1.0.0 00006 * @date 28-November-2016 00007 * @brief Implementation file for the X_NUCLEO_VL53L0A1 singleton class 00008 ****************************************************************************** 00009 * @attention 00010 * 00011 * <h2><center>© COPYRIGHT(c) 2016 STMicroelectronics</center></h2> 00012 * 00013 * Redistribution and use in source and binary forms, with or without modification, 00014 * are permitted provided that the following conditions are met: 00015 * 1. Redistributions of source code must retain the above copyright notice, 00016 * this list of conditions and the following disclaimer. 00017 * 2. Redistributions in binary form must reproduce the above copyright notice, 00018 * this list of conditions and the following disclaimer in the documentation 00019 * and/or other materials provided with the distribution. 00020 * 3. Neither the name of STMicroelectronics nor the names of its contributors 00021 * may be used to endorse or promote products derived from this software 00022 * without specific prior written permission. 00023 * 00024 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00025 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00026 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00027 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 00028 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00029 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 00030 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00031 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00032 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00033 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00034 * 00035 ****************************************************************************** 00036 */ 00037 00038 00039 /* Includes ------------------------------------------------------------------*/ 00040 #include "XNucleo53L0A1.h" 00041 #include "VL53L0X_platform_log.h" 00042 00043 /* Static variables ----------------------------------------------------------*/ 00044 XNucleo53L0A1 *XNucleo53L0A1::_instance = NULL; 00045 00046 XNucleo53L0A1 *XNucleo53L0A1::instance(DevI2C *ext_i2c) 00047 { 00048 if (_instance == NULL) { 00049 _instance = new XNucleo53L0A1(ext_i2c); 00050 } else { 00051 VL53L0X_ErrLog("Failed to create XNucleo53L0A1 instance\n\r"); 00052 } 00053 return _instance; 00054 } 00055 00056 XNucleo53L0A1 *XNucleo53L0A1::instance(DevI2C *ext_i2c, 00057 PinName gpio1_centre, 00058 PinName gpio1_left, PinName gpio1_right) 00059 { 00060 if (_instance == NULL) { 00061 _instance = new XNucleo53L0A1(ext_i2c, gpio1_centre, gpio1_left, gpio1_right); 00062 } else { 00063 VL53L0X_ErrLog("Failed to create XNucleo53L0A1 instance\n\r"); 00064 } 00065 return _instance; 00066 } 00067 00068 00069 int XNucleo53L0A1::init_board() 00070 { 00071 int status, n_dev = 0; 00072 00073 00074 00075 00076 00077 sensor_centre->VL53L0X_off(); 00078 sensor_left->VL53L0X_off(); 00079 sensor_right->VL53L0X_off(); 00080 status = sensor_centre->init_sensor(NEW_SENSOR_CENTRE_ADDRESS); 00081 if (status) { 00082 00083 delete sensor_centre; 00084 delete xshutdown_centre; 00085 sensor_centre = NULL; 00086 xshutdown_centre = NULL; 00087 //printf("Sensor centre not present\n\r"); 00088 00089 } else { 00090 00091 //printf("Sensor centre present\n\r"); 00092 n_dev++; 00093 } 00094 status = sensor_left->init_sensor(NEW_SENSOR_LEFT_ADDRESS); 00095 if (status) { 00096 00097 delete sensor_left; 00098 delete xshutdown_left; 00099 sensor_left = NULL; 00100 xshutdown_left = NULL; 00101 //printf("Sensor left not present\n\r"); 00102 00103 } else { 00104 00105 //printf("Sensor left present\n\r"); 00106 n_dev++; 00107 } 00108 00109 status = sensor_right->init_sensor(NEW_SENSOR_RIGHT_ADDRESS); 00110 if (status) { 00111 00112 delete sensor_right; 00113 delete xshutdown_right; 00114 sensor_right = NULL; 00115 xshutdown_right = NULL; 00116 //printf("Sensor right not present\n\r"); 00117 00118 } else { 00119 00120 //printf("Sensor right present\n\r"); 00121 n_dev++; 00122 } 00123 00124 if (n_dev == 0) { 00125 return 1; 00126 } else { 00127 return 0; 00128 } 00129 }
Generated on Wed Jul 13 2022 17:44:25 by
1.7.2
