tof_control/cpc_control/
cpc_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::cpc_type::{CPCTemp, CPCTempError};
use crate::device::tmp1075;

impl CPCTemp {
    pub fn new() -> Self {
        match Self::read_temp() {
            Ok(cpc_temp) => {
                cpc_temp
            }
            Err(_) => {
                Self {
                    cpc_temp: f32::MAX,
                }
            }
        }
    }
    pub fn read_temp() -> Result<CPCTemp, CPCTempError> {
        let cpc_tmp1075 = tmp1075::TMP1075::new(6, CPC_TMP1075_ADDRESS);
        cpc_tmp1075.config()?;
        let cpc_temp = cpc_tmp1075.read()?;

        Ok(
            CPCTemp {
                cpc_temp,
            }
        )
    }
}