embedded_devices/devices/sensirion/sen63c/
commands.rs

1use crate::devices::sensirion::commands::define_sensirion_commands;
2use embedded_interfaces::codegen::interface_objects;
3use uom::si::{
4    f64::{MassConcentration, Ratio, ThermodynamicTemperature},
5    mass_concentration::microgram_per_cubic_meter,
6    ratio::{part_per_million, percent},
7    thermodynamic_temperature::degree_celsius,
8};
9
10pub use crate::devices::sensirion::sen6x::commands::{
11    ActivateSHTHeater, DeviceReset, GetAmbientPressure, GetCo2SensorAutomaticSelfCalibration, GetDataReady,
12    GetProductName, GetSensorAltitude, GetSerialNumber, PerformForcedCo2Recalibration, ReadNumberConcentrationValues,
13    SetAmbientPressure, SetCo2SensorAutomaticSelfCalibration, SetSensorAltitude, SetTemperatureAccelerationParameters,
14    SetTemperatureOffsetParameters, StartContinuousMeasurement, StartFanCleaning, StopMeasurement,
15};
16
17interface_objects! {
18    struct MeasuredValues(size=14) {
19        /// PM1 mass concentration, LSB = 0.1 µg/m³
20        raw_mass_concentration_pm1: u16 = u16::MAX => {
21            quantity: MassConcentration,
22            unit: microgram_per_cubic_meter,
23            lsb: 1f64 / 10_000_000f64,
24        },
25        /// PM2.5 mass concentration, LSB = 0.1 µg/m³
26        raw_mass_concentration_pm2_5: u16 = u16::MAX => {
27            quantity: MassConcentration,
28            unit: microgram_per_cubic_meter,
29            lsb: 1f64 / 10_000_000f64,
30        },
31        /// PM4 mass concentration, LSB = 0.1 µg/m³
32        raw_mass_concentration_pm4: u16 = u16::MAX => {
33            quantity: MassConcentration,
34            unit: microgram_per_cubic_meter,
35            lsb: 1f64 / 10_000_000f64,
36        },
37        /// PM10 mass concentration, LSB = 0.1 µg/m³
38        raw_mass_concentration_pm10: u16 = u16::MAX => {
39            quantity: MassConcentration,
40            unit: microgram_per_cubic_meter,
41            lsb: 1f64 / 10_000_000f64,
42        },
43        /// Ambient relative humidity, LSB = 0.01%
44        raw_relative_humidity: i16 = i16::MAX => {
45            quantity: Ratio,
46            unit: percent,
47            lsb: 1f64 / 100f64,
48        },
49        /// Ambient temperature, LSB = 0.005°C
50        raw_temperature: i16 = i16::MAX => {
51            quantity: ThermodynamicTemperature,
52            unit: degree_celsius,
53            lsb: 1f64 / 200f64,
54        },
55        /// CO2 concentration, LSB = 1 ppm
56        /// Will be u16::MAX for the first 5-6 seconds after startup or reset.
57        raw_co2_concentration: u16 = u16::MAX => {
58            quantity: Ratio,
59            unit: part_per_million,
60            lsb: 1f64 / 1f64,
61        },
62    }
63
64    struct MeasuredRawValues(size=4) {
65        /// Raw relative humidity, LSB = 0.01%
66        raw_relative_humidity: i16 = i16::MAX => {
67            quantity: Ratio,
68            unit: percent,
69            lsb: 1f64 / 100f64,
70        },
71        /// Raw temperature, LSB = 0.005°C
72        raw_temperature: i16 = i16::MAX => {
73            quantity: ThermodynamicTemperature,
74            unit: degree_celsius,
75            lsb: 1f64 / 200f64,
76        },
77    }
78
79    struct DeviceStatus(size=4) {
80        _: u16{10},
81        /// Fan is switched on, but its speed is more than 10% off the target speed for multiple
82        /// consecutive measurement intervals. During the first 10 seconds after starting the
83        /// measurement, the fan speed is not checked (settling time). Very low or very high ambient
84        /// temperature could trigger this warning during startup. If this flag is set constantly, it
85        /// might indicate a problem with the power supply or with the fan, and the measured PM values
86        /// might be wrong. This flag is automatically cleared as soon as the measured speed is within
87        /// 10% of the target speed or when leaving the measure mode.
88        ///
89        /// Can occur only in measurement mode.
90        fan_speed_warning: bool = false,
91        _: u8,
92        /// Error related to the CO2 sensor. The CO2 values might be unknown or wrong if this flag is
93        /// set, relative humidity and temperature values might be out of specs due to compensation
94        /// algorithms depending on CO2 sensor state.
95        ///
96        /// Can occur only in measurement mode.
97        co2_error: bool = false,
98        /// Error related to the PM sensor. The particulate matter values might be unknown or wrong if
99        /// this flag is set, relative humidity and temperature values might be out of specs due to
100        /// compensation algorithms depending on PM sensor state.
101        ///
102        /// Can occur only in measurement mode.
103        pm_error: bool = false,
104        _: bool, // hcho_error
105        _: bool, // co2_error2
106        _: bool, // reserved
107        _: bool, // gas_error
108        /// Error related to the RH&T sensor. The temperature and humidity values might be unknown or
109        /// wrong if this flag is set, and other measured values might be out of specs due compensation
110        /// algorithms depending on RH&T sensor values.
111        ///
112        /// Can occur only in measurement mode.
113        rh_t_error: bool = false,
114        _: bool, // reserved
115        /// Fan is switched on, but 0 RPM is measured for multiple consecutive measurement intervals.
116        /// This can occur if the fan is mechanically blocked or broken. Note that the measured values
117        /// are most likely wrong if this error is reported.
118        ///
119        /// Can occur only in measurement mode.
120        fan_error: bool = false,
121        _: u8{4},
122    }
123}
124
125define_sensirion_commands! {
126    id_len 2;
127    marker [
128        ("sensirion-sen63c", crate::devices::sensirion::sen63c::SEN63CCommand),
129    ];
130
131    /// Returns the measured values. The command [`GetDataReady`] can be used to check if new data is
132    /// available since the last read operation. If no new data is available, the previous values will
133    /// be returned. If no data is available at all (e.g. measurement not running for at least one
134    /// second), all values will be at their upper limit (0xFFFF for u16, 0x7FFF for i16).
135    ///
136    /// May be executed during measurement.
137    read 0x0471 time_ms=20 ReadMeasuredValues() -> MeasuredValues;
138
139    /// Returns the measured raw values. The command [`GetDataReady`] can be used to check if new data
140    /// is available since the last read operation. If no new data is available, the previous values
141    /// will be returned. If no data is available at all (e.g. measurement not running for at least one
142    /// second), all values will be at their upper limit (0xFFFF for u16, 0x7FFF for i16).
143    ///
144    /// May be executed during measurement.
145    read 0x0492 time_ms=20 ReadMeasuredRawValues() -> MeasuredRawValues;
146
147    /// Reads the current device status.
148    ///
149    /// Note: The status flags of type `Error` are sticky, i.e. they are not cleared automatically even
150    /// if the error condition no longer exists. So, they can only be cleared manually with
151    /// [`ReadAndClearDeviceStatus`] or through a reset, either by calling [`DeviceReset`] or through a
152    /// power cycle. All other flags are not sticky, i.e. they are cleared automatically if the trigger
153    /// condition disappears.
154    ///
155    /// May be executed during measurement.
156    read 0xd206 time_ms=20 ReadDeviceStatus() -> DeviceStatus;
157
158    /// Reads the current device status (like command [`ReadDeviceStatus`]) and clears all
159    /// flags afterwards.
160    ///
161    /// May be executed during measurement.
162    read 0xd210 time_ms=20 ReadAndClearDeviceStatus() -> DeviceStatus;
163}