tof_control/tcpc_control/
tcpc_temp.rs

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
26
27
28
29
use crate::constant::*;
use crate::helper::tcpc_type::{TCPCTemp, TCPCTempError};
use crate::device::tmp1075;

impl TCPCTemp {
    pub fn new() -> Self {
        match Self::read_temp() {
            Ok(tcpc_temp) => {
                tcpc_temp
            }
            Err(_) => {
                Self {
                    tcpc_temp: f32::MAX,
                }
            }
        }
    }
    pub fn read_temp() -> Result<TCPCTemp, TCPCTempError> {
        let tcpc_tmp1075 = tmp1075::TMP1075::new(1, TCPC_TMP1075_ADDRESS);
        tcpc_tmp1075.config()?;
        let tcpc_temp = tcpc_tmp1075.read()?;

        Ok(
            TCPCTemp {
                tcpc_temp,
            }
        )
    }
}