fuchsnj / ds18b20

17 stars 11 forks source link

Temperature conversion problem #6

Open naskomit opened 1 year ago

naskomit commented 1 year ago

I believe the temperature conversion is incorrect at: https://github.com/fuchsnj/ds18b20/blob/master/src/lib.rs#:~:text=let%20temperature%20%3D,%7D%3B

According to the documentation, with lowering of the resolution, the least significant bits become meaningless, but the conversion factor has to be the same i.e. you should always divide by 16.

    let temperature = match resolution {
        Resolution::Bits12 => (raw_temp as f32) / 16.0,
        Resolution::Bits11 => (raw_temp as f32) / 16.0,
        Resolution::Bits10 => (raw_temp as f32) / 16.0,
        Resolution::Bits9 => (raw_temp as f32) / 16.0,
    };