Пример #1
0
void   LSM6DS3_X_GetAxes( int32_t *pData )
{
    /*Here we could check if the parameters are valid*/
  
    uint8_t tempReg = 0x00;
    int16_t pDataRaw[3];
    float sensitivity = 0;

    LSM6DS3_X_GetAxesRaw(pDataRaw);

    LSM6DS3_IO_Read(&tempReg, LSM6DS3_XG_MEMS_ADDRESS, LSM6DS3_XG_CTRL1_XL, 1);

    tempReg &= LSM6DS3_XL_FS_MASK;

    switch(tempReg)
    {
      case LSM6DS3_XL_FS_2G:
        sensitivity = 0.061;
        break;
      case LSM6DS3_XL_FS_4G:
        sensitivity = 0.122;
        break;
      case LSM6DS3_XL_FS_8G:
        sensitivity = 0.244;
        break;
      case LSM6DS3_XL_FS_16G:
        sensitivity = 0.488;
        break;
    }

    pData[0] = (int32_t)(pDataRaw[0] * sensitivity);
    pData[1] = (int32_t)(pDataRaw[1] * sensitivity);
    pData[2] = (int32_t)(pDataRaw[2] * sensitivity);
  
}
Пример #2
0
/**
 * @brief  Read data from LSM6DS3 Accelerometer and calculate linear acceleration in mg
 * @param  pData the pointer where the accelerometer data are stored
 * @retval IMU_6AXES_OK in case of success, an error code otherwise
 */
static IMU_6AXES_StatusTypeDef    LSM6DS3_X_GetAxes( int32_t *pData )
{
  /*Here we have to add the check if the parameters are valid*/
  int16_t pDataRaw[3];
  float sensitivity = 0.0f;
  
  if(LSM6DS3_X_GetAxesRaw(pDataRaw) != IMU_6AXES_OK)
  {
    return IMU_6AXES_ERROR;
  }
  
  if(LSM6DS3_X_GetSensitivity( &sensitivity ) != IMU_6AXES_OK)
  {
    return IMU_6AXES_ERROR;
  }
  
  pData[0] = (int32_t)(pDataRaw[0] * sensitivity);
  pData[1] = (int32_t)(pDataRaw[1] * sensitivity);
  pData[2] = (int32_t)(pDataRaw[2] * sensitivity);
  
  return IMU_6AXES_OK;
}