#[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "defmt-03", derive(defmt::Format))]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Temperature {
pub(crate) raw: i16,
}
impl Temperature {
pub const fn new(raw: i16) -> Self {
Self { raw }
}
pub const fn from_bytes(data: [u8; 2]) -> Self {
Self {
raw: i16::from_be_bytes(data),
}
}
pub const fn to_bytes(&self) -> [u8; 2] {
self.raw.to_be_bytes()
}
pub const fn raw(&self) -> i16 {
self.raw
}
pub const fn celsius(&self) -> f32 {
(self.raw as f32) / 340.0 + 36.53
}
}