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:
Wed Jun 07 12:53:53 2017 +0000
Revision:
9:367d1f390cb2
Parent:
2:58b5e9097aa3
Child:
11:ceaa5a026412
Enable support for left and right sensors. Tested with mbed_143.

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 0:c523920bcc09 47 if(_instance==NULL)
johnAlexander 0:c523920bcc09 48 _instance=new X_NUCLEO_53L0A1(ext_i2c);
johnAlexander 0:c523920bcc09 49 else
johnAlexander 0:c523920bcc09 50 VL53L0X_ErrLog("Failed to create X_NUCLEO_53L0A1 instance\n\r");
johnAlexander 0:c523920bcc09 51 return _instance;
johnAlexander 0:c523920bcc09 52 }
johnAlexander 0:c523920bcc09 53
johnAlexander 0:c523920bcc09 54 X_NUCLEO_53L0A1* X_NUCLEO_53L0A1::Instance(DevI2C *ext_i2c,
johnAlexander 0:c523920bcc09 55 PinName gpio1_centre,
johnAlexander 0:c523920bcc09 56 PinName gpio1_left, PinName gpio1_right)
johnAlexander 0:c523920bcc09 57 {
johnAlexander 0:c523920bcc09 58 if(_instance==NULL)
johnAlexander 0:c523920bcc09 59 _instance=new X_NUCLEO_53L0A1(ext_i2c, gpio1_centre, gpio1_left, gpio1_right);
johnAlexander 0:c523920bcc09 60 else
johnAlexander 0:c523920bcc09 61 VL53L0X_ErrLog("Failed to create X_NUCLEO_53L0A1 instance\n\r");
johnAlexander 0:c523920bcc09 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 0:c523920bcc09 67 {
johnAlexander 0:c523920bcc09 68 int status, n_dev=0;
johnAlexander 0:c523920bcc09 69
johnAlexander 0:c523920bcc09 70 sensor_centre->VL53L0X_Off();
johnAlexander 1:01b8004bc0a7 71 sensor_left->VL53L0X_Off();
johnAlexander 1:01b8004bc0a7 72 sensor_right->VL53L0X_Off();
johnAlexander 0:c523920bcc09 73 status=sensor_centre->InitSensor(NEW_SENSOR_CENTRE_ADDRESS);
johnAlexander 0:c523920bcc09 74 if(status)
johnAlexander 0:c523920bcc09 75 {
johnAlexander 0:c523920bcc09 76 delete sensor_centre;
johnAlexander 0:c523920bcc09 77 delete xshutdown_centre;
johnAlexander 0:c523920bcc09 78 sensor_centre=NULL;
johnAlexander 0:c523920bcc09 79 xshutdown_centre=NULL;
johnAlexander 0:c523920bcc09 80 printf("Sensor centre not present\n\r");
johnAlexander 0:c523920bcc09 81 }
johnAlexander 0:c523920bcc09 82 else
johnAlexander 0:c523920bcc09 83 {
johnAlexander 0:c523920bcc09 84 printf("Sensor centre present\n\r");
johnAlexander 0:c523920bcc09 85 n_dev++;
johnAlexander 0:c523920bcc09 86 }
johnAlexander 9:367d1f390cb2 87 status=sensor_left->InitSensor(NEW_SENSOR_LEFT_ADDRESS);
johnAlexander 0:c523920bcc09 88 if(status)
johnAlexander 0:c523920bcc09 89 {
johnAlexander 0:c523920bcc09 90 delete sensor_left;
johnAlexander 0:c523920bcc09 91 delete xshutdown_left;
johnAlexander 0:c523920bcc09 92 sensor_left=NULL;
johnAlexander 0:c523920bcc09 93 xshutdown_left=NULL;
johnAlexander 0:c523920bcc09 94 printf("Sensor left not present\n\r");
johnAlexander 0:c523920bcc09 95 }
johnAlexander 0:c523920bcc09 96 else
johnAlexander 0:c523920bcc09 97 {
johnAlexander 0:c523920bcc09 98 printf("Sensor left present\n\r");
johnAlexander 0:c523920bcc09 99 n_dev++;
johnAlexander 0:c523920bcc09 100 }
johnAlexander 9:367d1f390cb2 101
johnAlexander 9:367d1f390cb2 102 status=sensor_right->InitSensor(NEW_SENSOR_RIGHT_ADDRESS);
johnAlexander 0:c523920bcc09 103 if(status)
johnAlexander 0:c523920bcc09 104 {
johnAlexander 0:c523920bcc09 105 delete sensor_right;
johnAlexander 0:c523920bcc09 106 delete xshutdown_right;
johnAlexander 0:c523920bcc09 107 sensor_right=NULL;
johnAlexander 0:c523920bcc09 108 xshutdown_right=NULL;
johnAlexander 0:c523920bcc09 109 printf("Sensor right not present\n\r");
johnAlexander 0:c523920bcc09 110 }
johnAlexander 0:c523920bcc09 111 else
johnAlexander 0:c523920bcc09 112 {
johnAlexander 0:c523920bcc09 113 printf("Sensor right present\n\r");
johnAlexander 0:c523920bcc09 114 n_dev++;
johnAlexander 0:c523920bcc09 115 }
johnAlexander 9:367d1f390cb2 116
johnAlexander 0:c523920bcc09 117 if(n_dev==0)
johnAlexander 0:c523920bcc09 118 return 1;
johnAlexander 0:c523920bcc09 119 else
johnAlexander 0:c523920bcc09 120 return 0;
johnAlexander 0:c523920bcc09 121 }
johnAlexander 0:c523920bcc09 122