Skip to content

Commit

Permalink
Merge pull request #9 from nuenen313/get_x_axes-output-as-float
Browse files Browse the repository at this point in the history
Get x axes output as float
  • Loading branch information
cparata authored Jun 3, 2024
2 parents 288e364 + d1a1ad8 commit 1fcdf80
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 2 deletions.
2 changes: 1 addition & 1 deletion examples/LSM6DSR_I2C_HelloWorld/LSM6DSR_I2C_HelloWorld.ino
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ void loop() {
delay(250);

// Read accelerometer and gyroscope.
int32_t accelerometer[3];
int32_t accelerometer[3]; // Alternatively, use float accelerometer[3]
int32_t gyroscope[3];
AccGyr.Get_X_Axes(accelerometer);
AccGyr.Get_G_Axes(gyroscope);
Expand Down
2 changes: 1 addition & 1 deletion examples/LSM6DSR_SPI_HelloWorld/LSM6DSR_SPI_HelloWorld.ino
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ void loop() {
delay(250);

// Read accelerometer and gyroscope.
int32_t accelerometer[3];
int32_t accelerometer[3]; // Alternatively, use float accelerometer[3]
int32_t gyroscope[3];
AccGyr.Get_X_Axes(accelerometer);
AccGyr.Get_G_Axes(gyroscope);
Expand Down
31 changes: 31 additions & 0 deletions src/LSM6DSRSensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,37 @@ LSM6DSRStatusTypeDef LSM6DSRSensor::Get_X_Axes(int32_t *Acceleration)
}


/**
* @brief Get the LSM6DSR accelerometer sensor axes as floats
* @param Acceleration pointer where the values of the axes are written
* @retval 0 in case of success, an error code otherwise
*/
LSM6DSRStatusTypeDef LSM6DSRSensor::Get_X_Axes(float *Acceleration)
{
axis3bit16_t data_raw;
float sensitivity = 0.0f;

/* Read raw data values. */
if (lsm6dsr_acceleration_raw_get(&reg_ctx, data_raw.u8bit) != LSM6DSR_OK)
{
return LSM6DSR_ERROR;
}

/* Get LSM6DSR actual sensitivity. */
if (Get_X_Sensitivity(&sensitivity) != LSM6DSR_OK)
{
return LSM6DSR_ERROR;
}

/* Calculate the data. */
Acceleration[0] = ((float)((float)data_raw.i16bit[0] * sensitivity));
Acceleration[1] = ((float)((float)data_raw.i16bit[1] * sensitivity));
Acceleration[2] = ((float)((float)data_raw.i16bit[2] * sensitivity));

return LSM6DSR_OK;
}


/**
* @brief Get the LSM6DSR ACC data ready bit value
* @param Status the status of data ready bit
Expand Down
1 change: 1 addition & 0 deletions src/LSM6DSRSensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ class LSM6DSRSensor
LSM6DSRStatusTypeDef Set_X_FS(int32_t FullScale);
LSM6DSRStatusTypeDef Get_X_AxesRaw(int16_t *Value);
LSM6DSRStatusTypeDef Get_X_Axes(int32_t *Acceleration);
LSM6DSRStatusTypeDef Get_X_Axes(float *Acceleration);
LSM6DSRStatusTypeDef Get_X_DRDY_Status(uint8_t *Status);

LSM6DSRStatusTypeDef Enable_G();
Expand Down

0 comments on commit 1fcdf80

Please sign in to comment.