Suppressed conflicting destructor function.

Dependencies:   X_NUCLEO_COMMON ST_INTERFACES

Dependents:   D7A_1x_TRAINING D7_MLX_AND_BAT D7A_1x_demo_sensors_v3

Fork of X_NUCLEO_IKS01A1 by ST

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers LSM303C_ACC_Sensor.h Source File

LSM303C_ACC_Sensor.h

Go to the documentation of this file.
00001 /**
00002  ******************************************************************************
00003  * @file    LSM303C_ACC_Sensor.h
00004  * @author  CLab
00005  * @version V1.0.0
00006  * @date    5 August 2016
00007  * @brief   Abstract Class of an LSM303C accelerometer sensor.
00008  ******************************************************************************
00009  * @attention
00010  *
00011  * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
00012  *
00013  * Redistribution and use in source and binary forms, with or without modification,
00014  * are permitted provided that the following conditions are met:
00015  *   1. Redistributions of source code must retain the above copyright notice,
00016  *      this list of conditions and the following disclaimer.
00017  *   2. Redistributions in binary form must reproduce the above copyright notice,
00018  *      this list of conditions and the following disclaimer in the documentation
00019  *      and/or other materials provided with the distribution.
00020  *   3. Neither the name of STMicroelectronics nor the names of its contributors
00021  *      may be used to endorse or promote products derived from this software
00022  *      without specific prior written permission.
00023  *
00024  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00025  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00026  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00027  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
00028  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00029  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00030  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00031  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00032  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00033  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00034  *
00035  ******************************************************************************
00036  */
00037 
00038 
00039 /* Prevent recursive inclusion -----------------------------------------------*/
00040 
00041 #ifndef __LSM303C_ACC_Sensor_H__
00042 #define __LSM303C_ACC_Sensor_H__
00043 
00044 
00045 /* Includes ------------------------------------------------------------------*/
00046 
00047 #include "DevI2C.h"
00048 #include "LSM303C_ACC_driver.h"
00049 #include "MotionSensor.h"
00050 
00051 /* Defines -------------------------------------------------------------------*/
00052 #define LSM303C_ACC_SENSITIVITY_FOR_FS_2G_NORMAL_MODE               3.900f  /**< Sensitivity value for 2 g full scale and normal mode [mg/LSB] */
00053 #define LSM303C_ACC_SENSITIVITY_FOR_FS_2G_HIGH_RESOLUTION_MODE      0.980f  /**< Sensitivity value for 2 g full scale and high resolution mode [mg/LSB] */
00054 #define LSM303C_ACC_SENSITIVITY_FOR_FS_2G_LOW_POWER_MODE           15.630f  /**< Sensitivity value for 2 g full scale and low power mode [mg/LSB] */
00055 #define LSM303C_ACC_SENSITIVITY_FOR_FS_4G_NORMAL_MODE               7.820f  /**< Sensitivity value for 4 g full scale and normal mode [mg/LSB] */
00056 #define LSM303C_ACC_SENSITIVITY_FOR_FS_4G_HIGH_RESOLUTION_MODE      1.950f  /**< Sensitivity value for 4 g full scale and high resolution mode [mg/LSB] */
00057 #define LSM303C_ACC_SENSITIVITY_FOR_FS_4G_LOW_POWER_MODE           31.260f  /**< Sensitivity value for 4 g full scale and low power mode [mg/LSB] */
00058 #define LSM303C_ACC_SENSITIVITY_FOR_FS_8G_NORMAL_MODE              15.630f  /**< Sensitivity value for 8 g full scale and normal mode [mg/LSB] */
00059 #define LSM303C_ACC_SENSITIVITY_FOR_FS_8G_HIGH_RESOLUTION_MODE      3.900f  /**< Sensitivity value for 8 g full scale and high resolution mode [mg/LSB] */
00060 #define LSM303C_ACC_SENSITIVITY_FOR_FS_8G_LOW_POWER_MODE           62.520f  /**< Sensitivity value for 8 g full scale and low power mode [mg/LSB] */
00061 #define LSM303C_ACC_SENSITIVITY_FOR_FS_16G_NORMAL_MODE             46.900f  /**< Sensitivity value for 16 g full scale and normal mode [mg/LSB] */
00062 #define LSM303C_ACC_SENSITIVITY_FOR_FS_16G_HIGH_RESOLUTION_MODE    11.720f  /**< Sensitivity value for 16 g full scale and high resolution mode [mg/LSB] */
00063 #define LSM303C_ACC_SENSITIVITY_FOR_FS_16G_LOW_POWER_MODE         187.580f  /**< Sensitivity value for 16 g full scale and low power mode [mg/LSB] */
00064 
00065 /* Class Declaration ---------------------------------------------------------*/
00066 
00067 /**
00068  * Abstract class of an LSM303C Inertial Measurement Unit (IMU) 6 axes
00069  * sensor.
00070  */
00071 class LSM303C_ACC_Sensor : public MotionSensor
00072 {
00073   public:
00074     LSM303C_ACC_Sensor(DevI2C &i2c);
00075     LSM303C_ACC_Sensor(DevI2C &i2c, uint8_t address);
00076     virtual int Init(void *init);
00077     virtual int ReadID(uint8_t *id);
00078     virtual int Get_X_Axes(int32_t *pData);
00079     virtual int Get_X_AxesRaw(int16_t *pData);
00080     virtual int Get_X_Sensitivity(float *pfData);
00081     virtual int Get_X_ODR(float *odr);
00082     virtual int Set_X_ODR(float odr);
00083     virtual int Get_X_FS(float *fullScale);
00084     virtual int Set_X_FS(float fullScale);
00085     int Enable(void);
00086     int Disable(void);
00087     int ReadReg(uint8_t reg, uint8_t *data);
00088     int WriteReg(uint8_t reg, uint8_t data);
00089     
00090     /**
00091      * @brief Utility function to read data.
00092      * @param  pBuffer: pointer to data to be read.
00093      * @param  RegisterAddr: specifies internal address register to be read.
00094      * @param  NumByteToRead: number of bytes to be read.
00095      * @retval 0 if ok, an error code otherwise.
00096      */
00097     uint8_t IO_Read(uint8_t* pBuffer, uint8_t RegisterAddr, uint16_t NumByteToRead)
00098     {
00099         return (uint8_t) dev_i2c.i2c_read(pBuffer, address, RegisterAddr, NumByteToRead);
00100     }
00101     
00102     /**
00103      * @brief Utility function to write data.
00104      * @param  pBuffer: pointer to data to be written.
00105      * @param  RegisterAddr: specifies internal address register to be written.
00106      * @param  NumByteToWrite: number of bytes to write.
00107      * @retval 0 if ok, an error code otherwise.
00108      */
00109     uint8_t IO_Write(uint8_t* pBuffer, uint8_t RegisterAddr, uint16_t NumByteToWrite)
00110     {
00111         return (uint8_t) dev_i2c.i2c_write(pBuffer, address, RegisterAddr, NumByteToWrite);
00112     }
00113 
00114   private:
00115     int Set_X_ODR_When_Enabled(float odr);
00116     int Set_X_ODR_When_Disabled(float odr);
00117     int Get_X_Sensitivity_Normal_Mode(float *sensitivity );
00118     int Get_X_Sensitivity_LP_Mode(float *sensitivity );
00119     int Get_X_Sensitivity_HR_Mode(float *sensitivity );
00120 
00121     /* Helper classes. */
00122     DevI2C &dev_i2c;
00123     
00124     /* Configuration */
00125     uint8_t address;
00126     
00127     uint8_t isEnabled;
00128     float Last_ODR;
00129 };
00130 
00131 #ifdef __cplusplus
00132  extern "C" {
00133 #endif
00134 uint8_t LSM303C_ACC_IO_Write( void *handle, uint8_t WriteAddr, uint8_t *pBuffer, uint16_t nBytesToWrite );
00135 uint8_t LSM303C_ACC_IO_Read( void *handle, uint8_t ReadAddr, uint8_t *pBuffer, uint16_t nBytesToRead );
00136 #ifdef __cplusplus
00137   }
00138 #endif
00139 
00140 #endif