From cce7d4c65c784169aa08dfb992fa0b184dcc4d18 Mon Sep 17 00:00:00 2001 From: marcelbuesing Date: Mon, 28 May 2018 19:56:57 +0200 Subject: [PATCH] Replace run_gas u8 with boolean --- examples/reading_temperature.rs | 2 +- src/lib.rs | 11 +++++------ src/settings.rs | 6 +++++- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/examples/reading_temperature.rs b/examples/reading_temperature.rs index a5dc123..a4db46b 100644 --- a/examples/reading_temperature.rs +++ b/examples/reading_temperature.rs @@ -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); diff --git a/src/lib.rs b/src/lib.rs index d78304c..785fb81 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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::(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) diff --git a/src/settings.rs b/src/settings.rs index 43a1464..2f1ff69 100644 --- a/src/settings.rs +++ b/src/settings.rs @@ -45,9 +45,13 @@ impl Clone for TphSett { #[repr(C)] pub struct GasSett { pub nb_conv: u8, + /// Heater control pub heatr_ctrl: Option, - pub run_gas: Option, + /// Enable measurement of gas, disabled by default + pub run_gas_measurement: bool, + /// Heater temperature pub heatr_temp: Option, + /// Profile duration pub heatr_dur: Option, }