tinkerforge_async/bindings/
air_quality_bricklet.rs

1/* ***********************************************************
2 * This file was automatically generated on 2024-02-16.      *
3 *                                                           *
4 * Rust Bindings Version 2.0.20                              *
5 *                                                           *
6 * If you have a bugfix for this file and want to commit it, *
7 * please fix the bug in the generator. You can find a link  *
8 * to the generators git repository on tinkerforge.com       *
9 *************************************************************/
10
11//! Measures IAQ index, temperature, humidity and air pressure.
12//!
13//! See also the documentation [here](https://www.tinkerforge.com/en/doc/Software/Bricklets/AirQuality_Bricklet_Rust.html).
14#[allow(unused_imports)]
15use crate::{
16    base58::Uid, byte_converter::*, device::*, error::TinkerforgeError, ip_connection::async_io::AsyncIpConnection,
17    low_level_traits::LowLevelRead,
18};
19#[allow(unused_imports)]
20use futures_core::Stream;
21#[allow(unused_imports)]
22use tokio_stream::StreamExt;
23pub enum AirQualityBrickletFunction {
24    GetAllValues,
25    SetTemperatureOffset,
26    GetTemperatureOffset,
27    SetAllValuesCallbackConfiguration,
28    GetAllValuesCallbackConfiguration,
29    GetIaqIndex,
30    SetIaqIndexCallbackConfiguration,
31    GetIaqIndexCallbackConfiguration,
32    GetTemperature,
33    SetTemperatureCallbackConfiguration,
34    GetTemperatureCallbackConfiguration,
35    GetHumidity,
36    SetHumidityCallbackConfiguration,
37    GetHumidityCallbackConfiguration,
38    GetAirPressure,
39    SetAirPressureCallbackConfiguration,
40    GetAirPressureCallbackConfiguration,
41    RemoveCalibration,
42    SetBackgroundCalibrationDuration,
43    GetBackgroundCalibrationDuration,
44    GetSpitfpErrorCount,
45    SetBootloaderMode,
46    GetBootloaderMode,
47    SetWriteFirmwarePointer,
48    WriteFirmware,
49    SetStatusLedConfig,
50    GetStatusLedConfig,
51    GetChipTemperature,
52    Reset,
53    WriteUid,
54    ReadUid,
55    GetIdentity,
56    CallbackAllValues,
57    CallbackIaqIndex,
58    CallbackTemperature,
59    CallbackHumidity,
60    CallbackAirPressure,
61}
62impl From<AirQualityBrickletFunction> for u8 {
63    fn from(fun: AirQualityBrickletFunction) -> Self {
64        match fun {
65            AirQualityBrickletFunction::GetAllValues => 1,
66            AirQualityBrickletFunction::SetTemperatureOffset => 2,
67            AirQualityBrickletFunction::GetTemperatureOffset => 3,
68            AirQualityBrickletFunction::SetAllValuesCallbackConfiguration => 4,
69            AirQualityBrickletFunction::GetAllValuesCallbackConfiguration => 5,
70            AirQualityBrickletFunction::GetIaqIndex => 7,
71            AirQualityBrickletFunction::SetIaqIndexCallbackConfiguration => 8,
72            AirQualityBrickletFunction::GetIaqIndexCallbackConfiguration => 9,
73            AirQualityBrickletFunction::GetTemperature => 11,
74            AirQualityBrickletFunction::SetTemperatureCallbackConfiguration => 12,
75            AirQualityBrickletFunction::GetTemperatureCallbackConfiguration => 13,
76            AirQualityBrickletFunction::GetHumidity => 15,
77            AirQualityBrickletFunction::SetHumidityCallbackConfiguration => 16,
78            AirQualityBrickletFunction::GetHumidityCallbackConfiguration => 17,
79            AirQualityBrickletFunction::GetAirPressure => 19,
80            AirQualityBrickletFunction::SetAirPressureCallbackConfiguration => 20,
81            AirQualityBrickletFunction::GetAirPressureCallbackConfiguration => 21,
82            AirQualityBrickletFunction::RemoveCalibration => 23,
83            AirQualityBrickletFunction::SetBackgroundCalibrationDuration => 24,
84            AirQualityBrickletFunction::GetBackgroundCalibrationDuration => 25,
85            AirQualityBrickletFunction::GetSpitfpErrorCount => 234,
86            AirQualityBrickletFunction::SetBootloaderMode => 235,
87            AirQualityBrickletFunction::GetBootloaderMode => 236,
88            AirQualityBrickletFunction::SetWriteFirmwarePointer => 237,
89            AirQualityBrickletFunction::WriteFirmware => 238,
90            AirQualityBrickletFunction::SetStatusLedConfig => 239,
91            AirQualityBrickletFunction::GetStatusLedConfig => 240,
92            AirQualityBrickletFunction::GetChipTemperature => 242,
93            AirQualityBrickletFunction::Reset => 243,
94            AirQualityBrickletFunction::WriteUid => 248,
95            AirQualityBrickletFunction::ReadUid => 249,
96            AirQualityBrickletFunction::GetIdentity => 255,
97            AirQualityBrickletFunction::CallbackAllValues => 6,
98            AirQualityBrickletFunction::CallbackIaqIndex => 10,
99            AirQualityBrickletFunction::CallbackTemperature => 14,
100            AirQualityBrickletFunction::CallbackHumidity => 18,
101            AirQualityBrickletFunction::CallbackAirPressure => 22,
102        }
103    }
104}
105pub const AIR_QUALITY_BRICKLET_ACCURACY_UNRELIABLE: u8 = 0;
106pub const AIR_QUALITY_BRICKLET_ACCURACY_LOW: u8 = 1;
107pub const AIR_QUALITY_BRICKLET_ACCURACY_MEDIUM: u8 = 2;
108pub const AIR_QUALITY_BRICKLET_ACCURACY_HIGH: u8 = 3;
109pub const AIR_QUALITY_BRICKLET_THRESHOLD_OPTION_OFF: char = 'x';
110pub const AIR_QUALITY_BRICKLET_THRESHOLD_OPTION_OUTSIDE: char = 'o';
111pub const AIR_QUALITY_BRICKLET_THRESHOLD_OPTION_INSIDE: char = 'i';
112pub const AIR_QUALITY_BRICKLET_THRESHOLD_OPTION_SMALLER: char = '<';
113pub const AIR_QUALITY_BRICKLET_THRESHOLD_OPTION_GREATER: char = '>';
114pub const AIR_QUALITY_BRICKLET_DURATION_4_DAYS: u8 = 0;
115pub const AIR_QUALITY_BRICKLET_DURATION_28_DAYS: u8 = 1;
116pub const AIR_QUALITY_BRICKLET_BOOTLOADER_MODE_BOOTLOADER: u8 = 0;
117pub const AIR_QUALITY_BRICKLET_BOOTLOADER_MODE_FIRMWARE: u8 = 1;
118pub const AIR_QUALITY_BRICKLET_BOOTLOADER_MODE_BOOTLOADER_WAIT_FOR_REBOOT: u8 = 2;
119pub const AIR_QUALITY_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_REBOOT: u8 = 3;
120pub const AIR_QUALITY_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_ERASE_AND_REBOOT: u8 = 4;
121pub const AIR_QUALITY_BRICKLET_BOOTLOADER_STATUS_OK: u8 = 0;
122pub const AIR_QUALITY_BRICKLET_BOOTLOADER_STATUS_INVALID_MODE: u8 = 1;
123pub const AIR_QUALITY_BRICKLET_BOOTLOADER_STATUS_NO_CHANGE: u8 = 2;
124pub const AIR_QUALITY_BRICKLET_BOOTLOADER_STATUS_ENTRY_FUNCTION_NOT_PRESENT: u8 = 3;
125pub const AIR_QUALITY_BRICKLET_BOOTLOADER_STATUS_DEVICE_IDENTIFIER_INCORRECT: u8 = 4;
126pub const AIR_QUALITY_BRICKLET_BOOTLOADER_STATUS_CRC_MISMATCH: u8 = 5;
127pub const AIR_QUALITY_BRICKLET_STATUS_LED_CONFIG_OFF: u8 = 0;
128pub const AIR_QUALITY_BRICKLET_STATUS_LED_CONFIG_ON: u8 = 1;
129pub const AIR_QUALITY_BRICKLET_STATUS_LED_CONFIG_SHOW_HEARTBEAT: u8 = 2;
130pub const AIR_QUALITY_BRICKLET_STATUS_LED_CONFIG_SHOW_STATUS: u8 = 3;
131
132#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
133pub struct AllValues {
134    pub iaq_index: i32,
135    pub iaq_index_accuracy: u8,
136    pub temperature: i32,
137    pub humidity: i32,
138    pub air_pressure: i32,
139}
140impl FromByteSlice for AllValues {
141    fn bytes_expected() -> usize {
142        17
143    }
144    fn from_le_byte_slice(bytes: &[u8]) -> AllValues {
145        AllValues {
146            iaq_index: <i32>::from_le_byte_slice(&bytes[0..4]),
147            iaq_index_accuracy: <u8>::from_le_byte_slice(&bytes[4..5]),
148            temperature: <i32>::from_le_byte_slice(&bytes[5..9]),
149            humidity: <i32>::from_le_byte_slice(&bytes[9..13]),
150            air_pressure: <i32>::from_le_byte_slice(&bytes[13..17]),
151        }
152    }
153}
154
155#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
156pub struct AllValuesCallbackConfiguration {
157    pub period: u32,
158    pub value_has_to_change: bool,
159}
160impl FromByteSlice for AllValuesCallbackConfiguration {
161    fn bytes_expected() -> usize {
162        5
163    }
164    fn from_le_byte_slice(bytes: &[u8]) -> AllValuesCallbackConfiguration {
165        AllValuesCallbackConfiguration {
166            period: <u32>::from_le_byte_slice(&bytes[0..4]),
167            value_has_to_change: <bool>::from_le_byte_slice(&bytes[4..5]),
168        }
169    }
170}
171
172#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
173pub struct AllValuesEvent {
174    pub iaq_index: i32,
175    pub iaq_index_accuracy: u8,
176    pub temperature: i32,
177    pub humidity: i32,
178    pub air_pressure: i32,
179}
180impl FromByteSlice for AllValuesEvent {
181    fn bytes_expected() -> usize {
182        17
183    }
184    fn from_le_byte_slice(bytes: &[u8]) -> AllValuesEvent {
185        AllValuesEvent {
186            iaq_index: <i32>::from_le_byte_slice(&bytes[0..4]),
187            iaq_index_accuracy: <u8>::from_le_byte_slice(&bytes[4..5]),
188            temperature: <i32>::from_le_byte_slice(&bytes[5..9]),
189            humidity: <i32>::from_le_byte_slice(&bytes[9..13]),
190            air_pressure: <i32>::from_le_byte_slice(&bytes[13..17]),
191        }
192    }
193}
194
195#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
196pub struct IaqIndex {
197    pub iaq_index: i32,
198    pub iaq_index_accuracy: u8,
199}
200impl FromByteSlice for IaqIndex {
201    fn bytes_expected() -> usize {
202        5
203    }
204    fn from_le_byte_slice(bytes: &[u8]) -> IaqIndex {
205        IaqIndex { iaq_index: <i32>::from_le_byte_slice(&bytes[0..4]), iaq_index_accuracy: <u8>::from_le_byte_slice(&bytes[4..5]) }
206    }
207}
208
209#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
210pub struct IaqIndexCallbackConfiguration {
211    pub period: u32,
212    pub value_has_to_change: bool,
213}
214impl FromByteSlice for IaqIndexCallbackConfiguration {
215    fn bytes_expected() -> usize {
216        5
217    }
218    fn from_le_byte_slice(bytes: &[u8]) -> IaqIndexCallbackConfiguration {
219        IaqIndexCallbackConfiguration {
220            period: <u32>::from_le_byte_slice(&bytes[0..4]),
221            value_has_to_change: <bool>::from_le_byte_slice(&bytes[4..5]),
222        }
223    }
224}
225
226#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
227pub struct IaqIndexEvent {
228    pub iaq_index: i32,
229    pub iaq_index_accuracy: u8,
230}
231impl FromByteSlice for IaqIndexEvent {
232    fn bytes_expected() -> usize {
233        5
234    }
235    fn from_le_byte_slice(bytes: &[u8]) -> IaqIndexEvent {
236        IaqIndexEvent { iaq_index: <i32>::from_le_byte_slice(&bytes[0..4]), iaq_index_accuracy: <u8>::from_le_byte_slice(&bytes[4..5]) }
237    }
238}
239
240#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
241pub struct TemperatureCallbackConfiguration {
242    pub period: u32,
243    pub value_has_to_change: bool,
244    pub option: char,
245    pub min: i32,
246    pub max: i32,
247}
248impl FromByteSlice for TemperatureCallbackConfiguration {
249    fn bytes_expected() -> usize {
250        14
251    }
252    fn from_le_byte_slice(bytes: &[u8]) -> TemperatureCallbackConfiguration {
253        TemperatureCallbackConfiguration {
254            period: <u32>::from_le_byte_slice(&bytes[0..4]),
255            value_has_to_change: <bool>::from_le_byte_slice(&bytes[4..5]),
256            option: <char>::from_le_byte_slice(&bytes[5..6]),
257            min: <i32>::from_le_byte_slice(&bytes[6..10]),
258            max: <i32>::from_le_byte_slice(&bytes[10..14]),
259        }
260    }
261}
262
263#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
264pub struct HumidityCallbackConfiguration {
265    pub period: u32,
266    pub value_has_to_change: bool,
267    pub option: char,
268    pub min: i32,
269    pub max: i32,
270}
271impl FromByteSlice for HumidityCallbackConfiguration {
272    fn bytes_expected() -> usize {
273        14
274    }
275    fn from_le_byte_slice(bytes: &[u8]) -> HumidityCallbackConfiguration {
276        HumidityCallbackConfiguration {
277            period: <u32>::from_le_byte_slice(&bytes[0..4]),
278            value_has_to_change: <bool>::from_le_byte_slice(&bytes[4..5]),
279            option: <char>::from_le_byte_slice(&bytes[5..6]),
280            min: <i32>::from_le_byte_slice(&bytes[6..10]),
281            max: <i32>::from_le_byte_slice(&bytes[10..14]),
282        }
283    }
284}
285
286#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
287pub struct AirPressureCallbackConfiguration {
288    pub period: u32,
289    pub value_has_to_change: bool,
290    pub option: char,
291    pub min: i32,
292    pub max: i32,
293}
294impl FromByteSlice for AirPressureCallbackConfiguration {
295    fn bytes_expected() -> usize {
296        14
297    }
298    fn from_le_byte_slice(bytes: &[u8]) -> AirPressureCallbackConfiguration {
299        AirPressureCallbackConfiguration {
300            period: <u32>::from_le_byte_slice(&bytes[0..4]),
301            value_has_to_change: <bool>::from_le_byte_slice(&bytes[4..5]),
302            option: <char>::from_le_byte_slice(&bytes[5..6]),
303            min: <i32>::from_le_byte_slice(&bytes[6..10]),
304            max: <i32>::from_le_byte_slice(&bytes[10..14]),
305        }
306    }
307}
308
309#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
310pub struct SpitfpErrorCount {
311    pub error_count_ack_checksum: u32,
312    pub error_count_message_checksum: u32,
313    pub error_count_frame: u32,
314    pub error_count_overflow: u32,
315}
316impl FromByteSlice for SpitfpErrorCount {
317    fn bytes_expected() -> usize {
318        16
319    }
320    fn from_le_byte_slice(bytes: &[u8]) -> SpitfpErrorCount {
321        SpitfpErrorCount {
322            error_count_ack_checksum: <u32>::from_le_byte_slice(&bytes[0..4]),
323            error_count_message_checksum: <u32>::from_le_byte_slice(&bytes[4..8]),
324            error_count_frame: <u32>::from_le_byte_slice(&bytes[8..12]),
325            error_count_overflow: <u32>::from_le_byte_slice(&bytes[12..16]),
326        }
327    }
328}
329
330#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
331pub struct Identity {
332    pub uid: String,
333    pub connected_uid: String,
334    pub position: char,
335    pub hardware_version: [u8; 3],
336    pub firmware_version: [u8; 3],
337    pub device_identifier: u16,
338}
339impl FromByteSlice for Identity {
340    fn bytes_expected() -> usize {
341        25
342    }
343    fn from_le_byte_slice(bytes: &[u8]) -> Identity {
344        Identity {
345            uid: <String>::from_le_byte_slice(&bytes[0..8]),
346            connected_uid: <String>::from_le_byte_slice(&bytes[8..16]),
347            position: <char>::from_le_byte_slice(&bytes[16..17]),
348            hardware_version: <[u8; 3]>::from_le_byte_slice(&bytes[17..20]),
349            firmware_version: <[u8; 3]>::from_le_byte_slice(&bytes[20..23]),
350            device_identifier: <u16>::from_le_byte_slice(&bytes[23..25]),
351        }
352    }
353}
354
355/// Measures IAQ index, temperature, humidity and air pressure
356#[derive(Clone)]
357pub struct AirQualityBricklet {
358    device: Device,
359}
360impl AirQualityBricklet {
361    pub const DEVICE_IDENTIFIER: u16 = 297;
362    pub const DEVICE_DISPLAY_NAME: &'static str = "Air Quality Bricklet";
363    /// Creates an object with the unique device ID `uid`. This object can then be used after the IP Connection `ip_connection` is connected.
364    pub fn new(uid: Uid, connection: AsyncIpConnection) -> AirQualityBricklet {
365        let mut result = AirQualityBricklet { device: Device::new([2, 0, 10], uid, connection, Self::DEVICE_DISPLAY_NAME) };
366        result.device.response_expected[u8::from(AirQualityBrickletFunction::GetAllValues) as usize] = ResponseExpectedFlag::AlwaysTrue;
367        result.device.response_expected[u8::from(AirQualityBrickletFunction::SetTemperatureOffset) as usize] = ResponseExpectedFlag::False;
368        result.device.response_expected[u8::from(AirQualityBrickletFunction::GetTemperatureOffset) as usize] =
369            ResponseExpectedFlag::AlwaysTrue;
370        result.device.response_expected[u8::from(AirQualityBrickletFunction::SetAllValuesCallbackConfiguration) as usize] =
371            ResponseExpectedFlag::True;
372        result.device.response_expected[u8::from(AirQualityBrickletFunction::GetAllValuesCallbackConfiguration) as usize] =
373            ResponseExpectedFlag::AlwaysTrue;
374        result.device.response_expected[u8::from(AirQualityBrickletFunction::GetIaqIndex) as usize] = ResponseExpectedFlag::AlwaysTrue;
375        result.device.response_expected[u8::from(AirQualityBrickletFunction::SetIaqIndexCallbackConfiguration) as usize] =
376            ResponseExpectedFlag::True;
377        result.device.response_expected[u8::from(AirQualityBrickletFunction::GetIaqIndexCallbackConfiguration) as usize] =
378            ResponseExpectedFlag::AlwaysTrue;
379        result.device.response_expected[u8::from(AirQualityBrickletFunction::GetTemperature) as usize] = ResponseExpectedFlag::AlwaysTrue;
380        result.device.response_expected[u8::from(AirQualityBrickletFunction::SetTemperatureCallbackConfiguration) as usize] =
381            ResponseExpectedFlag::True;
382        result.device.response_expected[u8::from(AirQualityBrickletFunction::GetTemperatureCallbackConfiguration) as usize] =
383            ResponseExpectedFlag::AlwaysTrue;
384        result.device.response_expected[u8::from(AirQualityBrickletFunction::GetHumidity) as usize] = ResponseExpectedFlag::AlwaysTrue;
385        result.device.response_expected[u8::from(AirQualityBrickletFunction::SetHumidityCallbackConfiguration) as usize] =
386            ResponseExpectedFlag::True;
387        result.device.response_expected[u8::from(AirQualityBrickletFunction::GetHumidityCallbackConfiguration) as usize] =
388            ResponseExpectedFlag::AlwaysTrue;
389        result.device.response_expected[u8::from(AirQualityBrickletFunction::GetAirPressure) as usize] = ResponseExpectedFlag::AlwaysTrue;
390        result.device.response_expected[u8::from(AirQualityBrickletFunction::SetAirPressureCallbackConfiguration) as usize] =
391            ResponseExpectedFlag::True;
392        result.device.response_expected[u8::from(AirQualityBrickletFunction::GetAirPressureCallbackConfiguration) as usize] =
393            ResponseExpectedFlag::AlwaysTrue;
394        result.device.response_expected[u8::from(AirQualityBrickletFunction::RemoveCalibration) as usize] = ResponseExpectedFlag::False;
395        result.device.response_expected[u8::from(AirQualityBrickletFunction::SetBackgroundCalibrationDuration) as usize] =
396            ResponseExpectedFlag::False;
397        result.device.response_expected[u8::from(AirQualityBrickletFunction::GetBackgroundCalibrationDuration) as usize] =
398            ResponseExpectedFlag::AlwaysTrue;
399        result.device.response_expected[u8::from(AirQualityBrickletFunction::GetSpitfpErrorCount) as usize] =
400            ResponseExpectedFlag::AlwaysTrue;
401        result.device.response_expected[u8::from(AirQualityBrickletFunction::SetBootloaderMode) as usize] =
402            ResponseExpectedFlag::AlwaysTrue;
403        result.device.response_expected[u8::from(AirQualityBrickletFunction::GetBootloaderMode) as usize] =
404            ResponseExpectedFlag::AlwaysTrue;
405        result.device.response_expected[u8::from(AirQualityBrickletFunction::SetWriteFirmwarePointer) as usize] =
406            ResponseExpectedFlag::False;
407        result.device.response_expected[u8::from(AirQualityBrickletFunction::WriteFirmware) as usize] = ResponseExpectedFlag::AlwaysTrue;
408        result.device.response_expected[u8::from(AirQualityBrickletFunction::SetStatusLedConfig) as usize] = ResponseExpectedFlag::False;
409        result.device.response_expected[u8::from(AirQualityBrickletFunction::GetStatusLedConfig) as usize] =
410            ResponseExpectedFlag::AlwaysTrue;
411        result.device.response_expected[u8::from(AirQualityBrickletFunction::GetChipTemperature) as usize] =
412            ResponseExpectedFlag::AlwaysTrue;
413        result.device.response_expected[u8::from(AirQualityBrickletFunction::Reset) as usize] = ResponseExpectedFlag::False;
414        result.device.response_expected[u8::from(AirQualityBrickletFunction::WriteUid) as usize] = ResponseExpectedFlag::False;
415        result.device.response_expected[u8::from(AirQualityBrickletFunction::ReadUid) as usize] = ResponseExpectedFlag::AlwaysTrue;
416        result.device.response_expected[u8::from(AirQualityBrickletFunction::GetIdentity) as usize] = ResponseExpectedFlag::AlwaysTrue;
417        result
418    }
419
420    /// Returns the response expected flag for the function specified by the function ID parameter.
421    /// It is true if the function is expected to send a response, false otherwise.
422    ///
423    /// For getter functions this is enabled by default and cannot be disabled, because those
424    /// functions will always send a response. For callback configuration functions it is enabled
425    /// by default too, but can be disabled by [`set_response_expected`](crate::air_quality_bricklet::AirQualityBricklet::set_response_expected).
426    /// For setter functions it is disabled by default and can be enabled.
427    ///
428    /// Enabling the response expected flag for a setter function allows to detect timeouts
429    /// and other error conditions calls of this setter as well. The device will then send a response
430    /// for this purpose. If this flag is disabled for a setter function then no response is sent
431    /// and errors are silently ignored, because they cannot be detected.
432    ///
433    /// See [`set_response_expected`](crate::air_quality_bricklet::AirQualityBricklet::set_response_expected) for the list of function ID constants available for this function.
434    pub fn get_response_expected(&mut self, fun: AirQualityBrickletFunction) -> Result<bool, GetResponseExpectedError> {
435        self.device.get_response_expected(u8::from(fun))
436    }
437
438    /// Changes the response expected flag of the function specified by the function ID parameter.
439    /// This flag can only be changed for setter (default value: false) and callback configuration
440    /// functions (default value: true). For getter functions it is always enabled.
441    ///
442    /// Enabling the response expected flag for a setter function allows to detect timeouts and
443    /// other error conditions calls of this setter as well. The device will then send a response
444    /// for this purpose. If this flag is disabled for a setter function then no response is sent
445    /// and errors are silently ignored, because they cannot be detected.
446    pub fn set_response_expected(
447        &mut self,
448        fun: AirQualityBrickletFunction,
449        response_expected: bool,
450    ) -> Result<(), SetResponseExpectedError> {
451        self.device.set_response_expected(u8::from(fun), response_expected)
452    }
453
454    /// Changes the response expected flag for all setter and callback configuration functions of this device at once.
455    pub fn set_response_expected_all(&mut self, response_expected: bool) {
456        self.device.set_response_expected_all(response_expected)
457    }
458
459    /// Returns the version of the API definition (major, minor, revision) implemented by this API bindings.
460    /// This is neither the release version of this API bindings nor does it tell you anything about the represented Brick or Bricklet.
461    pub fn get_api_version(&self) -> [u8; 3] {
462        self.device.api_version
463    }
464
465    /// This receiver is triggered periodically according to the configuration set by
466    /// [`set_all_values_callback_configuration`].
467    ///
468    /// The parameters are the same as [`get_all_values`].
469    ///
470    /// [`get_all_values`]: #method.get_all_values
471    /// [`set_all_values_callback_configuration`]: #method.set_all_values_callback_configuration
472    pub async fn get_all_values_callback_receiver(&mut self) -> impl Stream<Item = AllValuesEvent> {
473        self.device
474            .get_callback_receiver(u8::from(AirQualityBrickletFunction::CallbackAllValues))
475            .await
476            .map(|p| AllValuesEvent::from_le_byte_slice(p.body()))
477    }
478
479    /// This receiver is triggered periodically according to the configuration set by
480    /// [`set_iaq_index_callback_configuration`].
481    ///
482    /// The parameters are the same as [`get_iaq_index`].
483    pub async fn get_iaq_index_callback_receiver(&mut self) -> impl Stream<Item = IaqIndexEvent> {
484        self.device
485            .get_callback_receiver(u8::from(AirQualityBrickletFunction::CallbackIaqIndex))
486            .await
487            .map(|p| IaqIndexEvent::from_le_byte_slice(p.body()))
488    }
489
490    /// This receiver is triggered periodically according to the configuration set by
491    /// [`set_temperature_callback_configuration`].
492    ///
493    /// The parameter is the same as [`get_temperature`].
494    pub async fn get_temperature_callback_receiver(&mut self) -> impl Stream<Item = i32> {
495        self.device
496            .get_callback_receiver(u8::from(AirQualityBrickletFunction::CallbackTemperature))
497            .await
498            .map(|p| i32::from_le_byte_slice(p.body()))
499    }
500
501    /// This receiver is triggered periodically according to the configuration set by
502    /// [`set_humidity_callback_configuration`].
503    ///
504    /// The parameter is the same as [`get_humidity`].
505    pub async fn get_humidity_callback_receiver(&mut self) -> impl Stream<Item = i32> {
506        self.device
507            .get_callback_receiver(u8::from(AirQualityBrickletFunction::CallbackHumidity))
508            .await
509            .map(|p| i32::from_le_byte_slice(p.body()))
510    }
511
512    /// This receiver is triggered periodically according to the configuration set by
513    /// [`set_air_pressure_callback_configuration`].
514    ///
515    /// The parameter is the same as [`get_air_pressure`].
516    pub async fn get_air_pressure_callback_receiver(&mut self) -> impl Stream<Item = i32> {
517        self.device
518            .get_callback_receiver(u8::from(AirQualityBrickletFunction::CallbackAirPressure))
519            .await
520            .map(|p| i32::from_le_byte_slice(p.body()))
521    }
522
523    /// Returns all values measured by the Air Quality Bricklet. The values are
524    /// IAQ (Indoor Air Quality) Index (higher value means greater level of air pollution), IAQ Index Accuracy, Temperature, Humidity and
525    /// Air Pressure.
526    ///
527    /// .. image:: /Images/Misc/bricklet_air_quality_iaq_index.png
528    ///    :scale: 100 %
529    ///    :alt: Air Quality Index description
530    ///    :align: center
531    ///    :target: ../../_images/Misc/bricklet_air_quality_iaq_index.png
532    ///
533    /// Associated constants:
534    /// * AIR_QUALITY_BRICKLET_ACCURACY_UNRELIABLE
535    ///	* AIR_QUALITY_BRICKLET_ACCURACY_LOW
536    ///	* AIR_QUALITY_BRICKLET_ACCURACY_MEDIUM
537    ///	* AIR_QUALITY_BRICKLET_ACCURACY_HIGH
538    pub async fn get_all_values(&mut self) -> Result<AllValues, TinkerforgeError> {
539        let payload = [0; 0];
540
541        #[allow(unused_variables)]
542        let result = self.device.get(u8::from(AirQualityBrickletFunction::GetAllValues), &payload).await?;
543        Ok(AllValues::from_le_byte_slice(result.body()))
544    }
545
546    /// Sets a temperature offset. A offset of 10 will decrease the measured temperature by 0.1 °C.
547    ///
548    /// If you install this Bricklet into an enclosure and you want to measure the ambient
549    /// temperature, you may have to decrease the measured temperature by some value to
550    /// compensate for the error because of the heating inside of the enclosure.
551    ///
552    /// We recommend that you leave the parts in the enclosure running for at least
553    /// 24 hours such that a temperature equilibrium can be reached. After that you can measure
554    /// the temperature directly outside of enclosure and set the difference as offset.
555    ///
556    /// This temperature offset is used to calculate the relative humidity and
557    /// IAQ index measurements. In case the Bricklet is installed in an enclosure, we
558    /// recommend to measure and set the temperature offset to improve the accuracy of
559    /// the measurements.
560    pub async fn set_temperature_offset(&mut self, offset: i32) -> Result<(), TinkerforgeError> {
561        let mut payload = [0; 4];
562        offset.write_to_slice(&mut payload[0..4]);
563
564        #[allow(unused_variables)]
565        let result = self.device.set(u8::from(AirQualityBrickletFunction::SetTemperatureOffset), &payload).await?;
566        Ok(())
567    }
568
569    /// Returns the temperature offset as set by
570    /// [`set_temperature_offset`].
571    pub async fn get_temperature_offset(&mut self) -> Result<i32, TinkerforgeError> {
572        let payload = [0; 0];
573
574        #[allow(unused_variables)]
575        let result = self.device.get(u8::from(AirQualityBrickletFunction::GetTemperatureOffset), &payload).await?;
576        Ok(i32::from_le_byte_slice(result.body()))
577    }
578
579    /// The period is the period with which the [`get_all_values_callback_receiver`]
580    /// receiver is triggered periodically. A value of 0 turns the receiver off.
581    ///
582    /// If the `value has to change`-parameter is set to true, the receiver is only
583    /// triggered after at least one of the values has changed. If the values didn't
584    /// change within the period, the receiver is triggered immediately on change.
585    ///
586    /// If it is set to false, the receiver is continuously triggered with the period,
587    /// independent of the value.
588    pub async fn set_all_values_callback_configuration(&mut self, period: u32, value_has_to_change: bool) -> Result<(), TinkerforgeError> {
589        let mut payload = [0; 5];
590        period.write_to_slice(&mut payload[0..4]);
591        value_has_to_change.write_to_slice(&mut payload[4..5]);
592
593        #[allow(unused_variables)]
594        let result = self.device.set(u8::from(AirQualityBrickletFunction::SetAllValuesCallbackConfiguration), &payload).await?;
595        Ok(())
596    }
597
598    /// Returns the receiver configuration as set by
599    /// [`set_all_values_callback_configuration`].
600    pub async fn get_all_values_callback_configuration(&mut self) -> Result<AllValuesCallbackConfiguration, TinkerforgeError> {
601        let payload = [0; 0];
602
603        #[allow(unused_variables)]
604        let result = self.device.get(u8::from(AirQualityBrickletFunction::GetAllValuesCallbackConfiguration), &payload).await?;
605        Ok(AllValuesCallbackConfiguration::from_le_byte_slice(result.body()))
606    }
607
608    /// Returns the IAQ index and accuracy. The higher the IAQ index, the greater the level of air pollution.
609    ///
610    /// .. image:: /Images/Misc/bricklet_air_quality_iaq_index.png
611    ///    :scale: 100 %
612    ///    :alt: IAQ index description
613    ///    :align: center
614    ///    :target: ../../_images/Misc/bricklet_air_quality_iaq_index.png
615    ///
616    /// If you want to get the value periodically, it is recommended to use the
617    /// [`get_iaq_index_callback_receiver`] receiver. You can set the receiver configuration
618    /// with [`set_iaq_index_callback_configuration`].
619    ///
620    /// Associated constants:
621    /// * AIR_QUALITY_BRICKLET_ACCURACY_UNRELIABLE
622    ///	* AIR_QUALITY_BRICKLET_ACCURACY_LOW
623    ///	* AIR_QUALITY_BRICKLET_ACCURACY_MEDIUM
624    ///	* AIR_QUALITY_BRICKLET_ACCURACY_HIGH
625    pub async fn get_iaq_index(&mut self) -> Result<IaqIndex, TinkerforgeError> {
626        let payload = [0; 0];
627
628        #[allow(unused_variables)]
629        let result = self.device.get(u8::from(AirQualityBrickletFunction::GetIaqIndex), &payload).await?;
630        Ok(IaqIndex::from_le_byte_slice(result.body()))
631    }
632
633    /// The period is the period with which the [`get_iaq_index_callback_receiver`]
634    /// receiver is triggered periodically. A value of 0 turns the receiver off.
635    ///
636    /// If the `value has to change`-parameter is set to true, the receiver is only
637    /// triggered after at least one of the values has changed. If the values didn't
638    /// change within the period, the receiver is triggered immediately on change.
639    ///
640    /// If it is set to false, the receiver is continuously triggered with the period,
641    /// independent of the value.
642    pub async fn set_iaq_index_callback_configuration(&mut self, period: u32, value_has_to_change: bool) -> Result<(), TinkerforgeError> {
643        let mut payload = [0; 5];
644        period.write_to_slice(&mut payload[0..4]);
645        value_has_to_change.write_to_slice(&mut payload[4..5]);
646
647        #[allow(unused_variables)]
648        let result = self.device.set(u8::from(AirQualityBrickletFunction::SetIaqIndexCallbackConfiguration), &payload).await?;
649        Ok(())
650    }
651
652    /// Returns the receiver configuration as set by
653    /// [`set_iaq_index_callback_configuration`].
654    pub async fn get_iaq_index_callback_configuration(&mut self) -> Result<IaqIndexCallbackConfiguration, TinkerforgeError> {
655        let payload = [0; 0];
656
657        #[allow(unused_variables)]
658        let result = self.device.get(u8::from(AirQualityBrickletFunction::GetIaqIndexCallbackConfiguration), &payload).await?;
659        Ok(IaqIndexCallbackConfiguration::from_le_byte_slice(result.body()))
660    }
661
662    /// Returns temperature.
663    ///
664    ///
665    /// If you want to get the value periodically, it is recommended to use the
666    /// [`get_temperature_callback_receiver`] receiver. You can set the receiver configuration
667    /// with [`set_temperature_callback_configuration`].
668    pub async fn get_temperature(&mut self) -> Result<i32, TinkerforgeError> {
669        let payload = [0; 0];
670
671        #[allow(unused_variables)]
672        let result = self.device.get(u8::from(AirQualityBrickletFunction::GetTemperature), &payload).await?;
673        Ok(i32::from_le_byte_slice(result.body()))
674    }
675
676    /// The period is the period with which the [`get_temperature_callback_receiver`] receiver is triggered
677    /// periodically. A value of 0 turns the receiver off.
678    ///
679    /// If the `value has to change`-parameter is set to true, the receiver is only
680    /// triggered after the value has changed. If the value didn't change
681    /// within the period, the receiver is triggered immediately on change.
682    ///
683    /// If it is set to false, the receiver is continuously triggered with the period,
684    /// independent of the value.
685    ///
686    /// It is furthermore possible to constrain the receiver with thresholds.
687    ///
688    /// The `option`-parameter together with min/max sets a threshold for the [`get_temperature_callback_receiver`] receiver.
689    ///
690    /// The following options are possible:
691    ///
692    ///  Option| Description
693    ///  --- | ---
694    ///  'x'|    Threshold is turned off
695    ///  'o'|    Threshold is triggered when the value is *outside* the min and max values
696    ///  'i'|    Threshold is triggered when the value is *inside* or equal to the min and max values
697    ///  '<'|    Threshold is triggered when the value is smaller than the min value (max is ignored)
698    ///  '>'|    Threshold is triggered when the value is greater than the min value (max is ignored)
699    ///
700    /// If the option is set to 'x' (threshold turned off) the receiver is triggered with the fixed period.
701    ///
702    /// Associated constants:
703    /// * AIR_QUALITY_BRICKLET_THRESHOLD_OPTION_OFF
704    ///	* AIR_QUALITY_BRICKLET_THRESHOLD_OPTION_OUTSIDE
705    ///	* AIR_QUALITY_BRICKLET_THRESHOLD_OPTION_INSIDE
706    ///	* AIR_QUALITY_BRICKLET_THRESHOLD_OPTION_SMALLER
707    ///	* AIR_QUALITY_BRICKLET_THRESHOLD_OPTION_GREATER
708    pub async fn set_temperature_callback_configuration(
709        &mut self,
710        period: u32,
711        value_has_to_change: bool,
712        option: char,
713        min: i32,
714        max: i32,
715    ) -> Result<(), TinkerforgeError> {
716        let mut payload = [0; 14];
717        period.write_to_slice(&mut payload[0..4]);
718        value_has_to_change.write_to_slice(&mut payload[4..5]);
719        option.write_to_slice(&mut payload[5..6]);
720        min.write_to_slice(&mut payload[6..10]);
721        max.write_to_slice(&mut payload[10..14]);
722
723        #[allow(unused_variables)]
724        let result = self.device.set(u8::from(AirQualityBrickletFunction::SetTemperatureCallbackConfiguration), &payload).await?;
725        Ok(())
726    }
727
728    /// Returns the receiver configuration as set by [`set_temperature_callback_configuration`].
729    ///
730    /// Associated constants:
731    /// * AIR_QUALITY_BRICKLET_THRESHOLD_OPTION_OFF
732    ///	* AIR_QUALITY_BRICKLET_THRESHOLD_OPTION_OUTSIDE
733    ///	* AIR_QUALITY_BRICKLET_THRESHOLD_OPTION_INSIDE
734    ///	* AIR_QUALITY_BRICKLET_THRESHOLD_OPTION_SMALLER
735    ///	* AIR_QUALITY_BRICKLET_THRESHOLD_OPTION_GREATER
736    pub async fn get_temperature_callback_configuration(&mut self) -> Result<TemperatureCallbackConfiguration, TinkerforgeError> {
737        let payload = [0; 0];
738
739        #[allow(unused_variables)]
740        let result = self.device.get(u8::from(AirQualityBrickletFunction::GetTemperatureCallbackConfiguration), &payload).await?;
741        Ok(TemperatureCallbackConfiguration::from_le_byte_slice(result.body()))
742    }
743
744    /// Returns relative humidity.
745    ///
746    ///
747    /// If you want to get the value periodically, it is recommended to use the
748    /// [`get_humidity_callback_receiver`] receiver. You can set the receiver configuration
749    /// with [`set_humidity_callback_configuration`].
750    pub async fn get_humidity(&mut self) -> Result<i32, TinkerforgeError> {
751        let payload = [0; 0];
752
753        #[allow(unused_variables)]
754        let result = self.device.get(u8::from(AirQualityBrickletFunction::GetHumidity), &payload).await?;
755        Ok(i32::from_le_byte_slice(result.body()))
756    }
757
758    /// The period is the period with which the [`get_humidity_callback_receiver`] receiver is triggered
759    /// periodically. A value of 0 turns the receiver off.
760    ///
761    /// If the `value has to change`-parameter is set to true, the receiver is only
762    /// triggered after the value has changed. If the value didn't change
763    /// within the period, the receiver is triggered immediately on change.
764    ///
765    /// If it is set to false, the receiver is continuously triggered with the period,
766    /// independent of the value.
767    ///
768    /// It is furthermore possible to constrain the receiver with thresholds.
769    ///
770    /// The `option`-parameter together with min/max sets a threshold for the [`get_humidity_callback_receiver`] receiver.
771    ///
772    /// The following options are possible:
773    ///
774    ///  Option| Description
775    ///  --- | ---
776    ///  'x'|    Threshold is turned off
777    ///  'o'|    Threshold is triggered when the value is *outside* the min and max values
778    ///  'i'|    Threshold is triggered when the value is *inside* or equal to the min and max values
779    ///  '<'|    Threshold is triggered when the value is smaller than the min value (max is ignored)
780    ///  '>'|    Threshold is triggered when the value is greater than the min value (max is ignored)
781    ///
782    /// If the option is set to 'x' (threshold turned off) the receiver is triggered with the fixed period.
783    ///
784    /// Associated constants:
785    /// * AIR_QUALITY_BRICKLET_THRESHOLD_OPTION_OFF
786    ///	* AIR_QUALITY_BRICKLET_THRESHOLD_OPTION_OUTSIDE
787    ///	* AIR_QUALITY_BRICKLET_THRESHOLD_OPTION_INSIDE
788    ///	* AIR_QUALITY_BRICKLET_THRESHOLD_OPTION_SMALLER
789    ///	* AIR_QUALITY_BRICKLET_THRESHOLD_OPTION_GREATER
790    pub async fn set_humidity_callback_configuration(
791        &mut self,
792        period: u32,
793        value_has_to_change: bool,
794        option: char,
795        min: i32,
796        max: i32,
797    ) -> Result<(), TinkerforgeError> {
798        let mut payload = [0; 14];
799        period.write_to_slice(&mut payload[0..4]);
800        value_has_to_change.write_to_slice(&mut payload[4..5]);
801        option.write_to_slice(&mut payload[5..6]);
802        min.write_to_slice(&mut payload[6..10]);
803        max.write_to_slice(&mut payload[10..14]);
804
805        #[allow(unused_variables)]
806        let result = self.device.set(u8::from(AirQualityBrickletFunction::SetHumidityCallbackConfiguration), &payload).await?;
807        Ok(())
808    }
809
810    /// Returns the receiver configuration as set by [`set_humidity_callback_configuration`].
811    ///
812    /// Associated constants:
813    /// * AIR_QUALITY_BRICKLET_THRESHOLD_OPTION_OFF
814    ///	* AIR_QUALITY_BRICKLET_THRESHOLD_OPTION_OUTSIDE
815    ///	* AIR_QUALITY_BRICKLET_THRESHOLD_OPTION_INSIDE
816    ///	* AIR_QUALITY_BRICKLET_THRESHOLD_OPTION_SMALLER
817    ///	* AIR_QUALITY_BRICKLET_THRESHOLD_OPTION_GREATER
818    pub async fn get_humidity_callback_configuration(&mut self) -> Result<HumidityCallbackConfiguration, TinkerforgeError> {
819        let payload = [0; 0];
820
821        #[allow(unused_variables)]
822        let result = self.device.get(u8::from(AirQualityBrickletFunction::GetHumidityCallbackConfiguration), &payload).await?;
823        Ok(HumidityCallbackConfiguration::from_le_byte_slice(result.body()))
824    }
825
826    /// Returns air pressure.
827    ///
828    ///
829    /// If you want to get the value periodically, it is recommended to use the
830    /// [`get_air_pressure_callback_receiver`] receiver. You can set the receiver configuration
831    /// with [`set_air_pressure_callback_configuration`].
832    pub async fn get_air_pressure(&mut self) -> Result<i32, TinkerforgeError> {
833        let payload = [0; 0];
834
835        #[allow(unused_variables)]
836        let result = self.device.get(u8::from(AirQualityBrickletFunction::GetAirPressure), &payload).await?;
837        Ok(i32::from_le_byte_slice(result.body()))
838    }
839
840    /// The period is the period with which the [`get_air_pressure_callback_receiver`] receiver is triggered
841    /// periodically. A value of 0 turns the receiver off.
842    ///
843    /// If the `value has to change`-parameter is set to true, the receiver is only
844    /// triggered after the value has changed. If the value didn't change
845    /// within the period, the receiver is triggered immediately on change.
846    ///
847    /// If it is set to false, the receiver is continuously triggered with the period,
848    /// independent of the value.
849    ///
850    /// It is furthermore possible to constrain the receiver with thresholds.
851    ///
852    /// The `option`-parameter together with min/max sets a threshold for the [`get_air_pressure_callback_receiver`] receiver.
853    ///
854    /// The following options are possible:
855    ///
856    ///  Option| Description
857    ///  --- | ---
858    ///  'x'|    Threshold is turned off
859    ///  'o'|    Threshold is triggered when the value is *outside* the min and max values
860    ///  'i'|    Threshold is triggered when the value is *inside* or equal to the min and max values
861    ///  '<'|    Threshold is triggered when the value is smaller than the min value (max is ignored)
862    ///  '>'|    Threshold is triggered when the value is greater than the min value (max is ignored)
863    ///
864    /// If the option is set to 'x' (threshold turned off) the receiver is triggered with the fixed period.
865    ///
866    /// Associated constants:
867    /// * AIR_QUALITY_BRICKLET_THRESHOLD_OPTION_OFF
868    ///	* AIR_QUALITY_BRICKLET_THRESHOLD_OPTION_OUTSIDE
869    ///	* AIR_QUALITY_BRICKLET_THRESHOLD_OPTION_INSIDE
870    ///	* AIR_QUALITY_BRICKLET_THRESHOLD_OPTION_SMALLER
871    ///	* AIR_QUALITY_BRICKLET_THRESHOLD_OPTION_GREATER
872    pub async fn set_air_pressure_callback_configuration(
873        &mut self,
874        period: u32,
875        value_has_to_change: bool,
876        option: char,
877        min: i32,
878        max: i32,
879    ) -> Result<(), TinkerforgeError> {
880        let mut payload = [0; 14];
881        period.write_to_slice(&mut payload[0..4]);
882        value_has_to_change.write_to_slice(&mut payload[4..5]);
883        option.write_to_slice(&mut payload[5..6]);
884        min.write_to_slice(&mut payload[6..10]);
885        max.write_to_slice(&mut payload[10..14]);
886
887        #[allow(unused_variables)]
888        let result = self.device.set(u8::from(AirQualityBrickletFunction::SetAirPressureCallbackConfiguration), &payload).await?;
889        Ok(())
890    }
891
892    /// Returns the receiver configuration as set by [`set_air_pressure_callback_configuration`].
893    ///
894    /// Associated constants:
895    /// * AIR_QUALITY_BRICKLET_THRESHOLD_OPTION_OFF
896    ///	* AIR_QUALITY_BRICKLET_THRESHOLD_OPTION_OUTSIDE
897    ///	* AIR_QUALITY_BRICKLET_THRESHOLD_OPTION_INSIDE
898    ///	* AIR_QUALITY_BRICKLET_THRESHOLD_OPTION_SMALLER
899    ///	* AIR_QUALITY_BRICKLET_THRESHOLD_OPTION_GREATER
900    pub async fn get_air_pressure_callback_configuration(&mut self) -> Result<AirPressureCallbackConfiguration, TinkerforgeError> {
901        let payload = [0; 0];
902
903        #[allow(unused_variables)]
904        let result = self.device.get(u8::from(AirQualityBrickletFunction::GetAirPressureCallbackConfiguration), &payload).await?;
905        Ok(AirPressureCallbackConfiguration::from_le_byte_slice(result.body()))
906    }
907
908    /// Deletes the calibration from flash. After you call this function,
909    /// you need to power cycle the Air Quality Bricklet.
910    ///
911    /// On the next power up the Bricklet will start a new calibration, as
912    /// if it was started for the very first time.
913    ///
914    /// The calibration is based on the data of the last four days, so it takes
915    /// four days until a full calibration is re-established.
916    ///
917    ///
918    /// .. versionadded:: 2.0.3$nbsp;(Plugin)
919    pub async fn remove_calibration(&mut self) -> Result<(), TinkerforgeError> {
920        let payload = [0; 0];
921
922        #[allow(unused_variables)]
923        let result = self.device.set(u8::from(AirQualityBrickletFunction::RemoveCalibration), &payload).await?;
924        Ok(())
925    }
926
927    /// The Air Quality Bricklet uses an automatic background calibration mechanism to
928    /// calculate the IAQ Index. This calibration mechanism considers a history of
929    /// measured data. The duration of this history can be configured to either be
930    /// 4 days or 28 days.
931    ///
932    /// If you keep the Bricklet mostly at one place and it does not get moved around
933    /// to different environments, we recommend that you use a duration of 28 days.
934    ///
935    /// If you change the duration, the current calibration will be discarded and
936    /// the calibration will start from beginning again. The configuration of the
937    /// duration is saved in flash, so you should only have to call this function
938    /// once in the lifetime of the Bricklet.
939    ///
940    /// The Bricklet has to be power cycled after this function is called
941    /// for a duration change to take effect.
942    ///
943    /// Before firmware version 2.0.3 this was not configurable and the duration was
944    /// 4 days.
945    ///
946    /// The default value (since firmware version 2.0.3) is 28 days.
947    ///
948    ///
949    /// .. versionadded:: 2.0.3$nbsp;(Plugin)
950    ///
951    /// Associated constants:
952    /// * AIR_QUALITY_BRICKLET_DURATION_4_DAYS
953    ///	* AIR_QUALITY_BRICKLET_DURATION_28_DAYS
954    pub async fn set_background_calibration_duration(&mut self, duration: u8) -> Result<(), TinkerforgeError> {
955        let mut payload = [0; 1];
956        duration.write_to_slice(&mut payload[0..1]);
957
958        #[allow(unused_variables)]
959        let result = self.device.set(u8::from(AirQualityBrickletFunction::SetBackgroundCalibrationDuration), &payload).await?;
960        Ok(())
961    }
962
963    /// Returns the background calibration duration as set by
964    /// [`set_background_calibration_duration`].
965    ///
966    ///
967    /// .. versionadded:: 2.0.3$nbsp;(Plugin)
968    ///
969    /// Associated constants:
970    /// * AIR_QUALITY_BRICKLET_DURATION_4_DAYS
971    ///	* AIR_QUALITY_BRICKLET_DURATION_28_DAYS
972    pub async fn get_background_calibration_duration(&mut self) -> Result<u8, TinkerforgeError> {
973        let payload = [0; 0];
974
975        #[allow(unused_variables)]
976        let result = self.device.get(u8::from(AirQualityBrickletFunction::GetBackgroundCalibrationDuration), &payload).await?;
977        Ok(u8::from_le_byte_slice(result.body()))
978    }
979
980    /// Returns the error count for the communication between Brick and Bricklet.
981    ///
982    /// The errors are divided into
983    ///
984    /// * ACK checksum errors,
985    /// * message checksum errors,
986    /// * framing errors and
987    /// * overflow errors.
988    ///
989    /// The errors counts are for errors that occur on the Bricklet side. All
990    /// Bricks have a similar function that returns the errors on the Brick side.
991    pub async fn get_spitfp_error_count(&mut self) -> Result<SpitfpErrorCount, TinkerforgeError> {
992        let payload = [0; 0];
993
994        #[allow(unused_variables)]
995        let result = self.device.get(u8::from(AirQualityBrickletFunction::GetSpitfpErrorCount), &payload).await?;
996        Ok(SpitfpErrorCount::from_le_byte_slice(result.body()))
997    }
998
999    /// Sets the bootloader mode and returns the status after the requested
1000    /// mode change was instigated.
1001    ///
1002    /// You can change from bootloader mode to firmware mode and vice versa. A change
1003    /// from bootloader mode to firmware mode will only take place if the entry function,
1004    /// device identifier and CRC are present and correct.
1005    ///
1006    /// This function is used by Brick Viewer during flashing. It should not be
1007    /// necessary to call it in a normal user program.
1008    ///
1009    /// Associated constants:
1010    /// * AIR_QUALITY_BRICKLET_BOOTLOADER_MODE_BOOTLOADER
1011    ///	* AIR_QUALITY_BRICKLET_BOOTLOADER_MODE_FIRMWARE
1012    ///	* AIR_QUALITY_BRICKLET_BOOTLOADER_MODE_BOOTLOADER_WAIT_FOR_REBOOT
1013    ///	* AIR_QUALITY_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_REBOOT
1014    ///	* AIR_QUALITY_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_ERASE_AND_REBOOT
1015    ///	* AIR_QUALITY_BRICKLET_BOOTLOADER_STATUS_OK
1016    ///	* AIR_QUALITY_BRICKLET_BOOTLOADER_STATUS_INVALID_MODE
1017    ///	* AIR_QUALITY_BRICKLET_BOOTLOADER_STATUS_NO_CHANGE
1018    ///	* AIR_QUALITY_BRICKLET_BOOTLOADER_STATUS_ENTRY_FUNCTION_NOT_PRESENT
1019    ///	* AIR_QUALITY_BRICKLET_BOOTLOADER_STATUS_DEVICE_IDENTIFIER_INCORRECT
1020    ///	* AIR_QUALITY_BRICKLET_BOOTLOADER_STATUS_CRC_MISMATCH
1021    pub async fn set_bootloader_mode(&mut self, mode: u8) -> Result<u8, TinkerforgeError> {
1022        let mut payload = [0; 1];
1023        mode.write_to_slice(&mut payload[0..1]);
1024
1025        #[allow(unused_variables)]
1026        let result = self.device.get(u8::from(AirQualityBrickletFunction::SetBootloaderMode), &payload).await?;
1027        Ok(u8::from_le_byte_slice(result.body()))
1028    }
1029
1030    /// Returns the current bootloader mode, see [`set_bootloader_mode`].
1031    ///
1032    /// Associated constants:
1033    /// * AIR_QUALITY_BRICKLET_BOOTLOADER_MODE_BOOTLOADER
1034    ///	* AIR_QUALITY_BRICKLET_BOOTLOADER_MODE_FIRMWARE
1035    ///	* AIR_QUALITY_BRICKLET_BOOTLOADER_MODE_BOOTLOADER_WAIT_FOR_REBOOT
1036    ///	* AIR_QUALITY_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_REBOOT
1037    ///	* AIR_QUALITY_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_ERASE_AND_REBOOT
1038    pub async fn get_bootloader_mode(&mut self) -> Result<u8, TinkerforgeError> {
1039        let payload = [0; 0];
1040
1041        #[allow(unused_variables)]
1042        let result = self.device.get(u8::from(AirQualityBrickletFunction::GetBootloaderMode), &payload).await?;
1043        Ok(u8::from_le_byte_slice(result.body()))
1044    }
1045
1046    /// Sets the firmware pointer for [`write_firmware`]. The pointer has
1047    /// to be increased by chunks of size 64. The data is written to flash
1048    /// every 4 chunks (which equals to one page of size 256).
1049    ///
1050    /// This function is used by Brick Viewer during flashing. It should not be
1051    /// necessary to call it in a normal user program.
1052    pub async fn set_write_firmware_pointer(&mut self, pointer: u32) -> Result<(), TinkerforgeError> {
1053        let mut payload = [0; 4];
1054        pointer.write_to_slice(&mut payload[0..4]);
1055
1056        #[allow(unused_variables)]
1057        let result = self.device.set(u8::from(AirQualityBrickletFunction::SetWriteFirmwarePointer), &payload).await?;
1058        Ok(())
1059    }
1060
1061    /// Writes 64 Bytes of firmware at the position as written by
1062    /// [`set_write_firmware_pointer`] before. The firmware is written
1063    /// to flash every 4 chunks.
1064    ///
1065    /// You can only write firmware in bootloader mode.
1066    ///
1067    /// This function is used by Brick Viewer during flashing. It should not be
1068    /// necessary to call it in a normal user program.
1069    pub async fn write_firmware(&mut self, data: &[u8; 64]) -> Result<u8, TinkerforgeError> {
1070        let mut payload = [0; 64];
1071        data.write_to_slice(&mut payload[0..64]);
1072
1073        #[allow(unused_variables)]
1074        let result = self.device.get(u8::from(AirQualityBrickletFunction::WriteFirmware), &payload).await?;
1075        Ok(u8::from_le_byte_slice(result.body()))
1076    }
1077
1078    /// Sets the status LED configuration. By default the LED shows
1079    /// communication traffic between Brick and Bricklet, it flickers once
1080    /// for every 10 received data packets.
1081    ///
1082    /// You can also turn the LED permanently on/off or show a heartbeat.
1083    ///
1084    /// If the Bricklet is in bootloader mode, the LED is will show heartbeat by default.
1085    ///
1086    /// Associated constants:
1087    /// * AIR_QUALITY_BRICKLET_STATUS_LED_CONFIG_OFF
1088    ///	* AIR_QUALITY_BRICKLET_STATUS_LED_CONFIG_ON
1089    ///	* AIR_QUALITY_BRICKLET_STATUS_LED_CONFIG_SHOW_HEARTBEAT
1090    ///	* AIR_QUALITY_BRICKLET_STATUS_LED_CONFIG_SHOW_STATUS
1091    pub async fn set_status_led_config(&mut self, config: u8) -> Result<(), TinkerforgeError> {
1092        let mut payload = [0; 1];
1093        config.write_to_slice(&mut payload[0..1]);
1094
1095        #[allow(unused_variables)]
1096        let result = self.device.set(u8::from(AirQualityBrickletFunction::SetStatusLedConfig), &payload).await?;
1097        Ok(())
1098    }
1099
1100    /// Returns the configuration as set by [`set_status_led_config`]
1101    ///
1102    /// Associated constants:
1103    /// * AIR_QUALITY_BRICKLET_STATUS_LED_CONFIG_OFF
1104    ///	* AIR_QUALITY_BRICKLET_STATUS_LED_CONFIG_ON
1105    ///	* AIR_QUALITY_BRICKLET_STATUS_LED_CONFIG_SHOW_HEARTBEAT
1106    ///	* AIR_QUALITY_BRICKLET_STATUS_LED_CONFIG_SHOW_STATUS
1107    pub async fn get_status_led_config(&mut self) -> Result<u8, TinkerforgeError> {
1108        let payload = [0; 0];
1109
1110        #[allow(unused_variables)]
1111        let result = self.device.get(u8::from(AirQualityBrickletFunction::GetStatusLedConfig), &payload).await?;
1112        Ok(u8::from_le_byte_slice(result.body()))
1113    }
1114
1115    /// Returns the temperature as measured inside the microcontroller. The
1116    /// value returned is not the ambient temperature!
1117    ///
1118    /// The temperature is only proportional to the real temperature and it has bad
1119    /// accuracy. Practically it is only useful as an indicator for
1120    /// temperature changes.
1121    pub async fn get_chip_temperature(&mut self) -> Result<i16, TinkerforgeError> {
1122        let payload = [0; 0];
1123
1124        #[allow(unused_variables)]
1125        let result = self.device.get(u8::from(AirQualityBrickletFunction::GetChipTemperature), &payload).await?;
1126        Ok(i16::from_le_byte_slice(result.body()))
1127    }
1128
1129    /// Calling this function will reset the Bricklet. All configurations
1130    /// will be lost.
1131    ///
1132    /// After a reset you have to create new device objects,
1133    /// calling functions on the existing ones will result in
1134    /// undefined behavior!
1135    pub async fn reset(&mut self) -> Result<(), TinkerforgeError> {
1136        let payload = [0; 0];
1137
1138        #[allow(unused_variables)]
1139        let result = self.device.set(u8::from(AirQualityBrickletFunction::Reset), &payload).await?;
1140        Ok(())
1141    }
1142
1143    /// Writes a new UID into flash. If you want to set a new UID
1144    /// you have to decode the Base58 encoded UID string into an
1145    /// integer first.
1146    ///
1147    /// We recommend that you use Brick Viewer to change the UID.
1148    pub async fn write_uid(&mut self, uid: u32) -> Result<(), TinkerforgeError> {
1149        let mut payload = [0; 4];
1150        uid.write_to_slice(&mut payload[0..4]);
1151
1152        #[allow(unused_variables)]
1153        let result = self.device.set(u8::from(AirQualityBrickletFunction::WriteUid), &payload).await?;
1154        Ok(())
1155    }
1156
1157    /// Returns the current UID as an integer. Encode as
1158    /// Base58 to get the usual string version.
1159    pub async fn read_uid(&mut self) -> Result<u32, TinkerforgeError> {
1160        let payload = [0; 0];
1161
1162        #[allow(unused_variables)]
1163        let result = self.device.get(u8::from(AirQualityBrickletFunction::ReadUid), &payload).await?;
1164        Ok(u32::from_le_byte_slice(result.body()))
1165    }
1166
1167    /// Returns the UID, the UID where the Bricklet is connected to,
1168    /// the position, the hardware and firmware version as well as the
1169    /// device identifier.
1170    ///
1171    /// The position can be 'a', 'b', 'c', 'd', 'e', 'f', 'g' or 'h' (Bricklet Port).
1172    /// A Bricklet connected to an [Isolator Bricklet](isolator_bricklet) is always at
1173    /// position 'z'.
1174    ///
1175    /// The device identifier numbers can be found [here](device_identifier).
1176    /// |device_identifier_constant|
1177    pub async fn get_identity(&mut self) -> Result<Identity, TinkerforgeError> {
1178        let payload = [0; 0];
1179
1180        #[allow(unused_variables)]
1181        let result = self.device.get(u8::from(AirQualityBrickletFunction::GetIdentity), &payload).await?;
1182        Ok(Identity::from_le_byte_slice(result.body()))
1183    }
1184}