INSAT Mini Project

Dependencies:   ST_INTERFACES X_NUCLEO_COMMON

Fork of X_NUCLEO_6180XA1 by ST

Committer:
licio.mapelli@st.com
Date:
Tue Jun 07 14:56:36 2016 +0200
Revision:
48:e799ad44dab7
Parent:
46:116dadbc80f1
Child:
54:17f3bb228b13
Fixed I2C address in component descriptor to default val after component PowerOn/Off.
Overridden singleton obj fake copy constructor and (=) assignement operator to avoid multiple singleton instances.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
gallonm 10:4954b09b72d8 1 /**
gallonm 10:4954b09b72d8 2 ******************************************************************************
gallonm 10:4954b09b72d8 3 * @file x_nucleo_6180xa1.cpp
gallonm 10:4954b09b72d8 4 * @author AST / EST
gallonm 10:4954b09b72d8 5 * @version V0.0.1
gallonm 10:4954b09b72d8 6 * @date 13-April-2015
gallonm 10:4954b09b72d8 7 * @brief Implementation file for the X_NUCLEO_VL6180XA1 singleton class
gallonm 10:4954b09b72d8 8 ******************************************************************************
gallonm 10:4954b09b72d8 9 * @attention
gallonm 10:4954b09b72d8 10 *
gallonm 10:4954b09b72d8 11 * <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
gallonm 10:4954b09b72d8 12 *
gallonm 10:4954b09b72d8 13 * Redistribution and use in source and binary forms, with or without modification,
gallonm 10:4954b09b72d8 14 * are permitted provided that the following conditions are met:
gallonm 10:4954b09b72d8 15 * 1. Redistributions of source code must retain the above copyright notice,
gallonm 10:4954b09b72d8 16 * this list of conditions and the following disclaimer.
gallonm 10:4954b09b72d8 17 * 2. Redistributions in binary form must reproduce the above copyright notice,
gallonm 10:4954b09b72d8 18 * this list of conditions and the following disclaimer in the documentation
gallonm 10:4954b09b72d8 19 * and/or other materials provided with the distribution.
gallonm 10:4954b09b72d8 20 * 3. Neither the name of STMicroelectronics nor the names of its contributors
gallonm 10:4954b09b72d8 21 * may be used to endorse or promote products derived from this software
gallonm 10:4954b09b72d8 22 * without specific prior written permission.
gallonm 10:4954b09b72d8 23 *
gallonm 10:4954b09b72d8 24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
gallonm 10:4954b09b72d8 25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
gallonm 10:4954b09b72d8 26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
gallonm 10:4954b09b72d8 27 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
gallonm 10:4954b09b72d8 28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
gallonm 10:4954b09b72d8 29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
gallonm 10:4954b09b72d8 30 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
gallonm 10:4954b09b72d8 31 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
gallonm 10:4954b09b72d8 32 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
gallonm 10:4954b09b72d8 33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
gallonm 10:4954b09b72d8 34 *
gallonm 10:4954b09b72d8 35 ******************************************************************************
gallonm 10:4954b09b72d8 36 */
gallonm 10:4954b09b72d8 37
gallonm 10:4954b09b72d8 38
gallonm 10:4954b09b72d8 39 /* Includes ------------------------------------------------------------------*/
gallonm 10:4954b09b72d8 40 #include "x_nucleo_6180xa1.h"
gallonm 10:4954b09b72d8 41
gallonm 10:4954b09b72d8 42 /* Static variables ----------------------------------------------------------*/
gallonm 10:4954b09b72d8 43 X_NUCLEO_6180XA1* X_NUCLEO_6180XA1::_instance = NULL;
gallonm 10:4954b09b72d8 44
gallonm 10:4954b09b72d8 45 X_NUCLEO_6180XA1* X_NUCLEO_6180XA1::Instance(DevI2C *ext_i2c)
gallonm 10:4954b09b72d8 46 {
gallonm 16:0d4776564733 47 if(_instance==NULL)
gallonm 16:0d4776564733 48 _instance=new X_NUCLEO_6180XA1(ext_i2c);
gallonm 16:0d4776564733 49 else
gallonm 28:7c9031e96c22 50 VL6180x_ErrLog("Failed to create X_NUCLEO_6180XA1 instance\n\r");
gallonm 16:0d4776564733 51 return _instance;
gallonm 10:4954b09b72d8 52 }
gallonm 10:4954b09b72d8 53
mapellil 36:f6278b3e7c82 54 X_NUCLEO_6180XA1* X_NUCLEO_6180XA1::Instance(DevI2C *ext_i2c,
mapellil 36:f6278b3e7c82 55 PinName gpio1_top, PinName gpio1_bottom,
mapellil 36:f6278b3e7c82 56 PinName gpio1_left, PinName gpio1_right)
mapellil 36:f6278b3e7c82 57 {
mapellil 36:f6278b3e7c82 58 if(_instance==NULL)
mapellil 36:f6278b3e7c82 59 //_instance=new X_NUCLEO_6180XA1(ext_i2c);
mapellil 36:f6278b3e7c82 60 _instance=new X_NUCLEO_6180XA1(ext_i2c, gpio1_top, gpio1_bottom, gpio1_left, gpio1_right);
mapellil 36:f6278b3e7c82 61 else
mapellil 36:f6278b3e7c82 62 VL6180x_ErrLog("Failed to create X_NUCLEO_6180XA1 instance\n\r");
mapellil 36:f6278b3e7c82 63 return _instance;
mapellil 36:f6278b3e7c82 64 }
mapellil 36:f6278b3e7c82 65
gallonm 10:4954b09b72d8 66
gallonm 20:dd8390d615bf 67 int X_NUCLEO_6180XA1::InitBoard()
gallonm 10:4954b09b72d8 68 {
mapellil 46:116dadbc80f1 69 int status, n_dev=0; uint8_t sensor_address;
gallonm 15:454710d17358 70
licio.mapelli@st.com 48:e799ad44dab7 71 sensor_top->VL6180x_Off();
licio.mapelli@st.com 48:e799ad44dab7 72 sensor_bottom->VL6180x_Off();
licio.mapelli@st.com 48:e799ad44dab7 73 sensor_left->VL6180x_Off();
licio.mapelli@st.com 48:e799ad44dab7 74 sensor_right->VL6180x_Off();
licio.mapelli@st.com 48:e799ad44dab7 75 sensor_address = NEW_SENSOR_TOP_ADDRESS;
licio.mapelli@st.com 48:e799ad44dab7 76 status=sensor_top->Init(&sensor_address);
licio.mapelli@st.com 48:e799ad44dab7 77 if(status)
licio.mapelli@st.com 48:e799ad44dab7 78 {
licio.mapelli@st.com 48:e799ad44dab7 79 printf("Sensor top not present\n\r");
licio.mapelli@st.com 48:e799ad44dab7 80 }
licio.mapelli@st.com 48:e799ad44dab7 81 else
licio.mapelli@st.com 48:e799ad44dab7 82 {
licio.mapelli@st.com 48:e799ad44dab7 83 printf("Sensor top present\n\r");
licio.mapelli@st.com 48:e799ad44dab7 84 n_dev++;
licio.mapelli@st.com 48:e799ad44dab7 85 }
licio.mapelli@st.com 48:e799ad44dab7 86 sensor_address = NEW_SENSOR_BOTTOM_ADDRESS;
licio.mapelli@st.com 48:e799ad44dab7 87 status=sensor_bottom->Init(&sensor_address);
licio.mapelli@st.com 48:e799ad44dab7 88 if(status)
licio.mapelli@st.com 48:e799ad44dab7 89 {
licio.mapelli@st.com 48:e799ad44dab7 90 printf("Sensor bottom not present\n\r");
licio.mapelli@st.com 48:e799ad44dab7 91 }
licio.mapelli@st.com 48:e799ad44dab7 92 else
licio.mapelli@st.com 48:e799ad44dab7 93 {
licio.mapelli@st.com 48:e799ad44dab7 94 printf("Sensor bottom present\n\r");
licio.mapelli@st.com 48:e799ad44dab7 95 n_dev++;
licio.mapelli@st.com 48:e799ad44dab7 96 }
licio.mapelli@st.com 48:e799ad44dab7 97 sensor_address = NEW_SENSOR_LEFT_ADDRESS;
licio.mapelli@st.com 48:e799ad44dab7 98 status=sensor_left->Init(&sensor_address);
licio.mapelli@st.com 48:e799ad44dab7 99 if(status)
licio.mapelli@st.com 48:e799ad44dab7 100 {
licio.mapelli@st.com 48:e799ad44dab7 101 printf("Sensor left not present\n\r");
licio.mapelli@st.com 48:e799ad44dab7 102 }
licio.mapelli@st.com 48:e799ad44dab7 103 else
licio.mapelli@st.com 48:e799ad44dab7 104 {
licio.mapelli@st.com 48:e799ad44dab7 105 printf("Sensor left present\n\r");
licio.mapelli@st.com 48:e799ad44dab7 106 n_dev++;
licio.mapelli@st.com 48:e799ad44dab7 107 }
licio.mapelli@st.com 48:e799ad44dab7 108 sensor_address = NEW_SENSOR_RIGHT_ADDRESS;
licio.mapelli@st.com 48:e799ad44dab7 109 status=sensor_right->Init(&sensor_address);
licio.mapelli@st.com 48:e799ad44dab7 110 if(status)
licio.mapelli@st.com 48:e799ad44dab7 111 {
licio.mapelli@st.com 48:e799ad44dab7 112 printf("Sensor right not present\n\r");
licio.mapelli@st.com 48:e799ad44dab7 113 }
licio.mapelli@st.com 48:e799ad44dab7 114 else
licio.mapelli@st.com 48:e799ad44dab7 115 {
licio.mapelli@st.com 48:e799ad44dab7 116 printf("Sensor right present\n\r");
licio.mapelli@st.com 48:e799ad44dab7 117 n_dev++;
licio.mapelli@st.com 48:e799ad44dab7 118 }
gallonm 16:0d4776564733 119 if(n_dev==0)
gallonm 16:0d4776564733 120 return 1;
gallonm 16:0d4776564733 121 else
gallonm 16:0d4776564733 122 return 0;
gallonm 10:4954b09b72d8 123 }
gallonm 10:4954b09b72d8 124
gallonm 10:4954b09b72d8 125