Mario

Dependents:   LoRaWANdemoUnina LoRaWANdemo72 LoRaWANRadiation Sensor_shield ... more

Committer:
salvatoregulfo
Date:
Tue Oct 03 12:21:11 2017 +0000
Revision:
0:98c301bb7d1b
Mario Conti

Who changed what in which revision?

UserRevisionLine numberNew contents of line
salvatoregulfo 0:98c301bb7d1b 1 /**
salvatoregulfo 0:98c301bb7d1b 2 ******************************************************************************
salvatoregulfo 0:98c301bb7d1b 3 * @file XNucleoIKS01A2.cpp
salvatoregulfo 0:98c301bb7d1b 4 * @author CLab
salvatoregulfo 0:98c301bb7d1b 5 * @version V1.0.0
salvatoregulfo 0:98c301bb7d1b 6 * @date 9-August-2016
salvatoregulfo 0:98c301bb7d1b 7 * @brief Implementation file for the X_NUCLEO_IKS01A2 singleton class
salvatoregulfo 0:98c301bb7d1b 8 ******************************************************************************
salvatoregulfo 0:98c301bb7d1b 9 * @attention
salvatoregulfo 0:98c301bb7d1b 10 *
salvatoregulfo 0:98c301bb7d1b 11 * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
salvatoregulfo 0:98c301bb7d1b 12 *
salvatoregulfo 0:98c301bb7d1b 13 * Redistribution and use in source and binary forms, with or without modification,
salvatoregulfo 0:98c301bb7d1b 14 * are permitted provided that the following conditions are met:
salvatoregulfo 0:98c301bb7d1b 15 * 1. Redistributions of source code must retain the above copyright notice,
salvatoregulfo 0:98c301bb7d1b 16 * this list of conditions and the following disclaimer.
salvatoregulfo 0:98c301bb7d1b 17 * 2. Redistributions in binary form must reproduce the above copyright notice,
salvatoregulfo 0:98c301bb7d1b 18 * this list of conditions and the following disclaimer in the documentation
salvatoregulfo 0:98c301bb7d1b 19 * and/or other materials provided with the distribution.
salvatoregulfo 0:98c301bb7d1b 20 * 3. Neither the name of STMicroelectronics nor the names of its contributors
salvatoregulfo 0:98c301bb7d1b 21 * may be used to endorse or promote products derived from this software
salvatoregulfo 0:98c301bb7d1b 22 * without specific prior written permission.
salvatoregulfo 0:98c301bb7d1b 23 *
salvatoregulfo 0:98c301bb7d1b 24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
salvatoregulfo 0:98c301bb7d1b 25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
salvatoregulfo 0:98c301bb7d1b 26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
salvatoregulfo 0:98c301bb7d1b 27 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
salvatoregulfo 0:98c301bb7d1b 28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
salvatoregulfo 0:98c301bb7d1b 29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
salvatoregulfo 0:98c301bb7d1b 30 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
salvatoregulfo 0:98c301bb7d1b 31 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
salvatoregulfo 0:98c301bb7d1b 32 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
salvatoregulfo 0:98c301bb7d1b 33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
salvatoregulfo 0:98c301bb7d1b 34 *
salvatoregulfo 0:98c301bb7d1b 35 ******************************************************************************
salvatoregulfo 0:98c301bb7d1b 36 */
salvatoregulfo 0:98c301bb7d1b 37
salvatoregulfo 0:98c301bb7d1b 38 /* Includes ------------------------------------------------------------------*/
salvatoregulfo 0:98c301bb7d1b 39 #include "mbed.h"
salvatoregulfo 0:98c301bb7d1b 40 #include "XNucleoIKS01A2.h"
salvatoregulfo 0:98c301bb7d1b 41
salvatoregulfo 0:98c301bb7d1b 42 /* Static variables ----------------------------------------------------------*/
salvatoregulfo 0:98c301bb7d1b 43 XNucleoIKS01A2 *XNucleoIKS01A2::_instance = NULL;
salvatoregulfo 0:98c301bb7d1b 44
salvatoregulfo 0:98c301bb7d1b 45
salvatoregulfo 0:98c301bb7d1b 46 /* Methods -------------------------------------------------------------------*/
salvatoregulfo 0:98c301bb7d1b 47 /**
salvatoregulfo 0:98c301bb7d1b 48 * @brief Constructor
salvatoregulfo 0:98c301bb7d1b 49 */
salvatoregulfo 0:98c301bb7d1b 50 XNucleoIKS01A2::XNucleoIKS01A2(DevI2C *ext_i2c, PinName int1, PinName int2) : dev_i2c(ext_i2c),
salvatoregulfo 0:98c301bb7d1b 51 ht_sensor(new HTS221Sensor(*dev_i2c)),
salvatoregulfo 0:98c301bb7d1b 52 magnetometer(new LSM303AGRMagSensor(*dev_i2c)),
salvatoregulfo 0:98c301bb7d1b 53 accelerometer(new LSM303AGRAccSensor(*dev_i2c)),
salvatoregulfo 0:98c301bb7d1b 54 pt_sensor(new LPS22HBSensor(*dev_i2c)),
salvatoregulfo 0:98c301bb7d1b 55 acc_gyro(new LSM6DSLSensor(*dev_i2c, int1, int2))
salvatoregulfo 0:98c301bb7d1b 56 {
salvatoregulfo 0:98c301bb7d1b 57 ht_sensor->init(NULL);
salvatoregulfo 0:98c301bb7d1b 58 magnetometer->init(NULL);
salvatoregulfo 0:98c301bb7d1b 59 accelerometer->init(NULL);
salvatoregulfo 0:98c301bb7d1b 60 pt_sensor->init(NULL);
salvatoregulfo 0:98c301bb7d1b 61 acc_gyro->init(NULL);
salvatoregulfo 0:98c301bb7d1b 62 }
salvatoregulfo 0:98c301bb7d1b 63
salvatoregulfo 0:98c301bb7d1b 64 /**
salvatoregulfo 0:98c301bb7d1b 65 * @brief Get singleton instance
salvatoregulfo 0:98c301bb7d1b 66 * @return a pointer to the initialized singleton instance of class XNucleoIKS01A2.
salvatoregulfo 0:98c301bb7d1b 67 * A return value of NULL indicates an out of memory situation.
salvatoregulfo 0:98c301bb7d1b 68 * @param[in] ext_i2c (optional) pointer to an instance of DevI2C to be used
salvatoregulfo 0:98c301bb7d1b 69 * for communication on the expansion board.
salvatoregulfo 0:98c301bb7d1b 70 * Defaults to NULL.
salvatoregulfo 0:98c301bb7d1b 71 * Taken into account only on the very first call of one of the 'Instance' functions.
salvatoregulfo 0:98c301bb7d1b 72 * If not provided a new DevI2C will be created with standard
salvatoregulfo 0:98c301bb7d1b 73 * configuration parameters.
salvatoregulfo 0:98c301bb7d1b 74 * The used DevI2C object gets saved in instance variable dev_i2c.
salvatoregulfo 0:98c301bb7d1b 75 * @param[in] int1 LSM6DSL INT1 pin.
salvatoregulfo 0:98c301bb7d1b 76 * Taken into account only on the very first call of one of the 'Instance' functions.
salvatoregulfo 0:98c301bb7d1b 77 * It maps the INT1 pin for LSM6DSL. Defaults to IKS01A2_PIN_LSM6DSL_INT1.
salvatoregulfo 0:98c301bb7d1b 78 * @param[in] int2 LSM6DSL INT1 pin.
salvatoregulfo 0:98c301bb7d1b 79 * Taken into account only on the very first call of one of the 'Instance' functions.
salvatoregulfo 0:98c301bb7d1b 80 * It maps the INT2 pin for LSM6DSL. Defaults to IKS01A2_PIN_LSM6DSL_INT2.
salvatoregulfo 0:98c301bb7d1b 81 */
salvatoregulfo 0:98c301bb7d1b 82 XNucleoIKS01A2 *XNucleoIKS01A2::instance(DevI2C *ext_i2c, PinName int1, PinName int2) {
salvatoregulfo 0:98c301bb7d1b 83 if(_instance == NULL) {
salvatoregulfo 0:98c301bb7d1b 84 if(ext_i2c == NULL)
salvatoregulfo 0:98c301bb7d1b 85 ext_i2c = new DevI2C(IKS01A2_PIN_I2C_SDA, IKS01A2_PIN_I2C_SCL);
salvatoregulfo 0:98c301bb7d1b 86
salvatoregulfo 0:98c301bb7d1b 87 if(ext_i2c != NULL)
salvatoregulfo 0:98c301bb7d1b 88 _instance = new XNucleoIKS01A2(ext_i2c, int1, int2);
salvatoregulfo 0:98c301bb7d1b 89 }
salvatoregulfo 0:98c301bb7d1b 90
salvatoregulfo 0:98c301bb7d1b 91 return _instance;
salvatoregulfo 0:98c301bb7d1b 92 }
salvatoregulfo 0:98c301bb7d1b 93
salvatoregulfo 0:98c301bb7d1b 94 /**
salvatoregulfo 0:98c301bb7d1b 95 * @brief Get singleton instance
salvatoregulfo 0:98c301bb7d1b 96 * @return a pointer to the initialized singleton instance of class X_NUCLEO_IKS01A1.
salvatoregulfo 0:98c301bb7d1b 97 * A return value of NULL indicates an out of memory situation.
salvatoregulfo 0:98c301bb7d1b 98 * @param[in] sda I2C data line pin.
salvatoregulfo 0:98c301bb7d1b 99 * Taken into account only on the very first call of one of the 'Instance' functions.
salvatoregulfo 0:98c301bb7d1b 100 * A new DevI2C will be created based on parameters 'sda' and 'scl'.
salvatoregulfo 0:98c301bb7d1b 101 * The used DevI2C object gets saved in instance variable dev_i2c.
salvatoregulfo 0:98c301bb7d1b 102 * @param[in] scl I2C clock line pin.
salvatoregulfo 0:98c301bb7d1b 103 * Taken into account only on the very first call of one of the 'Instance' functions.
salvatoregulfo 0:98c301bb7d1b 104 * A new DevI2C will be created based on parameters 'sda' and 'scl'.
salvatoregulfo 0:98c301bb7d1b 105 * The used DevI2C object gets saved in instance variable dev_i2c.
salvatoregulfo 0:98c301bb7d1b 106 * @param[in] int1 LSM6DSL INT1 pin.
salvatoregulfo 0:98c301bb7d1b 107 * Taken into account only on the very first call of one of the 'Instance' functions.
salvatoregulfo 0:98c301bb7d1b 108 * It maps the INT1 pin for LSM6DSL. Defaults to IKS01A2_PIN_LSM6DSL_INT1.
salvatoregulfo 0:98c301bb7d1b 109 * @param[in] int2 LSM6DSL INT1 pin.
salvatoregulfo 0:98c301bb7d1b 110 * Taken into account only on the very first call of one of the 'Instance' functions.
salvatoregulfo 0:98c301bb7d1b 111 * It maps the INT2 pin for LSM6DSL. Defaults to IKS01A2_PIN_LSM6DSL_INT2.
salvatoregulfo 0:98c301bb7d1b 112 */
salvatoregulfo 0:98c301bb7d1b 113 XNucleoIKS01A2 *XNucleoIKS01A2::instance(PinName sda, PinName scl, PinName int1, PinName int2) {
salvatoregulfo 0:98c301bb7d1b 114 if(_instance == NULL) {
salvatoregulfo 0:98c301bb7d1b 115 DevI2C *ext_i2c = new DevI2C(sda, scl);
salvatoregulfo 0:98c301bb7d1b 116
salvatoregulfo 0:98c301bb7d1b 117 if(ext_i2c != NULL)
salvatoregulfo 0:98c301bb7d1b 118 _instance = new XNucleoIKS01A2(ext_i2c, int1, int2);
salvatoregulfo 0:98c301bb7d1b 119 }
salvatoregulfo 0:98c301bb7d1b 120
salvatoregulfo 0:98c301bb7d1b 121 return _instance;
salvatoregulfo 0:98c301bb7d1b 122 }