1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
use fixed::types::I30F2;

use crate::{raw, RawError, Softdevice};

#[derive(Debug, PartialEq, Eq, Clone, Copy)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum TempError {
    Raw(RawError),
}

impl From<RawError> for TempError {
    fn from(err: RawError) -> Self {
        TempError::Raw(err)
    }
}

/// Get temperature reading in Celsius
///
/// Note this blocks for ~50us
pub fn temperature_celsius(_sd: &Softdevice) -> Result<I30F2, TempError> {
    let mut temp: i32 = 0;
    let ret = unsafe { raw::sd_temp_get(&mut temp) };
    RawError::convert(ret)?;
    Ok(I30F2::from_bits(temp))
}