Skip to content

Commit 0de765b

Browse files
authored
Merge pull request #45 from EnderDocs/patch-1
Refactor temperature calculation in F_BMI160.cpp
2 parents 1f64fe4 + d4517d8 commit 0de765b

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

src/F_BMI160.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,8 @@ void BMI160::update() {
111111

112112
uint8_t buf[2];
113113
readBytesI2C(wire, IMUAddress, BMI160_TEMPERATURE_0, 2, &buf[0]);
114-
float temp = ((((int16_t)buf[1]) << 8) | buf[0]);
115-
temperature = (temp / 512) + 23.f;
114+
int16_t raw = ((uint16_t)buf[1] << 8 | (uint16_t)buf[0]); // MSB<<8 | LSB
115+
temperature = (float)raw / 512.0f + 23.0f;
116116
}
117117

118118
void BMI160::getAccel(AccelData* out)
@@ -277,4 +277,4 @@ void BMI160::calibrateAccelGyro(calData* cal)
277277
cal->gyroBias[1] = (float)gyro_bias[1];
278278
cal->gyroBias[2] = (float)gyro_bias[2];
279279
cal->valid = true;
280-
}
280+
}

0 commit comments

Comments
 (0)