Skip to content

Commit 38f928f

Browse files
committed
Use enums for accelerometer and gyro ranges
1 parent e5a1c21 commit 38f928f

File tree

2 files changed

+27
-67
lines changed

2 files changed

+27
-67
lines changed

libraries/CurieImu/src/CurieImu.cpp

Lines changed: 4 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -59,85 +59,22 @@ bool CurieImuClass::begin()
5959

6060
int CurieImuClass::getGyroRange()
6161
{
62-
uint8_t fullScaleGyroRange = getFullScaleGyroRange();
63-
64-
switch (fullScaleGyroRange) {
65-
case BMI160_GYRO_RANGE_2000:
66-
return 2000;
67-
68-
case BMI160_GYRO_RANGE_1000:
69-
return 1000;
70-
71-
case BMI160_GYRO_RANGE_500:
72-
return 500;
73-
74-
case BMI160_GYRO_RANGE_250:
75-
return 250;
76-
77-
case BMI160_GYRO_RANGE_125:
78-
return 125;
79-
80-
default:
81-
return -1;
82-
}
62+
return getFullScaleGyroRange();
8363
}
8464

8565
void CurieImuClass::setGyroRange(int range)
8666
{
87-
uint8_t fullScaleGyroRange;
88-
89-
if (range >= 2000) {
90-
fullScaleGyroRange = BMI160_GYRO_RANGE_2000;
91-
} else if (range >= 1000) {
92-
fullScaleGyroRange = BMI160_GYRO_RANGE_1000;
93-
} else if (range >= 500) {
94-
fullScaleGyroRange = BMI160_GYRO_RANGE_500;
95-
} else if (range >= 250) {
96-
fullScaleGyroRange = BMI160_GYRO_RANGE_250;
97-
} else {
98-
fullScaleGyroRange = BMI160_GYRO_RANGE_125;
99-
}
100-
101-
setFullScaleGyroRange(fullScaleGyroRange);
67+
setFullScaleGyroRange(range);
10268
}
10369

10470
int CurieImuClass::getAccelerometerRange()
10571
{
106-
uint8_t fullScaleAccelRange = getFullScaleAccelRange();
107-
108-
switch (fullScaleAccelRange) {
109-
case BMI160_ACCEL_RANGE_2G:
110-
return 2;
111-
112-
case BMI160_ACCEL_RANGE_4G:
113-
return 4;
114-
115-
case BMI160_ACCEL_RANGE_8G:
116-
return 8;
117-
118-
case BMI160_ACCEL_RANGE_16G:
119-
return 16;
120-
121-
default:
122-
return -1;
123-
}
72+
return getFullScaleAccelRange();
12473
}
12574

12675
void CurieImuClass::setAccelerometerRange(int range)
12776
{
128-
uint8_t fullScaleAccelRange;
129-
130-
if (range >= 16) {
131-
fullScaleAccelRange = BMI160_ACCEL_RANGE_16G;
132-
} else if (range >= 8) {
133-
fullScaleAccelRange = BMI160_ACCEL_RANGE_8G;
134-
} else if (range >= 4) {
135-
fullScaleAccelRange = BMI160_ACCEL_RANGE_4G;
136-
} else {
137-
fullScaleAccelRange = BMI160_ACCEL_RANGE_2G;
138-
}
139-
140-
setFullScaleAccelRange(fullScaleAccelRange);
77+
setFullScaleAccelRange(range);
14178
}
14279

14380
void CurieImuClass::autoCalibrateGyroOffset()

libraries/CurieImu/src/CurieImu.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,29 @@ typedef enum {
6969
CURIE_IMU_DATA_READY,
7070
} CurieIMUFeature;
7171

72+
/**
73+
* Accelerometer Sensitivity Range options
74+
* @see setAccelerometerRange()
75+
*/
76+
typedef enum {
77+
CURIE_IMU_ACCEL_RANGE_2G = BMI160_ACCEL_RANGE_2G,
78+
CURIE_IMU_ACCEL_RANGE_4G = BMI160_ACCEL_RANGE_4G,
79+
CURIE_IMU_ACCEL_RANGE_8G = BMI160_ACCEL_RANGE_8G,
80+
CURIE_IMU_ACCEL_RANGE_16G = BMI160_ACCEL_RANGE_16G
81+
} CurieIMUAccelRange;
82+
83+
/**
84+
* Gyroscope Sensitivity Range options
85+
* @see setGyroRange()
86+
*/
87+
typedef enum {
88+
CURIE_IMU_GYRO_RANGE_2000 = BMI160_GYRO_RANGE_2000,
89+
CURIE_IMU_GYRO_RANGE_1000 = BMI160_GYRO_RANGE_1000,
90+
CURIE_IMU_GYRO_RANGE_500 = BMI160_GYRO_RANGE_500,
91+
CURIE_IMU_GYRO_RANGE_250 = BMI160_GYRO_RANGE_250,
92+
CURIE_IMU_GYRO_RANGE_125 = BMI160_GYRO_RANGE_125
93+
} CurieIMUGyroRange;
94+
7295
/**
7396
* Step Detection Mode options
7497
* @see setStepDetectionMode()

0 commit comments

Comments
 (0)