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:
Thu Jun 22 09:55:10 2017 +0000
Revision:
16:98ce55ddbb1a
Parent:
15:932d8b4e52c9
further code refactoring with resharper & astyle.; removal of deprecated interfaces.

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