Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix negative temperature readings in bme680 #614

Merged
merged 1 commit into from
Feb 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions components/bme680/bme680.c
Original file line number Diff line number Diff line change
Expand Up @@ -346,13 +346,15 @@ static int16_t bme680_convert_temperature(bme680_t *dev, uint32_t raw_temperatur

int64_t var1;
int64_t var2;
int64_t var3;
int16_t temperature;

var1 = ((((raw_temperature >> 3) - ((int32_t) cd->par_t1 << 1))) * ((int32_t) cd->par_t2)) >> 11;
var2 = (((((raw_temperature >> 4) - ((int32_t) cd->par_t1)) * ((raw_temperature >> 4) - ((int32_t) cd->par_t1))) >> 12)
* ((int32_t) cd->par_t3)) >> 14;
cd->t_fine = (int32_t) (var1 + var2);
temperature = (cd->t_fine * 5 + 128) >> 8;
var1 = ((int32_t)raw_temperature >> 3) - ((int32_t)cd->par_t1 << 1);
var2 = (var1 * (int32_t)cd->par_t2) >> 11;
var3 = ((var1 >> 1) * (var1 >> 1)) >> 12;
var3 = ((var3) * ((int32_t)cd->par_t3 << 4)) >> 14;
cd->t_fine = (int32_t)(var2 + var3);
temperature = (int16_t)(((cd->t_fine * 5) + 128) >> 8);

return temperature;
}
Expand Down
Loading