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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
//! Interface to BME sensors to read physical measurements.
use Input;
use bsec_bme_settings_t;
use ;
/// Trait to implement for your specific hardware to obtain measurements from
/// the BME sensor.
///
/// # Example
///
/// An rudimentary implementation for the BME680 sensor with the
/// [bme680](https://crates.io/crates/bme680) crate might look like this:
///
/// ```
/// use bme680::{Bme680, OversamplingSetting, PowerMode, SettingsBuilder};
/// use bsec::{Input, InputKind};
/// use bsec::bme::{BmeSensor, BmeSettingsHandle};
/// use embedded_hal::blocking::{delay::DelayMs, i2c};
/// use std::fmt::Debug;
/// use std::time::Duration;
///
/// pub struct Bme680Sensor<I2C, D>
/// where
/// D: DelayMs<u8>,
/// I2C: i2c::Read + i2c::Write
/// {
/// bme680: Bme680<I2C, D>,
/// }
///
/// impl<I2C, D> BmeSensor for Bme680Sensor<I2C, D>
/// where
/// D: DelayMs<u8>,
/// I2C: i2c::Read + i2c::Write,
/// <I2C as i2c::Read>::Error: Debug,
/// <I2C as i2c::Write>::Error: Debug,
/// {
/// type Error = bme680::Error<<I2C as i2c::Read>::Error, <I2C as i2c::Write>::Error>;
///
/// fn start_measurement(
/// &mut self,
/// settings: &BmeSettingsHandle,
/// ) -> Result<std::time::Duration, Self::Error> {
/// let settings = SettingsBuilder::new()
/// .with_humidity_oversampling(OversamplingSetting::from_u8(
/// settings.humidity_oversampling(),
/// ))
/// .with_temperature_oversampling(OversamplingSetting::from_u8(
/// settings.temperature_oversampling(),
/// ))
/// .with_pressure_oversampling(OversamplingSetting::from_u8(
/// settings.pressure_oversampling(),
/// ))
/// .with_run_gas(settings.run_gas())
/// .with_gas_measurement(
/// Duration::from_millis(settings.heating_duration().into()),
/// settings.heater_temperature(),
/// 20,
/// )
/// .build();
/// self.bme680
/// .set_sensor_settings(settings)?;
/// let profile_duration = self.bme680.get_profile_dur(&settings.0)?;
/// self.bme680.set_sensor_mode(PowerMode::ForcedMode)?;
/// Ok(profile_duration)
/// }
///
/// fn get_measurement(&mut self) -> nb::Result<Vec<Input>, Self::Error> {
/// let (data, _state) = self.bme680.get_sensor_data()?;
/// Ok(vec![
/// Input {
/// sensor: InputKind::Temperature,
/// signal: data.temperature_celsius(),
/// },
/// Input {
/// sensor: InputKind::Pressure,
/// signal: data.pressure_hpa(),
/// },
/// Input {
/// sensor: InputKind::Humidity,
/// signal: data.humidity_percent(),
/// },
/// Input {
/// sensor: InputKind::GasResistor,
/// signal: data.gas_resistance_ohm() as f32,
/// },
/// ])
/// }
/// }
/// ```
/// Handle to a struct with settings for the BME sensor.
///
/// Retrieve the settings from this handle to configure your BME sensor
/// appropriately in [`BmeSensor::start_measurement`] for the measurements
/// requested by the BSEC algorithm.