Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: X_NUCLEO_COMMON ST_INTERFACES
Dependents: HelloWorld_ST_Sensors MOTENV_Mbed mbed-os-mqtt-client LSM303AGR_JS ... more
LSM303AGRAccSensor.cpp
00001 /** 00002 ****************************************************************************** 00003 * @file LSM303AGRAccSensor.cpp 00004 * @author CLab 00005 * @version V1.0.0 00006 * @date 5 August 2016 00007 * @brief Implementation an LSM303AGR accelerometer sensor. 00008 ****************************************************************************** 00009 * @attention 00010 * 00011 * <h2><center>© 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 /* Includes ------------------------------------------------------------------*/ 00040 00041 #include "LSM303AGRAccSensor.h" 00042 00043 00044 /* Class Implementation ------------------------------------------------------*/ 00045 00046 LSM303AGRAccSensor::LSM303AGRAccSensor(SPI *spi, PinName cs_pin, PinName int1_pin, PinName int2_pin) : 00047 _dev_spi(spi), _cs_pin(cs_pin), _int1_pin(int1_pin), _int2_pin(int2_pin) // SPI3W ONLY 00048 { 00049 assert (spi); 00050 if (cs_pin == NC) 00051 { 00052 printf ("ERROR LSM303AGRAccSensor CS MUST NOT BE NC\n\r"); 00053 _dev_spi = NULL; 00054 _dev_i2c=NULL; 00055 return; 00056 } 00057 _cs_pin = 0; // enable SPI3W disable I2C 00058 _dev_i2c=NULL; 00059 00060 LSM303AGR_ACC_W_SPI_mode((void *)this, LSM303AGR_ACC_SIM_3_WIRES); 00061 } 00062 00063 00064 /** Constructor 00065 * @param i2c object of an helper class which handles the I2C peripheral 00066 * @param address the address of the component's instance 00067 */ 00068 LSM303AGRAccSensor::LSM303AGRAccSensor(DevI2C *i2c, uint8_t address, PinName int1_pin, PinName int2_pin) : 00069 _dev_i2c(i2c), _address(address), _cs_pin(NC), _int1_pin(int1_pin), _int2_pin(int2_pin) 00070 { 00071 assert (i2c); 00072 _dev_spi = NULL; 00073 }; 00074 00075 /** 00076 * @brief Initializing the component. 00077 * @param[in] init pointer to device specific initalization structure. 00078 * @retval "0" in case of success, an error code otherwise. 00079 */ 00080 int LSM303AGRAccSensor::init(void *init) 00081 { 00082 /* Enable BDU */ 00083 if ( LSM303AGR_ACC_W_BlockDataUpdate( (void *)this, LSM303AGR_ACC_BDU_ENABLED ) == MEMS_ERROR ) 00084 { 00085 return 1; 00086 } 00087 00088 /* FIFO mode selection */ 00089 if ( LSM303AGR_ACC_W_FifoMode( (void *)this, LSM303AGR_ACC_FM_BYPASS ) == MEMS_ERROR ) 00090 { 00091 return 1; 00092 } 00093 00094 /* Output data rate selection - power down. */ 00095 if ( LSM303AGR_ACC_W_ODR( (void *)this, LSM303AGR_ACC_ODR_DO_PWR_DOWN ) == MEMS_ERROR ) 00096 { 00097 return 1; 00098 } 00099 00100 /* Full scale selection. */ 00101 if ( set_x_fs( 2.0f ) == 1 ) 00102 { 00103 return 1; 00104 } 00105 00106 /* Enable axes. */ 00107 if ( LSM303AGR_ACC_W_XEN( (void *)this, LSM303AGR_ACC_XEN_ENABLED ) == MEMS_ERROR ) 00108 { 00109 return 1; 00110 } 00111 00112 if ( LSM303AGR_ACC_W_YEN ( (void *)this, LSM303AGR_ACC_YEN_ENABLED ) == MEMS_ERROR ) 00113 { 00114 return 1; 00115 } 00116 00117 if ( LSM303AGR_ACC_W_ZEN ( (void *)this, LSM303AGR_ACC_ZEN_ENABLED ) == MEMS_ERROR ) 00118 { 00119 return 1; 00120 } 00121 00122 /* Select default output data rate. */ 00123 _last_odr = 100.0f; 00124 00125 _is_enabled = 0; 00126 00127 return 0; 00128 } 00129 00130 /** 00131 * @brief Enable LSM303AGR Accelerator 00132 * @retval 0 in case of success, an error code otherwise 00133 */ 00134 int LSM303AGRAccSensor::enable(void) 00135 { 00136 /* Check if the component is already enabled */ 00137 if ( _is_enabled == 1 ) 00138 { 00139 return 0; 00140 } 00141 00142 /* Output data rate selection. */ 00143 if ( set_x_odr_when_enabled( _last_odr ) == 1 ) 00144 { 00145 return 1; 00146 } 00147 00148 _is_enabled = 1; 00149 00150 return 0; 00151 } 00152 00153 /** 00154 * @brief Disable LSM303AGR Accelerator 00155 * @retval 0 in case of success, an error code otherwise 00156 */ 00157 int LSM303AGRAccSensor::disable(void) 00158 { 00159 /* Check if the component is already disabled */ 00160 if ( _is_enabled == 0 ) 00161 { 00162 return 0; 00163 } 00164 00165 /* Store actual output data rate. */ 00166 if ( get_x_odr( &_last_odr ) == 1 ) 00167 { 00168 return 1; 00169 } 00170 00171 /* Output data rate selection - power down. */ 00172 if ( LSM303AGR_ACC_W_ODR( (void *)this, LSM303AGR_ACC_ODR_DO_PWR_DOWN ) == MEMS_ERROR ) 00173 { 00174 return 1; 00175 } 00176 00177 _is_enabled = 0; 00178 00179 return 0; 00180 } 00181 00182 /** 00183 * @brief Read ID of LSM303AGR Accelerometer 00184 * @param p_id the pointer where the ID of the device is stored 00185 * @retval 0 in case of success, an error code otherwise 00186 */ 00187 int LSM303AGRAccSensor::read_id(uint8_t *id) 00188 { 00189 if(!id) 00190 { 00191 return 1; 00192 } 00193 00194 /* Read WHO AM I register */ 00195 if ( LSM303AGR_ACC_R_WHO_AM_I( (void *)this, id ) == MEMS_ERROR ) 00196 { 00197 return 1; 00198 } 00199 00200 return 0; 00201 } 00202 00203 /** 00204 * @brief Read data from LSM303AGR Accelerometer 00205 * @param pData the pointer where the accelerometer data are stored 00206 * @retval 0 in case of success, an error code otherwise 00207 */ 00208 int LSM303AGRAccSensor::get_x_axes(int32_t *pData) 00209 { 00210 int data[3]; 00211 00212 /* Read data from LSM303AGR. */ 00213 if ( !LSM303AGR_ACC_Get_Acceleration((void *)this, data) ) 00214 { 00215 return 1; 00216 } 00217 00218 /* Calculate the data. */ 00219 pData[0] = (int32_t)data[0]; 00220 pData[1] = (int32_t)data[1]; 00221 pData[2] = (int32_t)data[2]; 00222 00223 return 0; 00224 } 00225 00226 /** 00227 * @brief Read Accelerometer Sensitivity 00228 * @param pfData the pointer where the accelerometer sensitivity is stored 00229 * @retval 0 in case of success, an error code otherwise 00230 */ 00231 int LSM303AGRAccSensor::get_x_sensitivity(float *pfData) 00232 { 00233 LSM303AGR_ACC_LPEN_t lp_value; 00234 LSM303AGR_ACC_HR_t hr_value; 00235 00236 /* Read low power flag */ 00237 if( LSM303AGR_ACC_R_LOWPWR_EN( (void *)this, &lp_value ) == MEMS_ERROR ) 00238 { 00239 return 1; 00240 } 00241 00242 /* Read high performance flag */ 00243 if( LSM303AGR_ACC_R_HiRes( (void *)this, &hr_value ) == MEMS_ERROR ) 00244 { 00245 return 1; 00246 } 00247 00248 if( lp_value == LSM303AGR_ACC_LPEN_DISABLED && hr_value == LSM303AGR_ACC_HR_DISABLED ) 00249 { 00250 /* Normal Mode */ 00251 return get_x_sensitivity_normal_mode( pfData ); 00252 } else if ( lp_value == LSM303AGR_ACC_LPEN_ENABLED && hr_value == LSM303AGR_ACC_HR_DISABLED ) 00253 { 00254 /* Low Power Mode */ 00255 return get_x_sensitivity_lp_mode( pfData ); 00256 } else if ( lp_value == LSM303AGR_ACC_LPEN_DISABLED && hr_value == LSM303AGR_ACC_HR_ENABLED ) 00257 { 00258 /* High Resolution Mode */ 00259 return get_x_sensitivity_hr_mode( pfData ); 00260 } else 00261 { 00262 /* Not allowed */ 00263 return 1; 00264 } 00265 } 00266 00267 /** 00268 * @brief Read Accelerometer Sensitivity in Normal Mode 00269 * @param sensitivity the pointer where the accelerometer sensitivity is stored 00270 * @retval 0 in case of success, an error code otherwise 00271 */ 00272 int LSM303AGRAccSensor::get_x_sensitivity_normal_mode( float *sensitivity ) 00273 { 00274 LSM303AGR_ACC_FS_t fullScale; 00275 00276 /* Read actual full scale selection from sensor. */ 00277 if ( LSM303AGR_ACC_R_FullScale( (void *)this, &fullScale ) == MEMS_ERROR ) 00278 { 00279 return 1; 00280 } 00281 00282 /* Store the sensitivity based on actual full scale. */ 00283 switch( fullScale ) 00284 { 00285 case LSM303AGR_ACC_FS_2G: 00286 *sensitivity = ( float )LSM303AGR_ACC_SENSITIVITY_FOR_FS_2G_NORMAL_MODE; 00287 break; 00288 case LSM303AGR_ACC_FS_4G: 00289 *sensitivity = ( float )LSM303AGR_ACC_SENSITIVITY_FOR_FS_4G_NORMAL_MODE; 00290 break; 00291 case LSM303AGR_ACC_FS_8G: 00292 *sensitivity = ( float )LSM303AGR_ACC_SENSITIVITY_FOR_FS_8G_NORMAL_MODE; 00293 break; 00294 case LSM303AGR_ACC_FS_16G: 00295 *sensitivity = ( float )LSM303AGR_ACC_SENSITIVITY_FOR_FS_16G_NORMAL_MODE; 00296 break; 00297 default: 00298 *sensitivity = -1.0f; 00299 return 1; 00300 } 00301 00302 return 0; 00303 } 00304 00305 /** 00306 * @brief Read Accelerometer Sensitivity in LP Mode 00307 * @param sensitivity the pointer where the accelerometer sensitivity is stored 00308 * @retval 0 in case of success, an error code otherwise 00309 */ 00310 int LSM303AGRAccSensor::get_x_sensitivity_lp_mode( float *sensitivity ) 00311 { 00312 LSM303AGR_ACC_FS_t fullScale; 00313 00314 /* Read actual full scale selection from sensor. */ 00315 if ( LSM303AGR_ACC_R_FullScale( (void *)this, &fullScale ) == MEMS_ERROR ) 00316 { 00317 return 1; 00318 } 00319 00320 /* Store the sensitivity based on actual full scale. */ 00321 switch( fullScale ) 00322 { 00323 case LSM303AGR_ACC_FS_2G: 00324 *sensitivity = ( float )LSM303AGR_ACC_SENSITIVITY_FOR_FS_2G_LOW_POWER_MODE; 00325 break; 00326 case LSM303AGR_ACC_FS_4G: 00327 *sensitivity = ( float )LSM303AGR_ACC_SENSITIVITY_FOR_FS_4G_LOW_POWER_MODE; 00328 break; 00329 case LSM303AGR_ACC_FS_8G: 00330 *sensitivity = ( float )LSM303AGR_ACC_SENSITIVITY_FOR_FS_8G_LOW_POWER_MODE; 00331 break; 00332 case LSM303AGR_ACC_FS_16G: 00333 *sensitivity = ( float )LSM303AGR_ACC_SENSITIVITY_FOR_FS_16G_LOW_POWER_MODE; 00334 break; 00335 default: 00336 *sensitivity = -1.0f; 00337 return 1; 00338 } 00339 00340 return 0; 00341 } 00342 00343 /** 00344 * @brief Read Accelerometer Sensitivity in HR Mode 00345 * @param sensitivity the pointer where the accelerometer sensitivity is stored 00346 * @retval 0 in case of success, an error code otherwise 00347 */ 00348 int LSM303AGRAccSensor::get_x_sensitivity_hr_mode( float *sensitivity ) 00349 { 00350 LSM303AGR_ACC_FS_t fullScale; 00351 00352 /* Read actual full scale selection from sensor. */ 00353 if ( LSM303AGR_ACC_R_FullScale( (void *)this, &fullScale ) == MEMS_ERROR ) 00354 { 00355 return 1; 00356 } 00357 00358 /* Store the sensitivity based on actual full scale. */ 00359 switch( fullScale ) 00360 { 00361 case LSM303AGR_ACC_FS_2G: 00362 *sensitivity = ( float )LSM303AGR_ACC_SENSITIVITY_FOR_FS_2G_HIGH_RESOLUTION_MODE; 00363 break; 00364 case LSM303AGR_ACC_FS_4G: 00365 *sensitivity = ( float )LSM303AGR_ACC_SENSITIVITY_FOR_FS_4G_HIGH_RESOLUTION_MODE; 00366 break; 00367 case LSM303AGR_ACC_FS_8G: 00368 *sensitivity = ( float )LSM303AGR_ACC_SENSITIVITY_FOR_FS_8G_HIGH_RESOLUTION_MODE; 00369 break; 00370 case LSM303AGR_ACC_FS_16G: 00371 *sensitivity = ( float )LSM303AGR_ACC_SENSITIVITY_FOR_FS_16G_HIGH_RESOLUTION_MODE; 00372 break; 00373 default: 00374 *sensitivity = -1.0f; 00375 return 1; 00376 } 00377 00378 return 0; 00379 } 00380 00381 /** 00382 * @brief Read raw data from LSM303AGR Accelerometer 00383 * @param pData the pointer where the accelerometer raw data are stored 00384 * @retval 0 in case of success, an error code otherwise 00385 */ 00386 int LSM303AGRAccSensor::get_x_axes_raw(int16_t *pData) 00387 { 00388 uint8_t regValue[6] = {0, 0, 0, 0, 0, 0}; 00389 u8_t shift = 0; 00390 LSM303AGR_ACC_LPEN_t lp; 00391 LSM303AGR_ACC_HR_t hr; 00392 00393 /* Determine which operational mode the acc is set */ 00394 if(!LSM303AGR_ACC_R_HiRes( (void *)this, &hr )) { 00395 return 1; 00396 } 00397 00398 if(!LSM303AGR_ACC_R_LOWPWR_EN( (void *)this, &lp )) { 00399 return 1; 00400 } 00401 00402 if (lp == LSM303AGR_ACC_LPEN_ENABLED && hr == LSM303AGR_ACC_HR_DISABLED) { 00403 /* op mode is LP 8-bit */ 00404 shift = 8; 00405 } else if (lp == LSM303AGR_ACC_LPEN_DISABLED && hr == LSM303AGR_ACC_HR_DISABLED) { 00406 /* op mode is Normal 10-bit */ 00407 shift = 6; 00408 } else if (lp == LSM303AGR_ACC_LPEN_DISABLED && hr == LSM303AGR_ACC_HR_ENABLED) { 00409 /* op mode is HR 12-bit */ 00410 shift = 4; 00411 } else { 00412 return 1; 00413 } 00414 00415 /* Read output registers from LSM303AGR_ACC_GYRO_OUTX_L_XL to LSM303AGR_ACC_GYRO_OUTZ_H_XL. */ 00416 if (!LSM303AGR_ACC_Get_Raw_Acceleration( (void *)this, ( uint8_t* )regValue )) 00417 { 00418 return 1; 00419 } 00420 00421 /* Format the data. */ 00422 pData[0] = ( ( ( ( ( int16_t )regValue[1] ) << 8 ) + ( int16_t )regValue[0] ) >> shift ); 00423 pData[1] = ( ( ( ( ( int16_t )regValue[3] ) << 8 ) + ( int16_t )regValue[2] ) >> shift ); 00424 pData[2] = ( ( ( ( ( int16_t )regValue[5] ) << 8 ) + ( int16_t )regValue[4] ) >> shift ); 00425 00426 return 0; 00427 } 00428 00429 /** 00430 * @brief Read LSM303AGR Accelerometer output data rate 00431 * @param odr the pointer to the output data rate 00432 * @retval 0 in case of success, an error code otherwise 00433 */ 00434 int LSM303AGRAccSensor::get_x_odr(float* odr) 00435 { 00436 LSM303AGR_ACC_ODR_t odr_low_level; 00437 00438 if ( LSM303AGR_ACC_R_ODR( (void *)this, &odr_low_level ) == MEMS_ERROR ) 00439 { 00440 return 1; 00441 } 00442 00443 switch( odr_low_level ) 00444 { 00445 case LSM303AGR_ACC_ODR_DO_PWR_DOWN: 00446 *odr = 0.0f; 00447 break; 00448 case LSM303AGR_ACC_ODR_DO_1Hz: 00449 *odr = 1.0f; 00450 break; 00451 case LSM303AGR_ACC_ODR_DO_10Hz: 00452 *odr = 10.0f; 00453 break; 00454 case LSM303AGR_ACC_ODR_DO_25Hz: 00455 *odr = 25.0f; 00456 break; 00457 case LSM303AGR_ACC_ODR_DO_50Hz: 00458 *odr = 50.0f; 00459 break; 00460 case LSM303AGR_ACC_ODR_DO_100Hz: 00461 *odr = 100.0f; 00462 break; 00463 case LSM303AGR_ACC_ODR_DO_200Hz: 00464 *odr = 200.0f; 00465 break; 00466 case LSM303AGR_ACC_ODR_DO_400Hz: 00467 *odr = 400.0f; 00468 break; 00469 default: 00470 *odr = -1.0f; 00471 return 1; 00472 } 00473 00474 return 0; 00475 } 00476 00477 /** 00478 * @brief Set ODR 00479 * @param odr the output data rate to be set 00480 * @retval 0 in case of success, an error code otherwise 00481 */ 00482 int LSM303AGRAccSensor::set_x_odr(float odr) 00483 { 00484 if(_is_enabled == 1) 00485 { 00486 if(set_x_odr_when_enabled(odr) == 1) 00487 { 00488 return 1; 00489 } 00490 } 00491 else 00492 { 00493 if(set_x_odr_when_disabled(odr) == 1) 00494 { 00495 return 1; 00496 } 00497 } 00498 00499 return 0; 00500 } 00501 00502 /** 00503 * @brief Set ODR when enabled 00504 * @param odr the output data rate to be set 00505 * @retval 0 in case of success, an error code otherwise 00506 */ 00507 int LSM303AGRAccSensor::set_x_odr_when_enabled(float odr) 00508 { 00509 LSM303AGR_ACC_ODR_t new_odr; 00510 00511 new_odr = ( odr <= 1.0f ) ? LSM303AGR_ACC_ODR_DO_1Hz 00512 : ( odr <= 10.0f ) ? LSM303AGR_ACC_ODR_DO_10Hz 00513 : ( odr <= 25.0f ) ? LSM303AGR_ACC_ODR_DO_25Hz 00514 : ( odr <= 50.0f ) ? LSM303AGR_ACC_ODR_DO_50Hz 00515 : ( odr <= 100.0f ) ? LSM303AGR_ACC_ODR_DO_100Hz 00516 : ( odr <= 200.0f ) ? LSM303AGR_ACC_ODR_DO_200Hz 00517 : LSM303AGR_ACC_ODR_DO_400Hz; 00518 00519 if ( LSM303AGR_ACC_W_ODR( (void *)this, new_odr ) == MEMS_ERROR ) 00520 { 00521 return 1; 00522 } 00523 00524 return 0; 00525 } 00526 00527 /** 00528 * @brief Set ODR when disabled 00529 * @param odr the output data rate to be set 00530 * @retval 0 in case of success, an error code otherwise 00531 */ 00532 int LSM303AGRAccSensor::set_x_odr_when_disabled(float odr) 00533 { 00534 _last_odr = ( odr <= 1.0f ) ? 1.0f 00535 : ( odr <= 10.0f ) ? 10.0f 00536 : ( odr <= 25.0f ) ? 25.0f 00537 : ( odr <= 50.0f ) ? 50.0f 00538 : ( odr <= 100.0f ) ? 100.0f 00539 : ( odr <= 200.0f ) ? 200.0f 00540 : 400.0f; 00541 00542 return 0; 00543 } 00544 00545 00546 /** 00547 * @brief Read LSM303AGR Accelerometer full scale 00548 * @param fullScale the pointer to the full scale 00549 * @retval 0 in case of success, an error code otherwise 00550 */ 00551 int LSM303AGRAccSensor::get_x_fs(float* fullScale) 00552 { 00553 LSM303AGR_ACC_FS_t fs_low_level; 00554 00555 if ( LSM303AGR_ACC_R_FullScale( (void *)this, &fs_low_level ) == MEMS_ERROR ) 00556 { 00557 return 1; 00558 } 00559 00560 switch( fs_low_level ) 00561 { 00562 case LSM303AGR_ACC_FS_2G: 00563 *fullScale = 2.0f; 00564 break; 00565 case LSM303AGR_ACC_FS_4G: 00566 *fullScale = 4.0f; 00567 break; 00568 case LSM303AGR_ACC_FS_8G: 00569 *fullScale = 8.0f; 00570 break; 00571 case LSM303AGR_ACC_FS_16G: 00572 *fullScale = 16.0f; 00573 break; 00574 default: 00575 *fullScale = -1.0f; 00576 return 1; 00577 } 00578 00579 return 0; 00580 } 00581 00582 /** 00583 * @brief Set full scale 00584 * @param fullScale the full scale to be set 00585 * @retval 0 in case of success, an error code otherwise 00586 */ 00587 int LSM303AGRAccSensor::set_x_fs(float fullScale) 00588 { 00589 LSM303AGR_ACC_FS_t new_fs; 00590 00591 new_fs = ( fullScale <= 2.0f ) ? LSM303AGR_ACC_FS_2G 00592 : ( fullScale <= 4.0f ) ? LSM303AGR_ACC_FS_4G 00593 : ( fullScale <= 8.0f ) ? LSM303AGR_ACC_FS_8G 00594 : LSM303AGR_ACC_FS_16G; 00595 00596 if ( LSM303AGR_ACC_W_FullScale( (void *)this, new_fs ) == MEMS_ERROR ) 00597 { 00598 return 1; 00599 } 00600 00601 return 0; 00602 } 00603 00604 /** 00605 * @brief Read accelerometer data from register 00606 * @param reg register address 00607 * @param data register data 00608 * @retval 0 in case of success 00609 * @retval 1 in case of failure 00610 */ 00611 int LSM303AGRAccSensor::read_reg( uint8_t reg, uint8_t *data ) 00612 { 00613 00614 if ( LSM303AGR_ACC_read_reg( (void *)this, reg, data ) == MEMS_ERROR ) 00615 { 00616 return 1; 00617 } 00618 00619 return 0; 00620 } 00621 00622 /** 00623 * @brief Write accelerometer data to register 00624 * @param reg register address 00625 * @param data register data 00626 * @retval 0 in case of success 00627 * @retval 1 in case of failure 00628 */ 00629 int LSM303AGRAccSensor::write_reg( uint8_t reg, uint8_t data ) 00630 { 00631 00632 if ( LSM303AGR_ACC_write_reg( (void *)this, reg, data ) == MEMS_ERROR ) 00633 { 00634 return 1; 00635 } 00636 00637 return 0; 00638 } 00639 00640 uint8_t LSM303AGR_ACC_io_write( void *handle, uint8_t WriteAddr, uint8_t *pBuffer, uint16_t nBytesToWrite ) 00641 { 00642 return ((LSM303AGRAccSensor *)handle)->io_write(pBuffer, WriteAddr, nBytesToWrite); 00643 } 00644 00645 uint8_t LSM303AGR_ACC_io_read( void *handle, uint8_t ReadAddr, uint8_t *pBuffer, uint16_t nBytesToRead ) 00646 { 00647 return ((LSM303AGRAccSensor *)handle)->io_read(pBuffer, ReadAddr, nBytesToRead); 00648 }
Generated on Tue Jul 12 2022 23:32:14 by
