mm

Dependencies:   VL53L0X

Committer:
johnAlexander
Date:
Mon Aug 07 14:30:21 2017 +0000
Revision:
14:8320b5ff96fa
Parent:
11:ceaa5a026412
Aligned to ARM mbed coding style.

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