Example of free fall detection for LSM6DSL in X-NUCLEO-IKS01A2

Dependencies:   X_NUCLEO_IKS01A2 mbed

Fork of FreeFall_IKS01A2 by ST Expansion SW Team

Free Fall Detection Demo Application based on sensor expansion board X-NUCLEO-IKS01A2

Main function is to show how to detect the free fall event using the sensor expansion board and send a notification using UART to a connected PC or Desktop and display it on terminal applications like TeraTerm.
After connection has been established:
- the user can try to leave falling the board and then view the notification using an hyper terminal. When the free fall is detected, the LED is switched on for a while.
- the user button can be used to enable/disable the free fall detection feature.

Committer:
cparata
Date:
Fri Aug 12 13:39:06 2016 +0000
Revision:
0:6a670fda63c2
First release of Free Fall for LSM6DSL in IKS01A2

Who changed what in which revision?

UserRevisionLine numberNew contents of line
cparata 0:6a670fda63c2 1 /**
cparata 0:6a670fda63c2 2 ******************************************************************************
cparata 0:6a670fda63c2 3 * @file LSM303AGR_MAG_Sensor.cpp
cparata 0:6a670fda63c2 4 * @author AST
cparata 0:6a670fda63c2 5 * @version V1.0.0
cparata 0:6a670fda63c2 6 * @date 5 August 2016
cparata 0:6a670fda63c2 7 * @brief Implementation an LSM303AGR magnetometer sensor.
cparata 0:6a670fda63c2 8 ******************************************************************************
cparata 0:6a670fda63c2 9 * @attention
cparata 0:6a670fda63c2 10 *
cparata 0:6a670fda63c2 11 * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
cparata 0:6a670fda63c2 12 *
cparata 0:6a670fda63c2 13 * Redistribution and use in source and binary forms, with or without modification,
cparata 0:6a670fda63c2 14 * are permitted provided that the following conditions are met:
cparata 0:6a670fda63c2 15 * 1. Redistributions of source code must retain the above copyright notice,
cparata 0:6a670fda63c2 16 * this list of conditions and the following disclaimer.
cparata 0:6a670fda63c2 17 * 2. Redistributions in binary form must reproduce the above copyright notice,
cparata 0:6a670fda63c2 18 * this list of conditions and the following disclaimer in the documentation
cparata 0:6a670fda63c2 19 * and/or other materials provided with the distribution.
cparata 0:6a670fda63c2 20 * 3. Neither the name of STMicroelectronics nor the names of its contributors
cparata 0:6a670fda63c2 21 * may be used to endorse or promote products derived from this software
cparata 0:6a670fda63c2 22 * without specific prior written permission.
cparata 0:6a670fda63c2 23 *
cparata 0:6a670fda63c2 24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
cparata 0:6a670fda63c2 25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
cparata 0:6a670fda63c2 26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
cparata 0:6a670fda63c2 27 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
cparata 0:6a670fda63c2 28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
cparata 0:6a670fda63c2 29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
cparata 0:6a670fda63c2 30 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
cparata 0:6a670fda63c2 31 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
cparata 0:6a670fda63c2 32 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
cparata 0:6a670fda63c2 33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
cparata 0:6a670fda63c2 34 *
cparata 0:6a670fda63c2 35 ******************************************************************************
cparata 0:6a670fda63c2 36 */
cparata 0:6a670fda63c2 37
cparata 0:6a670fda63c2 38
cparata 0:6a670fda63c2 39 /* Includes ------------------------------------------------------------------*/
cparata 0:6a670fda63c2 40
cparata 0:6a670fda63c2 41 #include "mbed.h"
cparata 0:6a670fda63c2 42 #include "DevI2C.h"
cparata 0:6a670fda63c2 43 #include "LSM303AGR_MAG_Sensor.h"
cparata 0:6a670fda63c2 44 #include "LSM303AGR_MAG_driver.h"
cparata 0:6a670fda63c2 45
cparata 0:6a670fda63c2 46
cparata 0:6a670fda63c2 47 /* Class Implementation ------------------------------------------------------*/
cparata 0:6a670fda63c2 48
cparata 0:6a670fda63c2 49 /** Constructor
cparata 0:6a670fda63c2 50 * @param i2c object of an helper class which handles the I2C peripheral
cparata 0:6a670fda63c2 51 * @param address the address of the component's instance
cparata 0:6a670fda63c2 52 */
cparata 0:6a670fda63c2 53 LSM303AGR_MAG_Sensor::LSM303AGR_MAG_Sensor(DevI2C &i2c) : dev_i2c(i2c)
cparata 0:6a670fda63c2 54 {
cparata 0:6a670fda63c2 55 address = LSM303AGR_MAG_I2C_ADDRESS;
cparata 0:6a670fda63c2 56
cparata 0:6a670fda63c2 57 /* Operating mode selection - power down */
cparata 0:6a670fda63c2 58 if ( LSM303AGR_MAG_W_MD( (void *)this, LSM303AGR_MAG_MD_IDLE1_MODE ) == MEMS_ERROR )
cparata 0:6a670fda63c2 59 {
cparata 0:6a670fda63c2 60 return;
cparata 0:6a670fda63c2 61 }
cparata 0:6a670fda63c2 62
cparata 0:6a670fda63c2 63 /* Enable BDU */
cparata 0:6a670fda63c2 64 if ( LSM303AGR_MAG_W_BDU( (void *)this, LSM303AGR_MAG_BDU_ENABLED ) == MEMS_ERROR )
cparata 0:6a670fda63c2 65 {
cparata 0:6a670fda63c2 66 return;
cparata 0:6a670fda63c2 67 }
cparata 0:6a670fda63c2 68
cparata 0:6a670fda63c2 69 if ( SetODR( 100.0f ) == LSM303AGR_MAG_STATUS_ERROR )
cparata 0:6a670fda63c2 70 {
cparata 0:6a670fda63c2 71 return;
cparata 0:6a670fda63c2 72 }
cparata 0:6a670fda63c2 73
cparata 0:6a670fda63c2 74 if ( SetFS( 50.0f ) == LSM303AGR_MAG_STATUS_ERROR )
cparata 0:6a670fda63c2 75 {
cparata 0:6a670fda63c2 76 return;
cparata 0:6a670fda63c2 77 }
cparata 0:6a670fda63c2 78
cparata 0:6a670fda63c2 79 if ( LSM303AGR_MAG_W_ST( (void *)this, LSM303AGR_MAG_ST_DISABLED ) == MEMS_ERROR )
cparata 0:6a670fda63c2 80 {
cparata 0:6a670fda63c2 81 return;
cparata 0:6a670fda63c2 82 }
cparata 0:6a670fda63c2 83 };
cparata 0:6a670fda63c2 84
cparata 0:6a670fda63c2 85 /** Constructor
cparata 0:6a670fda63c2 86 * @param i2c object of an helper class which handles the I2C peripheral
cparata 0:6a670fda63c2 87 * @param address the address of the component's instance
cparata 0:6a670fda63c2 88 */
cparata 0:6a670fda63c2 89 LSM303AGR_MAG_Sensor::LSM303AGR_MAG_Sensor(DevI2C &i2c, uint8_t address) : dev_i2c(i2c), address(address)
cparata 0:6a670fda63c2 90 {
cparata 0:6a670fda63c2 91 /* Operating mode selection - power down */
cparata 0:6a670fda63c2 92 if ( LSM303AGR_MAG_W_MD( (void *)this, LSM303AGR_MAG_MD_IDLE1_MODE ) == MEMS_ERROR )
cparata 0:6a670fda63c2 93 {
cparata 0:6a670fda63c2 94 return;
cparata 0:6a670fda63c2 95 }
cparata 0:6a670fda63c2 96
cparata 0:6a670fda63c2 97 /* Enable BDU */
cparata 0:6a670fda63c2 98 if ( LSM303AGR_MAG_W_BDU( (void *)this, LSM303AGR_MAG_BDU_ENABLED ) == MEMS_ERROR )
cparata 0:6a670fda63c2 99 {
cparata 0:6a670fda63c2 100 return;
cparata 0:6a670fda63c2 101 }
cparata 0:6a670fda63c2 102
cparata 0:6a670fda63c2 103 if ( SetODR( 100.0f ) == LSM303AGR_MAG_STATUS_ERROR )
cparata 0:6a670fda63c2 104 {
cparata 0:6a670fda63c2 105 return;
cparata 0:6a670fda63c2 106 }
cparata 0:6a670fda63c2 107
cparata 0:6a670fda63c2 108 if ( SetFS( 50.0f ) == LSM303AGR_MAG_STATUS_ERROR )
cparata 0:6a670fda63c2 109 {
cparata 0:6a670fda63c2 110 return;
cparata 0:6a670fda63c2 111 }
cparata 0:6a670fda63c2 112
cparata 0:6a670fda63c2 113 if ( LSM303AGR_MAG_W_ST( (void *)this, LSM303AGR_MAG_ST_DISABLED ) == MEMS_ERROR )
cparata 0:6a670fda63c2 114 {
cparata 0:6a670fda63c2 115 return;
cparata 0:6a670fda63c2 116 }
cparata 0:6a670fda63c2 117 };
cparata 0:6a670fda63c2 118
cparata 0:6a670fda63c2 119 /**
cparata 0:6a670fda63c2 120 * @brief Enable LSM303AGR magnetometer
cparata 0:6a670fda63c2 121 * @retval LSM303AGR_MAG_STATUS_OK in case of success, an error code otherwise
cparata 0:6a670fda63c2 122 */
cparata 0:6a670fda63c2 123 LSM303AGR_MAG_StatusTypeDef LSM303AGR_MAG_Sensor::Enable(void)
cparata 0:6a670fda63c2 124 {
cparata 0:6a670fda63c2 125 /* Operating mode selection */
cparata 0:6a670fda63c2 126 if ( LSM303AGR_MAG_W_MD( (void *)this, LSM303AGR_MAG_MD_CONTINUOS_MODE ) == MEMS_ERROR )
cparata 0:6a670fda63c2 127 {
cparata 0:6a670fda63c2 128 return LSM303AGR_MAG_STATUS_ERROR;
cparata 0:6a670fda63c2 129 }
cparata 0:6a670fda63c2 130
cparata 0:6a670fda63c2 131 return LSM303AGR_MAG_STATUS_OK;
cparata 0:6a670fda63c2 132 }
cparata 0:6a670fda63c2 133
cparata 0:6a670fda63c2 134 /**
cparata 0:6a670fda63c2 135 * @brief Disable LSM303AGR magnetometer
cparata 0:6a670fda63c2 136 * @retval LSM303AGR_MAG_STATUS_OK in case of success, an error code otherwise
cparata 0:6a670fda63c2 137 */
cparata 0:6a670fda63c2 138 LSM303AGR_MAG_StatusTypeDef LSM303AGR_MAG_Sensor::Disable(void)
cparata 0:6a670fda63c2 139 {
cparata 0:6a670fda63c2 140 /* Operating mode selection - power down */
cparata 0:6a670fda63c2 141 if ( LSM303AGR_MAG_W_MD( (void *)this, LSM303AGR_MAG_MD_IDLE1_MODE ) == MEMS_ERROR )
cparata 0:6a670fda63c2 142 {
cparata 0:6a670fda63c2 143 return LSM303AGR_MAG_STATUS_ERROR;
cparata 0:6a670fda63c2 144 }
cparata 0:6a670fda63c2 145
cparata 0:6a670fda63c2 146 return LSM303AGR_MAG_STATUS_OK;
cparata 0:6a670fda63c2 147 }
cparata 0:6a670fda63c2 148
cparata 0:6a670fda63c2 149 /**
cparata 0:6a670fda63c2 150 * @brief Read ID of LSM303AGR Magnetometer
cparata 0:6a670fda63c2 151 * @param p_id the pointer where the ID of the device is stored
cparata 0:6a670fda63c2 152 * @retval LSM303AGR_MAG_STATUS_OK in case of success, an error code otherwise
cparata 0:6a670fda63c2 153 */
cparata 0:6a670fda63c2 154 LSM303AGR_MAG_StatusTypeDef LSM303AGR_MAG_Sensor::ReadID(uint8_t *p_id)
cparata 0:6a670fda63c2 155 {
cparata 0:6a670fda63c2 156 if(!p_id)
cparata 0:6a670fda63c2 157 {
cparata 0:6a670fda63c2 158 return LSM303AGR_MAG_STATUS_ERROR;
cparata 0:6a670fda63c2 159 }
cparata 0:6a670fda63c2 160
cparata 0:6a670fda63c2 161 /* Read WHO AM I register */
cparata 0:6a670fda63c2 162 if ( LSM303AGR_MAG_R_WHO_AM_I( (void *)this, p_id ) == MEMS_ERROR )
cparata 0:6a670fda63c2 163 {
cparata 0:6a670fda63c2 164 return LSM303AGR_MAG_STATUS_ERROR;
cparata 0:6a670fda63c2 165 }
cparata 0:6a670fda63c2 166
cparata 0:6a670fda63c2 167 return LSM303AGR_MAG_STATUS_OK;
cparata 0:6a670fda63c2 168 }
cparata 0:6a670fda63c2 169
cparata 0:6a670fda63c2 170 /**
cparata 0:6a670fda63c2 171 * @brief Read data from LSM303AGR Magnetometer
cparata 0:6a670fda63c2 172 * @param pData the pointer where the magnetometer data are stored
cparata 0:6a670fda63c2 173 * @retval LSM303AGR_MAG_STATUS_OK in case of success, an error code otherwise
cparata 0:6a670fda63c2 174 */
cparata 0:6a670fda63c2 175 LSM303AGR_MAG_StatusTypeDef LSM303AGR_MAG_Sensor::GetAxes(int32_t *pData)
cparata 0:6a670fda63c2 176 {
cparata 0:6a670fda63c2 177 int16_t pDataRaw[3];
cparata 0:6a670fda63c2 178 float sensitivity = 0;
cparata 0:6a670fda63c2 179
cparata 0:6a670fda63c2 180 /* Read raw data from LSM303AGR output register. */
cparata 0:6a670fda63c2 181 if ( GetAxesRaw( pDataRaw ) == LSM303AGR_MAG_STATUS_ERROR )
cparata 0:6a670fda63c2 182 {
cparata 0:6a670fda63c2 183 return LSM303AGR_MAG_STATUS_ERROR;
cparata 0:6a670fda63c2 184 }
cparata 0:6a670fda63c2 185
cparata 0:6a670fda63c2 186 /* Get LSM303AGR actual sensitivity. */
cparata 0:6a670fda63c2 187 if ( GetSensitivity( &sensitivity ) == LSM303AGR_MAG_STATUS_ERROR )
cparata 0:6a670fda63c2 188 {
cparata 0:6a670fda63c2 189 return LSM303AGR_MAG_STATUS_ERROR;
cparata 0:6a670fda63c2 190 }
cparata 0:6a670fda63c2 191
cparata 0:6a670fda63c2 192 /* Calculate the data. */
cparata 0:6a670fda63c2 193 pData[0] = ( int32_t )( pDataRaw[0] * sensitivity );
cparata 0:6a670fda63c2 194 pData[1] = ( int32_t )( pDataRaw[1] * sensitivity );
cparata 0:6a670fda63c2 195 pData[2] = ( int32_t )( pDataRaw[2] * sensitivity );
cparata 0:6a670fda63c2 196
cparata 0:6a670fda63c2 197 return LSM303AGR_MAG_STATUS_OK;
cparata 0:6a670fda63c2 198 }
cparata 0:6a670fda63c2 199
cparata 0:6a670fda63c2 200 /**
cparata 0:6a670fda63c2 201 * @brief Read Magnetometer Sensitivity
cparata 0:6a670fda63c2 202 * @param pfData the pointer where the magnetometer sensitivity is stored
cparata 0:6a670fda63c2 203 * @retval LSM303AGR_MAG_STATUS_OK in case of success, an error code otherwise
cparata 0:6a670fda63c2 204 */
cparata 0:6a670fda63c2 205 LSM303AGR_MAG_StatusTypeDef LSM303AGR_MAG_Sensor::GetSensitivity(float *pfData)
cparata 0:6a670fda63c2 206 {
cparata 0:6a670fda63c2 207 *pfData = 1.5f;
cparata 0:6a670fda63c2 208
cparata 0:6a670fda63c2 209 return LSM303AGR_MAG_STATUS_OK;
cparata 0:6a670fda63c2 210 }
cparata 0:6a670fda63c2 211
cparata 0:6a670fda63c2 212 /**
cparata 0:6a670fda63c2 213 * @brief Read raw data from LSM303AGR Magnetometer
cparata 0:6a670fda63c2 214 * @param pData the pointer where the magnetomer raw data are stored
cparata 0:6a670fda63c2 215 * @retval LSM303AGR_MAG_STATUS_OK in case of success, an error code otherwise
cparata 0:6a670fda63c2 216 */
cparata 0:6a670fda63c2 217 LSM303AGR_MAG_StatusTypeDef LSM303AGR_MAG_Sensor::GetAxesRaw(int16_t *pData)
cparata 0:6a670fda63c2 218 {
cparata 0:6a670fda63c2 219 uint8_t regValue[6] = {0, 0, 0, 0, 0, 0};
cparata 0:6a670fda63c2 220 int16_t *regValueInt16;
cparata 0:6a670fda63c2 221
cparata 0:6a670fda63c2 222 /* Read output registers from LSM303AGR_MAG_OUTX_L to LSM303AGR_MAG_OUTZ_H. */
cparata 0:6a670fda63c2 223 if ( LSM303AGR_MAG_Get_Raw_Magnetic( (void *)this, regValue ) == MEMS_ERROR )
cparata 0:6a670fda63c2 224 {
cparata 0:6a670fda63c2 225 return LSM303AGR_MAG_STATUS_ERROR;
cparata 0:6a670fda63c2 226 }
cparata 0:6a670fda63c2 227
cparata 0:6a670fda63c2 228 regValueInt16 = (int16_t *)regValue;
cparata 0:6a670fda63c2 229
cparata 0:6a670fda63c2 230 /* Format the data. */
cparata 0:6a670fda63c2 231 pData[0] = regValueInt16[0];
cparata 0:6a670fda63c2 232 pData[1] = regValueInt16[1];
cparata 0:6a670fda63c2 233 pData[2] = regValueInt16[2];
cparata 0:6a670fda63c2 234
cparata 0:6a670fda63c2 235 return LSM303AGR_MAG_STATUS_OK;
cparata 0:6a670fda63c2 236 }
cparata 0:6a670fda63c2 237
cparata 0:6a670fda63c2 238 /**
cparata 0:6a670fda63c2 239 * @brief Read LSM303AGR Magnetometer output data rate
cparata 0:6a670fda63c2 240 * @param odr the pointer to the output data rate
cparata 0:6a670fda63c2 241 * @retval LSM303AGR_MAG_STATUS_OK in case of success, an error code otherwise
cparata 0:6a670fda63c2 242 */
cparata 0:6a670fda63c2 243 LSM303AGR_MAG_StatusTypeDef LSM303AGR_MAG_Sensor::GetODR(float* odr)
cparata 0:6a670fda63c2 244 {
cparata 0:6a670fda63c2 245 LSM303AGR_MAG_ODR_t odr_low_level;
cparata 0:6a670fda63c2 246
cparata 0:6a670fda63c2 247 if ( LSM303AGR_MAG_R_ODR( (void *)this, &odr_low_level ) == MEMS_ERROR )
cparata 0:6a670fda63c2 248 {
cparata 0:6a670fda63c2 249 return LSM303AGR_MAG_STATUS_ERROR;
cparata 0:6a670fda63c2 250 }
cparata 0:6a670fda63c2 251
cparata 0:6a670fda63c2 252 switch( odr_low_level )
cparata 0:6a670fda63c2 253 {
cparata 0:6a670fda63c2 254 case LSM303AGR_MAG_ODR_10Hz:
cparata 0:6a670fda63c2 255 *odr = 10.000f;
cparata 0:6a670fda63c2 256 break;
cparata 0:6a670fda63c2 257 case LSM303AGR_MAG_ODR_20Hz:
cparata 0:6a670fda63c2 258 *odr = 20.000f;
cparata 0:6a670fda63c2 259 break;
cparata 0:6a670fda63c2 260 case LSM303AGR_MAG_ODR_50Hz:
cparata 0:6a670fda63c2 261 *odr = 50.000f;
cparata 0:6a670fda63c2 262 break;
cparata 0:6a670fda63c2 263 case LSM303AGR_MAG_ODR_100Hz:
cparata 0:6a670fda63c2 264 *odr = 100.000f;
cparata 0:6a670fda63c2 265 break;
cparata 0:6a670fda63c2 266 default:
cparata 0:6a670fda63c2 267 *odr = -1.000f;
cparata 0:6a670fda63c2 268 return LSM303AGR_MAG_STATUS_ERROR;
cparata 0:6a670fda63c2 269 }
cparata 0:6a670fda63c2 270 return LSM303AGR_MAG_STATUS_OK;
cparata 0:6a670fda63c2 271 }
cparata 0:6a670fda63c2 272
cparata 0:6a670fda63c2 273 /**
cparata 0:6a670fda63c2 274 * @brief Set ODR
cparata 0:6a670fda63c2 275 * @param odr the output data rate to be set
cparata 0:6a670fda63c2 276 * @retval LSM303AGR_MAG_STATUS_OK in case of success, an error code otherwise
cparata 0:6a670fda63c2 277 */
cparata 0:6a670fda63c2 278 LSM303AGR_MAG_StatusTypeDef LSM303AGR_MAG_Sensor::SetODR(float odr)
cparata 0:6a670fda63c2 279 {
cparata 0:6a670fda63c2 280 LSM303AGR_MAG_ODR_t new_odr;
cparata 0:6a670fda63c2 281
cparata 0:6a670fda63c2 282 new_odr = ( odr <= 10.000f ) ? LSM303AGR_MAG_ODR_10Hz
cparata 0:6a670fda63c2 283 : ( odr <= 20.000f ) ? LSM303AGR_MAG_ODR_20Hz
cparata 0:6a670fda63c2 284 : ( odr <= 50.000f ) ? LSM303AGR_MAG_ODR_50Hz
cparata 0:6a670fda63c2 285 : LSM303AGR_MAG_ODR_100Hz;
cparata 0:6a670fda63c2 286
cparata 0:6a670fda63c2 287 if ( LSM303AGR_MAG_W_ODR( (void *)this, new_odr ) == MEMS_ERROR )
cparata 0:6a670fda63c2 288 {
cparata 0:6a670fda63c2 289 return LSM303AGR_MAG_STATUS_ERROR;
cparata 0:6a670fda63c2 290 }
cparata 0:6a670fda63c2 291
cparata 0:6a670fda63c2 292 return LSM303AGR_MAG_STATUS_OK;
cparata 0:6a670fda63c2 293 }
cparata 0:6a670fda63c2 294
cparata 0:6a670fda63c2 295
cparata 0:6a670fda63c2 296 /**
cparata 0:6a670fda63c2 297 * @brief Read LSM303AGR Magnetometer full scale
cparata 0:6a670fda63c2 298 * @param fullScale the pointer to the output data rate
cparata 0:6a670fda63c2 299 * @retval LSM303AGR_MAG_STATUS_OK in case of success, an error code otherwise
cparata 0:6a670fda63c2 300 */
cparata 0:6a670fda63c2 301 LSM303AGR_MAG_StatusTypeDef LSM303AGR_MAG_Sensor::GetFS(float* fullScale)
cparata 0:6a670fda63c2 302 {
cparata 0:6a670fda63c2 303 *fullScale = 50.0f;
cparata 0:6a670fda63c2 304
cparata 0:6a670fda63c2 305 return LSM303AGR_MAG_STATUS_OK;
cparata 0:6a670fda63c2 306 }
cparata 0:6a670fda63c2 307
cparata 0:6a670fda63c2 308 /**
cparata 0:6a670fda63c2 309 * @brief Set full scale
cparata 0:6a670fda63c2 310 * @param fullScale the full scale to be set
cparata 0:6a670fda63c2 311 * @retval LSM303AGR_MAG_STATUS_OK in case of success, an error code otherwise
cparata 0:6a670fda63c2 312 */
cparata 0:6a670fda63c2 313 LSM303AGR_MAG_StatusTypeDef LSM303AGR_MAG_Sensor::SetFS(float fullScale)
cparata 0:6a670fda63c2 314 {
cparata 0:6a670fda63c2 315 return LSM303AGR_MAG_STATUS_OK;
cparata 0:6a670fda63c2 316 }
cparata 0:6a670fda63c2 317
cparata 0:6a670fda63c2 318
cparata 0:6a670fda63c2 319 /**
cparata 0:6a670fda63c2 320 * @brief Read magnetometer data from register
cparata 0:6a670fda63c2 321 * @param reg register address
cparata 0:6a670fda63c2 322 * @param data register data
cparata 0:6a670fda63c2 323 * @retval LSM303AGR_MAG_STATUS_OK in case of success
cparata 0:6a670fda63c2 324 * @retval LSM303AGR_MAG_STATUS_ERROR in case of failure
cparata 0:6a670fda63c2 325 */
cparata 0:6a670fda63c2 326 LSM303AGR_MAG_StatusTypeDef LSM303AGR_MAG_Sensor::ReadReg( uint8_t reg, uint8_t *data )
cparata 0:6a670fda63c2 327 {
cparata 0:6a670fda63c2 328 if ( LSM303AGR_MAG_ReadReg( (void *)this, reg, data ) == MEMS_ERROR )
cparata 0:6a670fda63c2 329 {
cparata 0:6a670fda63c2 330 return LSM303AGR_MAG_STATUS_ERROR;
cparata 0:6a670fda63c2 331 }
cparata 0:6a670fda63c2 332
cparata 0:6a670fda63c2 333 return LSM303AGR_MAG_STATUS_OK;
cparata 0:6a670fda63c2 334 }
cparata 0:6a670fda63c2 335
cparata 0:6a670fda63c2 336
cparata 0:6a670fda63c2 337 /**
cparata 0:6a670fda63c2 338 * @brief Write magnetometer data to register
cparata 0:6a670fda63c2 339 * @param reg register address
cparata 0:6a670fda63c2 340 * @param data register data
cparata 0:6a670fda63c2 341 * @retval LSM303AGR_MAG_STATUS_OK in case of success
cparata 0:6a670fda63c2 342 * @retval LSM303AGR_MAG_STATUS_ERROR in case of failure
cparata 0:6a670fda63c2 343 */
cparata 0:6a670fda63c2 344 LSM303AGR_MAG_StatusTypeDef LSM303AGR_MAG_Sensor::WriteReg( uint8_t reg, uint8_t data )
cparata 0:6a670fda63c2 345 {
cparata 0:6a670fda63c2 346 if ( LSM303AGR_MAG_WriteReg( (void *)this, reg, data ) == MEMS_ERROR )
cparata 0:6a670fda63c2 347 {
cparata 0:6a670fda63c2 348 return LSM303AGR_MAG_STATUS_ERROR;
cparata 0:6a670fda63c2 349 }
cparata 0:6a670fda63c2 350
cparata 0:6a670fda63c2 351 return LSM303AGR_MAG_STATUS_OK;
cparata 0:6a670fda63c2 352 }
cparata 0:6a670fda63c2 353
cparata 0:6a670fda63c2 354 uint8_t LSM303AGR_MAG_IO_Write( void *handle, uint8_t WriteAddr, uint8_t *pBuffer, uint16_t nBytesToWrite )
cparata 0:6a670fda63c2 355 {
cparata 0:6a670fda63c2 356 return ((LSM303AGR_MAG_Sensor *)handle)->IO_Write(pBuffer, WriteAddr, nBytesToWrite);
cparata 0:6a670fda63c2 357 }
cparata 0:6a670fda63c2 358
cparata 0:6a670fda63c2 359 uint8_t LSM303AGR_MAG_IO_Read( void *handle, uint8_t ReadAddr, uint8_t *pBuffer, uint16_t nBytesToRead )
cparata 0:6a670fda63c2 360 {
cparata 0:6a670fda63c2 361 return ((LSM303AGR_MAG_Sensor *)handle)->IO_Read(pBuffer, ReadAddr, nBytesToRead);
cparata 0:6a670fda63c2 362 }