use super::Device;
pub struct DS18B20;
pub const CMD_CONVERT_T: u8 = 0x44;
pub const CMD_WRITE_SCRATCHPAD: u8 = 0x4e;
pub const CMD_READ_SCRATCHPAD: u8 = 0xbe;
pub const CMD_COPY_SCRATCHPAD: u8 = 0x48;
pub const CMD_RECALL_EEPROM: u8 = 0xb8;
pub const CMD_POWER_SUPPLY: u8 = 0xb4;
#[repr(u8)]
pub enum Resolution {
Nine = 0b000_11111,
Ten = 0b001_11111,
Eleven = 0b010_11111,
Twelve = 0b011_11111,
}
impl Resolution {
pub fn bits(&self) -> u8 {
match self {
Resolution::Nine => 9,
Resolution::Ten => 10,
Resolution::Eleven => 11,
Resolution::Twelve => 12,
}
}
pub fn conversion_time_ms(&self) -> u16 {
match self {
Resolution::Nine => 94,
Resolution::Ten => 188,
Resolution::Eleven => 375,
Resolution::Twelve => 750,
}
}
}
impl Default for Resolution {
fn default() -> Self {
Resolution::Twelve
}
}
pub struct Config {
pub resolution: Resolution,
pub t_h: i8,
pub t_l: i8,
}
impl Default for Config {
fn default() -> Self {
Config {
resolution: Resolution::Twelve,
t_h: 125,
t_l: -55,
}
}
}
pub trait DB18B20Ext {
fn set_config(&mut self, config: Config);
fn read_config(&mut self) -> Config;
fn start_measurement(&mut self);
fn read_measurement(&mut self) -> f32;
fn read_raw_measurement(&mut self) -> [u8; 2];
fn save_config(&mut self);
fn load_saved_config(&mut self);
fn is_parasite(&mut self) -> bool;
}