From d4517d864cf278f0f9e654b0c00efbd97cde4852 Mon Sep 17 00:00:00 2001 From: EnderDocs <89111040+EnderDocs@users.noreply.github.com> Date: Wed, 31 Dec 2025 12:00:54 +0000 Subject: [PATCH] Refactor temperature calculation in F_BMI160.cpp Was testing the temperature and getting 140~ when real value dropped below 23.00, the converstion itself had an issue. Tested it. --- src/F_BMI160.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/F_BMI160.cpp b/src/F_BMI160.cpp index 18ddb3a..f0a516a 100644 --- a/src/F_BMI160.cpp +++ b/src/F_BMI160.cpp @@ -111,8 +111,8 @@ void BMI160::update() { uint8_t buf[2]; readBytesI2C(wire, IMUAddress, BMI160_TEMPERATURE_0, 2, &buf[0]); - float temp = ((((int16_t)buf[1]) << 8) | buf[0]); - temperature = (temp / 512) + 23.f; + int16_t raw = ((uint16_t)buf[1] << 8 | (uint16_t)buf[0]); // MSB<<8 | LSB + temperature = (float)raw / 512.0f + 23.0f; } void BMI160::getAccel(AccelData* out) @@ -277,4 +277,4 @@ void BMI160::calibrateAccelGyro(calData* cal) cal->gyroBias[1] = (float)gyro_bias[1]; cal->gyroBias[2] = (float)gyro_bias[2]; cal->valid = true; -} \ No newline at end of file +}