Closed mbuesch closed 1 year ago
The 12 bit signed values h4 and h5 are meant to be sign extended to signed 16 bit. The data sheet is ambiguous about this, but the official driver provided by Bosch does sign extension:
https://github.com/BoschSensortec/BME280_driver/blob/c47f06eb44fc96970f0abfcc941ec16425b2a9e6/bme280.c#L1528
Also see this example code for why this step cast makes a difference: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=99d2c26c65a324288c1a9c3a08eeb0dc
h_data[4] doesn't strictly need this step cast, but I included it for symmetry. The new mask 0xF0 is necessary with this sign extension cast.
h_data[4]
0xF0
This bug is very similar to this other bug in this other crate: https://github.com/newAM/bme280-multibus/pull/22
The 12 bit signed values h4 and h5 are meant to be sign extended to signed 16 bit. The data sheet is ambiguous about this, but the official driver provided by Bosch does sign extension:
https://github.com/BoschSensortec/BME280_driver/blob/c47f06eb44fc96970f0abfcc941ec16425b2a9e6/bme280.c#L1528
Also see this example code for why this step cast makes a difference: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=99d2c26c65a324288c1a9c3a08eeb0dc
h_data[4]
doesn't strictly need this step cast, but I included it for symmetry. The new mask0xF0
is necessary with this sign extension cast.This bug is very similar to this other bug in this other crate: https://github.com/newAM/bme280-multibus/pull/22