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 ST

Committer:
johnAlexander
Date:
Tue Jun 20 16:00:31 2017 +0000
Revision:
15:932d8b4e52c9
Parent:
11:ceaa5a026412
Child:
16:98ce55ddbb1a
x_nucleo_53l0a1 & vl53l0x_class class reformatted with astyle tool.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
johnAlexander 0:c523920bcc09 1 /**
johnAlexander 0:c523920bcc09 2 ******************************************************************************
johnAlexander 0:c523920bcc09 3 * @file x_nucleo_53L0A1.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 ------------------------------------------------------------------*/
johnAlexander 0:c523920bcc09 40 #include "x_nucleo_53l0a1.h"
johnAlexander 0:c523920bcc09 41
johnAlexander 0:c523920bcc09 42 /* Static variables ----------------------------------------------------------*/
johnAlexander 0:c523920bcc09 43 X_NUCLEO_53L0A1* X_NUCLEO_53L0A1::_instance = NULL;
johnAlexander 0:c523920bcc09 44
johnAlexander 0:c523920bcc09 45 X_NUCLEO_53L0A1* X_NUCLEO_53L0A1::Instance(DevI2C *ext_i2c)
johnAlexander 0:c523920bcc09 46 {
johnAlexander 15:932d8b4e52c9 47 if(_instance==NULL)
johnAlexander 15:932d8b4e52c9 48 _instance=new X_NUCLEO_53L0A1(ext_i2c);
johnAlexander 15:932d8b4e52c9 49 else
johnAlexander 15:932d8b4e52c9 50 VL53L0X_ErrLog("Failed to create X_NUCLEO_53L0A1 instance\n\r");
johnAlexander 15:932d8b4e52c9 51 return _instance;
johnAlexander 0:c523920bcc09 52 }
johnAlexander 0:c523920bcc09 53
johnAlexander 15:932d8b4e52c9 54 X_NUCLEO_53L0A1* X_NUCLEO_53L0A1::Instance(DevI2C *ext_i2c,
johnAlexander 15:932d8b4e52c9 55 PinName gpio1_centre,
johnAlexander 15:932d8b4e52c9 56 PinName gpio1_left, PinName gpio1_right)
johnAlexander 0:c523920bcc09 57 {
johnAlexander 15:932d8b4e52c9 58 if(_instance==NULL)
johnAlexander 15:932d8b4e52c9 59 _instance=new X_NUCLEO_53L0A1(ext_i2c, gpio1_centre, gpio1_left, gpio1_right);
johnAlexander 15:932d8b4e52c9 60 else
johnAlexander 15:932d8b4e52c9 61 VL53L0X_ErrLog("Failed to create X_NUCLEO_53L0A1 instance\n\r");
johnAlexander 15:932d8b4e52c9 62 return _instance;
johnAlexander 0:c523920bcc09 63 }
johnAlexander 0:c523920bcc09 64
johnAlexander 0:c523920bcc09 65
johnAlexander 0:c523920bcc09 66 int X_NUCLEO_53L0A1::InitBoard()
johnAlexander 15:932d8b4e52c9 67 {
johnAlexander 15:932d8b4e52c9 68 int status, n_dev=0;
johnAlexander 9:367d1f390cb2 69
johnAlexander 15:932d8b4e52c9 70 sensor_centre->VL53L0X_Off();
johnAlexander 15:932d8b4e52c9 71 sensor_left->VL53L0X_Off();
johnAlexander 15:932d8b4e52c9 72 sensor_right->VL53L0X_Off();
johnAlexander 15:932d8b4e52c9 73 status=sensor_centre->InitSensor(NEW_SENSOR_CENTRE_ADDRESS);
johnAlexander 15:932d8b4e52c9 74 if(status) {
johnAlexander 15:932d8b4e52c9 75 delete sensor_centre;
johnAlexander 15:932d8b4e52c9 76 delete xshutdown_centre;
johnAlexander 15:932d8b4e52c9 77 sensor_centre=NULL;
johnAlexander 15:932d8b4e52c9 78 xshutdown_centre=NULL;
johnAlexander 15:932d8b4e52c9 79 printf("Sensor centre not present\n\r");
johnAlexander 15:932d8b4e52c9 80 } else {
johnAlexander 15:932d8b4e52c9 81 printf("Sensor centre present\n\r");
johnAlexander 15:932d8b4e52c9 82 n_dev++;
johnAlexander 15:932d8b4e52c9 83 }
johnAlexander 15:932d8b4e52c9 84 status=sensor_left->InitSensor(NEW_SENSOR_LEFT_ADDRESS);
johnAlexander 15:932d8b4e52c9 85 if(status) {
johnAlexander 15:932d8b4e52c9 86 delete sensor_left;
johnAlexander 15:932d8b4e52c9 87 delete xshutdown_left;
johnAlexander 15:932d8b4e52c9 88 sensor_left=NULL;
johnAlexander 15:932d8b4e52c9 89 xshutdown_left=NULL;
johnAlexander 15:932d8b4e52c9 90 printf("Sensor left not present\n\r");
johnAlexander 15:932d8b4e52c9 91 } else {
johnAlexander 15:932d8b4e52c9 92 printf("Sensor left present\n\r");
johnAlexander 15:932d8b4e52c9 93 n_dev++;
johnAlexander 15:932d8b4e52c9 94 }
johnAlexander 9:367d1f390cb2 95
johnAlexander 15:932d8b4e52c9 96 status=sensor_right->InitSensor(NEW_SENSOR_RIGHT_ADDRESS);
johnAlexander 15:932d8b4e52c9 97 if(status) {
johnAlexander 15:932d8b4e52c9 98 delete sensor_right;
johnAlexander 15:932d8b4e52c9 99 delete xshutdown_right;
johnAlexander 15:932d8b4e52c9 100 sensor_right=NULL;
johnAlexander 15:932d8b4e52c9 101 xshutdown_right=NULL;
johnAlexander 15:932d8b4e52c9 102 printf("Sensor right not present\n\r");
johnAlexander 15:932d8b4e52c9 103 } else {
johnAlexander 15:932d8b4e52c9 104 printf("Sensor right present\n\r");
johnAlexander 15:932d8b4e52c9 105 n_dev++;
johnAlexander 15:932d8b4e52c9 106 }
johnAlexander 15:932d8b4e52c9 107
johnAlexander 15:932d8b4e52c9 108 if(n_dev==0)
johnAlexander 15:932d8b4e52c9 109 return 1;
johnAlexander 15:932d8b4e52c9 110 else
johnAlexander 15:932d8b4e52c9 111 return 0;
johnAlexander 0:c523920bcc09 112 }