Updates to follow mbed SDK coding style guidelines.
Dependencies: ST_INTERFACES X_NUCLEO_COMMON
Dependents: 53L0A1_Satellites_with_Interrupts_OS5 Display_53L0A1_OS5
Fork of X_NUCLEO_53L0A1 by
x_nucleo_53l0a1.cpp
00001 /** 00002 ****************************************************************************** 00003 * @file x_nucleo_53L0A1.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 "x_nucleo_53l0a1.h" 00041 #include "vl53l0x_platform_log.h" 00042 00043 /* Static variables ----------------------------------------------------------*/ 00044 X_NUCLEO_53L0A1* X_NUCLEO_53L0A1::_instance = NULL; 00045 00046 X_NUCLEO_53L0A1* X_NUCLEO_53L0A1::instance(DevI2C *ext_i2c) 00047 { 00048 if(_instance==NULL) 00049 _instance=new X_NUCLEO_53L0A1(ext_i2c); 00050 else 00051 VL53L0X_ErrLog("Failed to create X_NUCLEO_53L0A1 instance\n\r"); 00052 return _instance; 00053 } 00054 00055 X_NUCLEO_53L0A1* X_NUCLEO_53L0A1::instance(DevI2C *ext_i2c, 00056 PinName gpio1_centre, 00057 PinName gpio1_left, PinName gpio1_right) 00058 { 00059 if(_instance==NULL) 00060 _instance=new X_NUCLEO_53L0A1(ext_i2c, gpio1_centre, gpio1_left, gpio1_right); 00061 else 00062 VL53L0X_ErrLog("Failed to create X_NUCLEO_53L0A1 instance\n\r"); 00063 return _instance; 00064 } 00065 00066 00067 int X_NUCLEO_53L0A1::init_board() 00068 { 00069 int status, n_dev=0; 00070 00071 sensor_centre->vl53l0x_off(); 00072 sensor_left->vl53l0x_off(); 00073 sensor_right->vl53l0x_off(); 00074 status=sensor_centre->init_sensor(NEW_SENSOR_CENTRE_ADDRESS); 00075 if(status) { 00076 delete sensor_centre; 00077 delete xshutdown_centre; 00078 sensor_centre=NULL; 00079 xshutdown_centre=NULL; 00080 printf("Sensor centre not present\n\r"); 00081 } else { 00082 printf("Sensor centre present\n\r"); 00083 n_dev++; 00084 } 00085 status=sensor_left->init_sensor(NEW_SENSOR_LEFT_ADDRESS); 00086 if(status) { 00087 delete sensor_left; 00088 delete xshutdown_left; 00089 sensor_left=NULL; 00090 xshutdown_left=NULL; 00091 printf("Sensor left not present\n\r"); 00092 } else { 00093 printf("Sensor left present\n\r"); 00094 n_dev++; 00095 } 00096 00097 status=sensor_right->init_sensor(NEW_SENSOR_RIGHT_ADDRESS); 00098 if(status) { 00099 delete sensor_right; 00100 delete xshutdown_right; 00101 sensor_right=NULL; 00102 xshutdown_right=NULL; 00103 printf("Sensor right not present\n\r"); 00104 } else { 00105 printf("Sensor right present\n\r"); 00106 n_dev++; 00107 } 00108 00109 if(n_dev==0) 00110 return 1; 00111 else 00112 return 0; 00113 }
Generated on Wed Jul 13 2022 19:35:41 by 1.7.2