Skip to content

Commit 408a529

Browse files
committed
Fix issue on full scale
1 parent 09d0ded commit 408a529

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=STM32duino LSM6DSV16X
2-
version=2.0.0
2+
version=2.0.1
33
author=SRA
44
maintainer=stm32duino
55
sentence=Ultra Low Power inertial measurement unit.

src/LSM6DSV16XSensor.cpp

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,6 @@ LSM6DSV16XSensor::LSM6DSV16XSensor(TwoWire *i2c, uint8_t address) : dev_i2c(i2c)
5555
dev_spi = NULL;
5656
acc_is_enabled = 0L;
5757
gyro_is_enabled = 0L;
58-
acc_fs = LSM6DSV16X_2g;
59-
gyro_fs = LSM6DSV16X_125dps;
6058
}
6159

6260
/** Constructor
@@ -73,8 +71,6 @@ LSM6DSV16XSensor::LSM6DSV16XSensor(SPIClass *spi, int cs_pin, uint32_t spi_speed
7371
dev_i2c = NULL;
7472
acc_is_enabled = 0L;
7573
gyro_is_enabled = 0L;
76-
acc_fs = LSM6DSV16X_2g;
77-
gyro_fs = LSM6DSV16X_125dps;
7874
}
7975

8076
/**
@@ -83,6 +79,8 @@ LSM6DSV16XSensor::LSM6DSV16XSensor(SPIClass *spi, int cs_pin, uint32_t spi_speed
8379
*/
8480
LSM6DSV16XStatusTypeDef LSM6DSV16XSensor::begin()
8581
{
82+
int32_t fs = 0;
83+
8684
if (dev_spi) {
8785
// Configure CS pin
8886
pinMode(cs_pin, OUTPUT);
@@ -113,6 +111,16 @@ LSM6DSV16XStatusTypeDef LSM6DSV16XSensor::begin()
113111
return LSM6DSV16X_ERROR;
114112
}
115113

114+
/* Set accelerometer full scale internal variable */
115+
if (Get_X_FS(&fs) != LSM6DSV16X_OK) {
116+
return LSM6DSV16X_ERROR;
117+
}
118+
119+
acc_fs = (fs <= 2) ? LSM6DSV16X_2g
120+
: (fs <= 4) ? LSM6DSV16X_4g
121+
: (fs <= 8) ? LSM6DSV16X_8g
122+
: LSM6DSV16X_16g;
123+
116124
/* Full scale selection. */
117125
if (lsm6dsv16x_xl_full_scale_set(&reg_ctx, LSM6DSV16X_2g) != LSM6DSV16X_OK) {
118126
return LSM6DSV16X_ERROR;
@@ -126,6 +134,18 @@ LSM6DSV16XStatusTypeDef LSM6DSV16XSensor::begin()
126134
return LSM6DSV16X_ERROR;
127135
}
128136

137+
/* Set gyroscope full scale internal variable */
138+
if (Get_G_FS(&fs) != LSM6DSV16X_OK) {
139+
return LSM6DSV16X_ERROR;
140+
}
141+
142+
gyro_fs = (fs <= 125) ? LSM6DSV16X_125dps
143+
: (fs <= 250) ? LSM6DSV16X_250dps
144+
: (fs <= 500) ? LSM6DSV16X_500dps
145+
: (fs <= 1000) ? LSM6DSV16X_1000dps
146+
: (fs <= 2000) ? LSM6DSV16X_2000dps
147+
: LSM6DSV16X_4000dps;
148+
129149
/* Full scale selection. */
130150
if (lsm6dsv16x_gy_full_scale_set(&reg_ctx, LSM6DSV16X_2000dps) != LSM6DSV16X_OK) {
131151
return LSM6DSV16X_ERROR;

0 commit comments

Comments
 (0)