Replace run_gas u8 with boolean

This commit is contained in:
marcelbuesing 2018-05-28 19:56:57 +02:00
parent dd05721aa3
commit cce7d4c65c
No known key found for this signature in database
GPG key ID: EF3934305E975944
3 changed files with 11 additions and 8 deletions

View file

@ -29,7 +29,7 @@ fn main() -> result::Result<
sensor_settings.tph_sett.os_temp = Some(OversamplingSetting::OS8x);
sensor_settings.tph_sett.filter = Some(2);
sensor_settings.gas_sett.run_gas = Some(0x01);
sensor_settings.gas_sett.run_gas_measurement = true;
sensor_settings.gas_sett.heatr_dur = Some(Duration::from_millis(1500));
sensor_settings.gas_sett.heatr_temp = Some(320);

View file

@ -576,9 +576,8 @@ where
if desired_settings.contains(DesiredSensorSettings::RUN_GAS_SEL) {
debug!("RUN_GAS_SEL: true");
let gas_sett_run_gas =
boundary_check::<I2C>(gas_sett.run_gas, "GasSett.run_gas", 0, 1)?;
data = (data as (i32) & !0x10i32 | gas_sett_run_gas as (i32) << 4i32 & 0x10i32)
data = (data as (i32) & !0x10i32
| gas_sett.run_gas_measurement as (i32) << 4i32 & 0x10i32)
as (u8);
}
@ -642,8 +641,8 @@ where
.contains(DesiredSensorSettings::RUN_GAS_SEL | DesiredSensorSettings::NBCONV_SEL)
{
sensor_settings.gas_sett.nb_conv = (data_array[1usize] as (i32) & 0xfi32) as (u8);
sensor_settings.gas_sett.run_gas =
Some(((data_array[1usize] as (i32) & 0x10i32) >> 4i32) as (u8));
sensor_settings.gas_sett.run_gas_measurement =
((data_array[1usize] as (i32) & 0x10i32) >> 4i32) == 0;
}
Ok(sensor_settings)
@ -758,7 +757,7 @@ where
tph_dur = tph_dur.wrapping_div(1000u32);
tph_dur = tph_dur.wrapping_add(1u32);
let mut duration = Duration::from_millis(tph_dur as u64);
if sensor_settings.gas_sett.run_gas.unwrap_or(0) != 0 {
if sensor_settings.gas_sett.run_gas_measurement {
duration = duration + sensor_settings.gas_sett.heatr_dur.expect("Heatrdur");
}
Ok(duration)

View file

@ -45,9 +45,13 @@ impl Clone for TphSett {
#[repr(C)]
pub struct GasSett {
pub nb_conv: u8,
/// Heater control
pub heatr_ctrl: Option<u8>,
pub run_gas: Option<u8>,
/// Enable measurement of gas, disabled by default
pub run_gas_measurement: bool,
/// Heater temperature
pub heatr_temp: Option<u16>,
/// Profile duration
pub heatr_dur: Option<Duration>,
}