use embedded_hal::i2c::I2c;

const REG: u8 = 0;
const ADDR: u8 = 0x48;

/// 温度をセルシウス度で返す。
pub fn celcius<E>(bus: &mut impl I2c<Error = E>) -> Result<f64, E> {
    let bytes = [REG];
    let mut buffer = [0_u8; 2];

    // 0x48番地に値を読み書き
    bus.write_read(ADDR, &bytes, &mut buffer)?;

    let temp = ((buffer[0] as u16) << 8) | buffer[1] as u16;
    Ok((temp as i16 >> 3) as f64 / 16.0)
}
