bmp180_embedded_hal/
calibration.rs1#[derive(Default, Clone)]
5#[cfg_attr(feature = "impl-defmt-format", derive(defmt::Format))]
6#[cfg_attr(feature = "impl-debug", derive(core::fmt::Debug))]
7pub struct Calibration {
8 pub ac1: i16,
10 pub ac2: i16,
12 pub ac3: i16,
14 pub ac4: u16,
16 pub ac5: u16,
18 pub ac6: u16,
20
21 pub b1: i16,
23 pub b2: i16,
25
26 pub mb: i16,
28 pub mc: i16,
30 pub md: i16,
32}
33
34impl Calibration {
35 pub fn from_slice(slice: &[u8; 22]) -> Self {
37 let ac1 = (slice[0] as i16) << 8 | slice[1] as i16;
38 let ac2 = (slice[2] as i16) << 8 | slice[3] as i16;
39 let ac3 = (slice[4] as i16) << 8 | slice[5] as i16;
40 let ac4 = (slice[6] as u16) << 8 | slice[7] as u16;
41 let ac5 = (slice[8] as u16) << 8 | slice[9] as u16;
42 let ac6 = (slice[10] as u16) << 8 | slice[11] as u16;
43
44 let b1 = (slice[12] as i16) << 8 | slice[13] as i16;
45 let b2 = (slice[14] as i16) << 8 | slice[15] as i16;
46
47 let mb = (slice[16] as i16) << 8 | slice[17] as i16;
48 let mc = (slice[18] as i16) << 8 | slice[19] as i16;
49 let md = (slice[20] as i16) << 8 | slice[21] as i16;
50
51 Self {
52 ac1,
53 ac2,
54 ac3,
55 ac4,
56 ac5,
57 ac6,
58 b1,
59 b2,
60 mb,
61 mc,
62 md,
63 }
64 }
65}