dbrgn / sht2x-rs

WIP Platform agnostic Rust driver for the Sensirion SHT2x temperature/humidity sensors.
Apache License 2.0
2 stars 2 forks source link

i16 temperature (milli-degrees celsius) return type insufficient for device operating range #2

Open tim-seoss opened 5 years ago

tim-seoss commented 5 years ago

The temperature method currently returns an i16 (which is documented as being milli-degrees Celsius), so will overflow at temperatures over 32.767°C, or below -32.768°C. The SHT21 operating range is -40°C to +125°C

Possible solutions would be to reduce the number of decimal places (e.g. to 2) or use an i32.

tim-seoss commented 5 years ago

I'm happy to create a PR btw.

dbrgn commented 5 years ago

Good catch :slightly_smiling_face: Using an i32 is probably the best approach.

In the mcp3425 crate, I also added a feature flag that allows using types from the measurements crate (See Temperature). But I doubt a lot of people would use that, especially on embedded devices (since it uses f64).

tim-seoss commented 5 years ago

OK, I think it's probably adding measurements::temperature::Temperature like you did in the mcp3425 crate. In the meantime I've added temperature and humidity (both in thousandths and stored as i32 using the "newtype" pattern). Please take a look at the pull request which I'll open in a minute to see what you think...