scd30_interface/command.rs
1//! SCD30 I2C Commands.
2
3/// I2C Commands for the SCD30 according to its [interface
4/// description](https://sensirion.com/media/documents/D7CEEF4A/6165372F/Sensirion_CO2_Sensors_SCD30_Interface_Description.pdf)
5#[derive(Clone, Copy)]
6pub enum Command {
7 /// Enable continuous measurements with an ambient pressure compensation. The ambient pressure
8 /// compensation is sent as an argument after the command. Setting it to 0 uses the default
9 /// value of 1013.25 mBar. Accepted value range: 0 or [700...1400] in mBar.
10 TriggerContinuousMeasurement = 0x0010,
11 /// Stop continuous measurements.
12 StopContinuousMeasurement = 0x0104,
13 /// Sets the measurement interval in continuous mode. The interval is sent as an argument
14 /// after the command. The initial value is 2 s. Accepted value range: [2...1800] in s. If no
15 /// argument is given the value is read back.
16 SetMeasurementInterval = 0x4600,
17 /// Queries whether a measurement can be read from the sensor's buffer. The answer is `1` if
18 /// a measurement is available, `0` otherwise.
19 GetDataReady = 0x0202,
20 /// If a measurement is available reads out the measurement. The measurement contains the CO2
21 /// concentration in ppm, the temperature in °C and the relative humidity in %.
22 ReadMeasurement = 0x0300,
23 /// (De-)Activates continuous, automatic self calibration (ASC). The setting is sent as an
24 /// argument after the command. Sending a `1` activates ASC, sending a `0` deactivates ASC. See
25 /// the interface description for the self-calibration procedure.
26 ActivateAutomaticSelfCalibration = 0x5306,
27 /// Set or get the forced re-calibration value (FRC). After re-powering this returns the standard
28 /// value of 400 ppm. Sending an argument after the command sets the FRC to the sent value.
29 /// Accepted value range: [400...2000] ppm. If no argument is given the value is read back.
30 ForcedRecalibrationValue = 0x5204,
31 /// Set temperature offset caused by self-heating. The offset is sent as an argument after the
32 /// command. Accepted value range: [0.1...UINT16::MAX * 0.1] in °C.
33 SetTemperatureOffset = 0x5403,
34 /// Set operating height over sea level. The height is sent as an argument after the command.
35 /// Accepted value range: [0..UINT16::MAX] in m above sea level. If no argument is given the
36 /// value is read back.
37 SetAltitudeCompensation = 0x5102,
38 /// Queries the firmware version of the sensor. The responses is the major.minor version.
39 ReadFirmwareVersion = 0xD100,
40 /// Reset the device, similar to a power-off reset, by restarting the sensor controller.
41 SoftReset = 0xD304,
42}
43
44impl Command {
45 /// Returns a big endian byte representation of the command.
46 pub fn to_be_bytes(&self) -> [u8; 2] {
47 (*self as u16).to_be_bytes()
48 }
49}
50
51#[cfg(test)]
52mod tests {
53 use super::*;
54
55 #[test]
56 fn serialize_to_bytes_works() {
57 use Command::*;
58 let data = [
59 (TriggerContinuousMeasurement, [0x00, 0x10]),
60 (StopContinuousMeasurement, [0x01, 0x04]),
61 (SetMeasurementInterval, [0x46, 0x00]),
62 (GetDataReady, [0x02, 0x02]),
63 (ReadMeasurement, [0x03, 0x00]),
64 (ActivateAutomaticSelfCalibration, [0x53, 0x06]),
65 (ForcedRecalibrationValue, [0x52, 0x04]),
66 (SetTemperatureOffset, [0x54, 0x03]),
67 (SetAltitudeCompensation, [0x51, 0x02]),
68 (ReadFirmwareVersion, [0xD1, 0x00]),
69 (SoftReset, [0xD3, 0x04]),
70 ];
71
72 for (command, result) in data {
73 assert_eq!(command.to_be_bytes(), result);
74 }
75 }
76}