Changes to the library related to interrupt mode.

Dependencies:   ST_INTERFACES X_NUCLEO_COMMON

Dependents:   Display_53L0A1_IntSatelites Display_53L0A1_InterruptMode

Fork of X_NUCLEO_53L0A1 by ST

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers x_nucleo_53l0a1.cpp Source File

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>&copy; 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 
00042 /* Static variables ----------------------------------------------------------*/
00043 X_NUCLEO_53L0A1* X_NUCLEO_53L0A1::_instance = NULL;
00044 
00045 X_NUCLEO_53L0A1* X_NUCLEO_53L0A1::Instance(DevI2C *ext_i2c)
00046 {
00047    if(_instance==NULL)
00048       _instance=new X_NUCLEO_53L0A1(ext_i2c);
00049    else
00050       VL53L0X_ErrLog("Failed to create X_NUCLEO_53L0A1 instance\n\r");
00051    return _instance;
00052 }
00053 
00054 X_NUCLEO_53L0A1* X_NUCLEO_53L0A1::Instance(DevI2C *ext_i2c, 
00055                                              PinName gpio1_centre, 
00056                                              PinName gpio1_left, PinName gpio1_right)
00057 {
00058    if(_instance==NULL)
00059       _instance=new X_NUCLEO_53L0A1(ext_i2c, gpio1_centre, gpio1_left, gpio1_right);
00060    else
00061       VL53L0X_ErrLog("Failed to create X_NUCLEO_53L0A1 instance\n\r");
00062    return _instance;
00063 }
00064 
00065 
00066 int X_NUCLEO_53L0A1::InitBoard()
00067 {   
00068    int status, n_dev=0;
00069     
00070    sensor_centre->VL53L0X_Off();
00071    sensor_left->VL53L0X_Off();
00072    sensor_right->VL53L0X_Off();
00073    status=sensor_centre->InitSensor(NEW_SENSOR_CENTRE_ADDRESS);
00074    if(status)
00075    {
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    }
00082    else
00083    {
00084       printf("Sensor centre present\n\r");
00085       n_dev++;
00086    }
00087    status=sensor_left->InitSensor(NEW_SENSOR_LEFT_ADDRESS);
00088    if(status)
00089    {
00090       delete sensor_left;
00091       delete xshutdown_left;
00092       sensor_left=NULL;
00093       xshutdown_left=NULL;
00094       printf("Sensor left not present\n\r");
00095    }
00096    else
00097    {
00098       printf("Sensor left present\n\r");
00099       n_dev++;
00100    }
00101 
00102    status=sensor_right->InitSensor(NEW_SENSOR_RIGHT_ADDRESS);
00103    if(status)
00104    {
00105       delete sensor_right;
00106       delete xshutdown_right;
00107       sensor_right=NULL;
00108       xshutdown_right=NULL;
00109       printf("Sensor right not present\n\r");
00110    }
00111    else
00112    {
00113       printf("Sensor right present\n\r");
00114       n_dev++;
00115    }
00116 
00117    if(n_dev==0)
00118       return 1;
00119    else
00120       return 0;
00121 }