Closed antonio-hickey closed 1 year ago
@eldruin
hey was hoping you could give me a hint here, my tests are failing do to ChecksumMismatch thrown from Self::check_pec
:
pub(crate) fn read_u16(&mut self, register: u8) -> Result<u16, Error<E>> {
let mut data = [0; 3];
self.i2c
.write_read(self.address, &[register], &mut data)
.map_err(Error::I2C)?;
let pec = data[2];
Self::check_pec(
&[
self.address << 1,
register,
(self.address << 1) + 1,
data[0],
data[1],
],
pec,
)?;
Ok(u16::from(data[0]) | (u16::from(data[1]) << 8))
}
I noticed this works when I actually use the method in code, but fails test.
You need to calculate the PEC for your transfer and put that in the test as well. In this case it is the third byte. See for example here
Hey @eldruin got test's passing, never heard of PEC before so that was fun to learn about.
Let me know if there's any changes or more doc's / tests you want to see for this feature. :)
I have published this in version 0.2.1.
This library has an emphasis on platform agnostic, but I ran into a LOT of problems trying to work with the
f32
values returned from the methods in this library when running on bare metal.I know using
u16
is a little less accurate thanf32
, but it's nice to be able to call a method that just works out of the box when running on bare metal.This PR introduces 3 new methods for
Mlx90614
and 2 new methods forMlx90615
which are all just clones of existing temperature methods but persevering their raw u16 value type.I'm not 100% sold on the method names, and definitely open to suggestions.
Also willing to write additional docs, tests, and examples for these :) , if you think this feature will be merged.
Fixes #3