bmp180_embedded_hal/
calibration.rs

1//! Calibration data.
2
3/// Calibration data according to the BMP180 datasheet.
4#[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    /// AC1.
9    pub ac1: i16,
10    /// AC2.
11    pub ac2: i16,
12    /// AC3.
13    pub ac3: i16,
14    /// AC4.
15    pub ac4: u16,
16    /// AC5.
17    pub ac5: u16,
18    /// AC6.
19    pub ac6: u16,
20
21    /// B1.
22    pub b1: i16,
23    /// B2.
24    pub b2: i16,
25
26    /// MB.
27    pub mb: i16,
28    /// MC.
29    pub mc: i16,
30    /// MD.
31    pub md: i16,
32}
33
34impl Calibration {
35    /// Create a new [`Calibration`] instance from a slice.
36    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}