Skip to content

Commit

Permalink
Merge pull request #614 from UncleRus/fix/bme680-negative-temp
Browse files Browse the repository at this point in the history
fix: fix negative temperature readings in bme680
  • Loading branch information
UncleRus authored Feb 23, 2024
2 parents 6b9cdc3 + 79a0ed5 commit fa5733b
Showing 1 changed file with 7 additions and 5 deletions.
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

0 comments on commit fa5733b

Please sign in to comment.