tinkerforge_async/bindings/
co2_v2_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 CO2 concentration, temperature and humidity.
12//!
13//! See also the documentation [here](https://www.tinkerforge.com/en/doc/Software/Bricklets/CO2V2_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 Co2V2BrickletFunction {
24    GetAllValues,
25    SetAirPressure,
26    GetAirPressure,
27    SetTemperatureOffset,
28    GetTemperatureOffset,
29    SetAllValuesCallbackConfiguration,
30    GetAllValuesCallbackConfiguration,
31    GetCo2Concentration,
32    SetCo2ConcentrationCallbackConfiguration,
33    GetCo2ConcentrationCallbackConfiguration,
34    GetTemperature,
35    SetTemperatureCallbackConfiguration,
36    GetTemperatureCallbackConfiguration,
37    GetHumidity,
38    SetHumidityCallbackConfiguration,
39    GetHumidityCallbackConfiguration,
40    GetSpitfpErrorCount,
41    SetBootloaderMode,
42    GetBootloaderMode,
43    SetWriteFirmwarePointer,
44    WriteFirmware,
45    SetStatusLedConfig,
46    GetStatusLedConfig,
47    GetChipTemperature,
48    Reset,
49    WriteUid,
50    ReadUid,
51    GetIdentity,
52    CallbackAllValues,
53    CallbackCo2Concentration,
54    CallbackTemperature,
55    CallbackHumidity,
56}
57impl From<Co2V2BrickletFunction> for u8 {
58    fn from(fun: Co2V2BrickletFunction) -> Self {
59        match fun {
60            Co2V2BrickletFunction::GetAllValues => 1,
61            Co2V2BrickletFunction::SetAirPressure => 2,
62            Co2V2BrickletFunction::GetAirPressure => 3,
63            Co2V2BrickletFunction::SetTemperatureOffset => 4,
64            Co2V2BrickletFunction::GetTemperatureOffset => 5,
65            Co2V2BrickletFunction::SetAllValuesCallbackConfiguration => 6,
66            Co2V2BrickletFunction::GetAllValuesCallbackConfiguration => 7,
67            Co2V2BrickletFunction::GetCo2Concentration => 9,
68            Co2V2BrickletFunction::SetCo2ConcentrationCallbackConfiguration => 10,
69            Co2V2BrickletFunction::GetCo2ConcentrationCallbackConfiguration => 11,
70            Co2V2BrickletFunction::GetTemperature => 13,
71            Co2V2BrickletFunction::SetTemperatureCallbackConfiguration => 14,
72            Co2V2BrickletFunction::GetTemperatureCallbackConfiguration => 15,
73            Co2V2BrickletFunction::GetHumidity => 17,
74            Co2V2BrickletFunction::SetHumidityCallbackConfiguration => 18,
75            Co2V2BrickletFunction::GetHumidityCallbackConfiguration => 19,
76            Co2V2BrickletFunction::GetSpitfpErrorCount => 234,
77            Co2V2BrickletFunction::SetBootloaderMode => 235,
78            Co2V2BrickletFunction::GetBootloaderMode => 236,
79            Co2V2BrickletFunction::SetWriteFirmwarePointer => 237,
80            Co2V2BrickletFunction::WriteFirmware => 238,
81            Co2V2BrickletFunction::SetStatusLedConfig => 239,
82            Co2V2BrickletFunction::GetStatusLedConfig => 240,
83            Co2V2BrickletFunction::GetChipTemperature => 242,
84            Co2V2BrickletFunction::Reset => 243,
85            Co2V2BrickletFunction::WriteUid => 248,
86            Co2V2BrickletFunction::ReadUid => 249,
87            Co2V2BrickletFunction::GetIdentity => 255,
88            Co2V2BrickletFunction::CallbackAllValues => 8,
89            Co2V2BrickletFunction::CallbackCo2Concentration => 12,
90            Co2V2BrickletFunction::CallbackTemperature => 16,
91            Co2V2BrickletFunction::CallbackHumidity => 20,
92        }
93    }
94}
95pub const CO2_V2_BRICKLET_THRESHOLD_OPTION_OFF: char = 'x';
96pub const CO2_V2_BRICKLET_THRESHOLD_OPTION_OUTSIDE: char = 'o';
97pub const CO2_V2_BRICKLET_THRESHOLD_OPTION_INSIDE: char = 'i';
98pub const CO2_V2_BRICKLET_THRESHOLD_OPTION_SMALLER: char = '<';
99pub const CO2_V2_BRICKLET_THRESHOLD_OPTION_GREATER: char = '>';
100pub const CO2_V2_BRICKLET_BOOTLOADER_MODE_BOOTLOADER: u8 = 0;
101pub const CO2_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE: u8 = 1;
102pub const CO2_V2_BRICKLET_BOOTLOADER_MODE_BOOTLOADER_WAIT_FOR_REBOOT: u8 = 2;
103pub const CO2_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_REBOOT: u8 = 3;
104pub const CO2_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_ERASE_AND_REBOOT: u8 = 4;
105pub const CO2_V2_BRICKLET_BOOTLOADER_STATUS_OK: u8 = 0;
106pub const CO2_V2_BRICKLET_BOOTLOADER_STATUS_INVALID_MODE: u8 = 1;
107pub const CO2_V2_BRICKLET_BOOTLOADER_STATUS_NO_CHANGE: u8 = 2;
108pub const CO2_V2_BRICKLET_BOOTLOADER_STATUS_ENTRY_FUNCTION_NOT_PRESENT: u8 = 3;
109pub const CO2_V2_BRICKLET_BOOTLOADER_STATUS_DEVICE_IDENTIFIER_INCORRECT: u8 = 4;
110pub const CO2_V2_BRICKLET_BOOTLOADER_STATUS_CRC_MISMATCH: u8 = 5;
111pub const CO2_V2_BRICKLET_STATUS_LED_CONFIG_OFF: u8 = 0;
112pub const CO2_V2_BRICKLET_STATUS_LED_CONFIG_ON: u8 = 1;
113pub const CO2_V2_BRICKLET_STATUS_LED_CONFIG_SHOW_HEARTBEAT: u8 = 2;
114pub const CO2_V2_BRICKLET_STATUS_LED_CONFIG_SHOW_STATUS: u8 = 3;
115
116#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
117pub struct AllValues {
118    pub co2_concentration: u16,
119    pub temperature: i16,
120    pub humidity: u16,
121}
122impl FromByteSlice for AllValues {
123    fn bytes_expected() -> usize {
124        6
125    }
126    fn from_le_byte_slice(bytes: &[u8]) -> AllValues {
127        AllValues {
128            co2_concentration: <u16>::from_le_byte_slice(&bytes[0..2]),
129            temperature: <i16>::from_le_byte_slice(&bytes[2..4]),
130            humidity: <u16>::from_le_byte_slice(&bytes[4..6]),
131        }
132    }
133}
134
135#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
136pub struct AllValuesCallbackConfiguration {
137    pub period: u32,
138    pub value_has_to_change: bool,
139}
140impl FromByteSlice for AllValuesCallbackConfiguration {
141    fn bytes_expected() -> usize {
142        5
143    }
144    fn from_le_byte_slice(bytes: &[u8]) -> AllValuesCallbackConfiguration {
145        AllValuesCallbackConfiguration {
146            period: <u32>::from_le_byte_slice(&bytes[0..4]),
147            value_has_to_change: <bool>::from_le_byte_slice(&bytes[4..5]),
148        }
149    }
150}
151
152#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
153pub struct AllValuesEvent {
154    pub co2_concentration: u16,
155    pub temperature: i16,
156    pub humidity: u16,
157}
158impl FromByteSlice for AllValuesEvent {
159    fn bytes_expected() -> usize {
160        6
161    }
162    fn from_le_byte_slice(bytes: &[u8]) -> AllValuesEvent {
163        AllValuesEvent {
164            co2_concentration: <u16>::from_le_byte_slice(&bytes[0..2]),
165            temperature: <i16>::from_le_byte_slice(&bytes[2..4]),
166            humidity: <u16>::from_le_byte_slice(&bytes[4..6]),
167        }
168    }
169}
170
171#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
172pub struct Co2ConcentrationCallbackConfiguration {
173    pub period: u32,
174    pub value_has_to_change: bool,
175    pub option: char,
176    pub min: u16,
177    pub max: u16,
178}
179impl FromByteSlice for Co2ConcentrationCallbackConfiguration {
180    fn bytes_expected() -> usize {
181        10
182    }
183    fn from_le_byte_slice(bytes: &[u8]) -> Co2ConcentrationCallbackConfiguration {
184        Co2ConcentrationCallbackConfiguration {
185            period: <u32>::from_le_byte_slice(&bytes[0..4]),
186            value_has_to_change: <bool>::from_le_byte_slice(&bytes[4..5]),
187            option: <char>::from_le_byte_slice(&bytes[5..6]),
188            min: <u16>::from_le_byte_slice(&bytes[6..8]),
189            max: <u16>::from_le_byte_slice(&bytes[8..10]),
190        }
191    }
192}
193
194#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
195pub struct TemperatureCallbackConfiguration {
196    pub period: u32,
197    pub value_has_to_change: bool,
198    pub option: char,
199    pub min: i16,
200    pub max: i16,
201}
202impl FromByteSlice for TemperatureCallbackConfiguration {
203    fn bytes_expected() -> usize {
204        10
205    }
206    fn from_le_byte_slice(bytes: &[u8]) -> TemperatureCallbackConfiguration {
207        TemperatureCallbackConfiguration {
208            period: <u32>::from_le_byte_slice(&bytes[0..4]),
209            value_has_to_change: <bool>::from_le_byte_slice(&bytes[4..5]),
210            option: <char>::from_le_byte_slice(&bytes[5..6]),
211            min: <i16>::from_le_byte_slice(&bytes[6..8]),
212            max: <i16>::from_le_byte_slice(&bytes[8..10]),
213        }
214    }
215}
216
217#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
218pub struct HumidityCallbackConfiguration {
219    pub period: u32,
220    pub value_has_to_change: bool,
221    pub option: char,
222    pub min: u16,
223    pub max: u16,
224}
225impl FromByteSlice for HumidityCallbackConfiguration {
226    fn bytes_expected() -> usize {
227        10
228    }
229    fn from_le_byte_slice(bytes: &[u8]) -> HumidityCallbackConfiguration {
230        HumidityCallbackConfiguration {
231            period: <u32>::from_le_byte_slice(&bytes[0..4]),
232            value_has_to_change: <bool>::from_le_byte_slice(&bytes[4..5]),
233            option: <char>::from_le_byte_slice(&bytes[5..6]),
234            min: <u16>::from_le_byte_slice(&bytes[6..8]),
235            max: <u16>::from_le_byte_slice(&bytes[8..10]),
236        }
237    }
238}
239
240#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
241pub struct SpitfpErrorCount {
242    pub error_count_ack_checksum: u32,
243    pub error_count_message_checksum: u32,
244    pub error_count_frame: u32,
245    pub error_count_overflow: u32,
246}
247impl FromByteSlice for SpitfpErrorCount {
248    fn bytes_expected() -> usize {
249        16
250    }
251    fn from_le_byte_slice(bytes: &[u8]) -> SpitfpErrorCount {
252        SpitfpErrorCount {
253            error_count_ack_checksum: <u32>::from_le_byte_slice(&bytes[0..4]),
254            error_count_message_checksum: <u32>::from_le_byte_slice(&bytes[4..8]),
255            error_count_frame: <u32>::from_le_byte_slice(&bytes[8..12]),
256            error_count_overflow: <u32>::from_le_byte_slice(&bytes[12..16]),
257        }
258    }
259}
260
261#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
262pub struct Identity {
263    pub uid: String,
264    pub connected_uid: String,
265    pub position: char,
266    pub hardware_version: [u8; 3],
267    pub firmware_version: [u8; 3],
268    pub device_identifier: u16,
269}
270impl FromByteSlice for Identity {
271    fn bytes_expected() -> usize {
272        25
273    }
274    fn from_le_byte_slice(bytes: &[u8]) -> Identity {
275        Identity {
276            uid: <String>::from_le_byte_slice(&bytes[0..8]),
277            connected_uid: <String>::from_le_byte_slice(&bytes[8..16]),
278            position: <char>::from_le_byte_slice(&bytes[16..17]),
279            hardware_version: <[u8; 3]>::from_le_byte_slice(&bytes[17..20]),
280            firmware_version: <[u8; 3]>::from_le_byte_slice(&bytes[20..23]),
281            device_identifier: <u16>::from_le_byte_slice(&bytes[23..25]),
282        }
283    }
284}
285
286/// Measures CO2 concentration, temperature and humidity
287#[derive(Clone)]
288pub struct Co2V2Bricklet {
289    device: Device,
290}
291impl Co2V2Bricklet {
292    pub const DEVICE_IDENTIFIER: u16 = 2147;
293    pub const DEVICE_DISPLAY_NAME: &'static str = "CO2 Bricklet 2.0";
294    /// Creates an object with the unique device ID `uid`. This object can then be used after the IP Connection `ip_connection` is connected.
295    pub fn new(uid: Uid, connection: AsyncIpConnection) -> Co2V2Bricklet {
296        let mut result = Co2V2Bricklet { device: Device::new([2, 0, 10], uid, connection, Self::DEVICE_DISPLAY_NAME) };
297        result.device.response_expected[u8::from(Co2V2BrickletFunction::GetAllValues) as usize] = ResponseExpectedFlag::AlwaysTrue;
298        result.device.response_expected[u8::from(Co2V2BrickletFunction::SetAirPressure) as usize] = ResponseExpectedFlag::False;
299        result.device.response_expected[u8::from(Co2V2BrickletFunction::GetAirPressure) as usize] = ResponseExpectedFlag::AlwaysTrue;
300        result.device.response_expected[u8::from(Co2V2BrickletFunction::SetTemperatureOffset) as usize] = ResponseExpectedFlag::False;
301        result.device.response_expected[u8::from(Co2V2BrickletFunction::GetTemperatureOffset) as usize] = ResponseExpectedFlag::AlwaysTrue;
302        result.device.response_expected[u8::from(Co2V2BrickletFunction::SetAllValuesCallbackConfiguration) as usize] =
303            ResponseExpectedFlag::True;
304        result.device.response_expected[u8::from(Co2V2BrickletFunction::GetAllValuesCallbackConfiguration) as usize] =
305            ResponseExpectedFlag::AlwaysTrue;
306        result.device.response_expected[u8::from(Co2V2BrickletFunction::GetCo2Concentration) as usize] = ResponseExpectedFlag::AlwaysTrue;
307        result.device.response_expected[u8::from(Co2V2BrickletFunction::SetCo2ConcentrationCallbackConfiguration) as usize] =
308            ResponseExpectedFlag::True;
309        result.device.response_expected[u8::from(Co2V2BrickletFunction::GetCo2ConcentrationCallbackConfiguration) as usize] =
310            ResponseExpectedFlag::AlwaysTrue;
311        result.device.response_expected[u8::from(Co2V2BrickletFunction::GetTemperature) as usize] = ResponseExpectedFlag::AlwaysTrue;
312        result.device.response_expected[u8::from(Co2V2BrickletFunction::SetTemperatureCallbackConfiguration) as usize] =
313            ResponseExpectedFlag::True;
314        result.device.response_expected[u8::from(Co2V2BrickletFunction::GetTemperatureCallbackConfiguration) as usize] =
315            ResponseExpectedFlag::AlwaysTrue;
316        result.device.response_expected[u8::from(Co2V2BrickletFunction::GetHumidity) as usize] = ResponseExpectedFlag::AlwaysTrue;
317        result.device.response_expected[u8::from(Co2V2BrickletFunction::SetHumidityCallbackConfiguration) as usize] =
318            ResponseExpectedFlag::True;
319        result.device.response_expected[u8::from(Co2V2BrickletFunction::GetHumidityCallbackConfiguration) as usize] =
320            ResponseExpectedFlag::AlwaysTrue;
321        result.device.response_expected[u8::from(Co2V2BrickletFunction::GetSpitfpErrorCount) as usize] = ResponseExpectedFlag::AlwaysTrue;
322        result.device.response_expected[u8::from(Co2V2BrickletFunction::SetBootloaderMode) as usize] = ResponseExpectedFlag::AlwaysTrue;
323        result.device.response_expected[u8::from(Co2V2BrickletFunction::GetBootloaderMode) as usize] = ResponseExpectedFlag::AlwaysTrue;
324        result.device.response_expected[u8::from(Co2V2BrickletFunction::SetWriteFirmwarePointer) as usize] = ResponseExpectedFlag::False;
325        result.device.response_expected[u8::from(Co2V2BrickletFunction::WriteFirmware) as usize] = ResponseExpectedFlag::AlwaysTrue;
326        result.device.response_expected[u8::from(Co2V2BrickletFunction::SetStatusLedConfig) as usize] = ResponseExpectedFlag::False;
327        result.device.response_expected[u8::from(Co2V2BrickletFunction::GetStatusLedConfig) as usize] = ResponseExpectedFlag::AlwaysTrue;
328        result.device.response_expected[u8::from(Co2V2BrickletFunction::GetChipTemperature) as usize] = ResponseExpectedFlag::AlwaysTrue;
329        result.device.response_expected[u8::from(Co2V2BrickletFunction::Reset) as usize] = ResponseExpectedFlag::False;
330        result.device.response_expected[u8::from(Co2V2BrickletFunction::WriteUid) as usize] = ResponseExpectedFlag::False;
331        result.device.response_expected[u8::from(Co2V2BrickletFunction::ReadUid) as usize] = ResponseExpectedFlag::AlwaysTrue;
332        result.device.response_expected[u8::from(Co2V2BrickletFunction::GetIdentity) as usize] = ResponseExpectedFlag::AlwaysTrue;
333        result
334    }
335
336    /// Returns the response expected flag for the function specified by the function ID parameter.
337    /// It is true if the function is expected to send a response, false otherwise.
338    ///
339    /// For getter functions this is enabled by default and cannot be disabled, because those
340    /// functions will always send a response. For callback configuration functions it is enabled
341    /// by default too, but can be disabled by [`set_response_expected`](crate::co2_v2_bricklet::Co2V2Bricklet::set_response_expected).
342    /// For setter functions it is disabled by default and can be enabled.
343    ///
344    /// Enabling the response expected flag for a setter function allows to detect timeouts
345    /// and other error conditions calls of this setter as well. The device will then send a response
346    /// for this purpose. If this flag is disabled for a setter function then no response is sent
347    /// and errors are silently ignored, because they cannot be detected.
348    ///
349    /// See [`set_response_expected`](crate::co2_v2_bricklet::Co2V2Bricklet::set_response_expected) for the list of function ID constants available for this function.
350    pub fn get_response_expected(&mut self, fun: Co2V2BrickletFunction) -> Result<bool, GetResponseExpectedError> {
351        self.device.get_response_expected(u8::from(fun))
352    }
353
354    /// Changes the response expected flag of the function specified by the function ID parameter.
355    /// This flag can only be changed for setter (default value: false) and callback configuration
356    /// functions (default value: true). For getter functions it is always enabled.
357    ///
358    /// Enabling the response expected flag for a setter function allows to detect timeouts and
359    /// other error conditions calls of this setter as well. The device will then send a response
360    /// for this purpose. If this flag is disabled for a setter function then no response is sent
361    /// and errors are silently ignored, because they cannot be detected.
362    pub fn set_response_expected(&mut self, fun: Co2V2BrickletFunction, response_expected: bool) -> Result<(), SetResponseExpectedError> {
363        self.device.set_response_expected(u8::from(fun), response_expected)
364    }
365
366    /// Changes the response expected flag for all setter and callback configuration functions of this device at once.
367    pub fn set_response_expected_all(&mut self, response_expected: bool) {
368        self.device.set_response_expected_all(response_expected)
369    }
370
371    /// Returns the version of the API definition (major, minor, revision) implemented by this API bindings.
372    /// This is neither the release version of this API bindings nor does it tell you anything about the represented Brick or Bricklet.
373    pub fn get_api_version(&self) -> [u8; 3] {
374        self.device.api_version
375    }
376
377    /// This receiver is triggered periodically according to the configuration set by
378    /// [`set_all_values_callback_configuration`].
379    ///
380    /// The parameters are the same as [`get_all_values`].
381    ///
382    /// # Note
383    ///  The sensor is able to messure up to 120 °C. However it is only specified up to 70 °C.
384    ///  Exposing the Bricklet to higher temperatures might result in permanent damage.
385    ///
386    /// [`get_all_values`]: #method.get_all_values
387    /// [`set_all_values_callback_configuration`]: #method.set_all_values_callback_configuration
388    pub async fn get_all_values_callback_receiver(&mut self) -> impl Stream<Item = AllValuesEvent> {
389        self.device
390            .get_callback_receiver(u8::from(Co2V2BrickletFunction::CallbackAllValues))
391            .await
392            .map(|p| AllValuesEvent::from_le_byte_slice(p.body()))
393    }
394
395    /// This receiver is triggered periodically according to the configuration set by
396    /// [`set_co2_concentration_callback_configuration`].
397    ///
398    /// The parameter is the same as [`get_co2_concentration`].
399    pub async fn get_co2_concentration_callback_receiver(&mut self) -> impl Stream<Item = u16> {
400        self.device
401            .get_callback_receiver(u8::from(Co2V2BrickletFunction::CallbackCo2Concentration))
402            .await
403            .map(|p| u16::from_le_byte_slice(p.body()))
404    }
405
406    /// This receiver is triggered periodically according to the configuration set by
407    /// [`set_temperature_callback_configuration`].
408    ///
409    /// The parameter is the same as [`get_temperature`].
410    pub async fn get_temperature_callback_receiver(&mut self) -> impl Stream<Item = i16> {
411        self.device
412            .get_callback_receiver(u8::from(Co2V2BrickletFunction::CallbackTemperature))
413            .await
414            .map(|p| i16::from_le_byte_slice(p.body()))
415    }
416
417    /// This receiver is triggered periodically according to the configuration set by
418    /// [`set_humidity_callback_configuration`].
419    ///
420    /// The parameter is the same as [`get_humidity`].
421    pub async fn get_humidity_callback_receiver(&mut self) -> impl Stream<Item = u16> {
422        self.device
423            .get_callback_receiver(u8::from(Co2V2BrickletFunction::CallbackHumidity))
424            .await
425            .map(|p| u16::from_le_byte_slice(p.body()))
426    }
427
428    /// Returns all values measured by the CO2 Bricklet 2.0.
429    ///
430    /// If you want to get the values periodically, it is recommended to use the
431    /// [`get_all_values_callback_receiver`] receiver. You can set the receiver configuration
432    /// with [`set_all_values_callback_configuration`].
433    ///
434    /// # Note
435    ///  The sensor is able to messure up to 120 °C. However it is only specified up to 70 °C.
436    ///  Exposing the Bricklet to higher temperatures might result in permanent damage.
437    pub async fn get_all_values(&mut self) -> Result<AllValues, TinkerforgeError> {
438        let payload = [0; 0];
439
440        #[allow(unused_variables)]
441        let result = self.device.get(u8::from(Co2V2BrickletFunction::GetAllValues), &payload).await?;
442        Ok(AllValues::from_le_byte_slice(result.body()))
443    }
444
445    /// The CO2 concentration depends (among other things) on the ambient air pressure.
446    ///
447    /// To increase the accuracy of the CO2 Bricklet 2.0 you can set the current air pressure.
448    /// You use the [Barometer Bricklet 2.0](barometer_v2_bricklet) or the
449    /// [Air Quality Bricklet](air_quality_bricklet) to get the current air pressure.
450    ///
451    /// By default air pressure compensation is disabled. Once you set a value it
452    /// will be used for compensation. You can turn the compensation off again by
453    /// setting the value to 0.
454    ///
455    /// It is sufficient to update the value every few minutes.
456    pub async fn set_air_pressure(&mut self, air_pressure: u16) -> Result<(), TinkerforgeError> {
457        let mut payload = [0; 2];
458        air_pressure.write_to_slice(&mut payload[0..2]);
459
460        #[allow(unused_variables)]
461        let result = self.device.set(u8::from(Co2V2BrickletFunction::SetAirPressure), &payload).await?;
462        Ok(())
463    }
464
465    /// Returns the ambient air pressure as set by [`set_air_pressure`].
466    pub async fn get_air_pressure(&mut self) -> Result<u16, TinkerforgeError> {
467        let payload = [0; 0];
468
469        #[allow(unused_variables)]
470        let result = self.device.get(u8::from(Co2V2BrickletFunction::GetAirPressure), &payload).await?;
471        Ok(u16::from_le_byte_slice(result.body()))
472    }
473
474    /// Sets a temperature offset. A offset of 10 will decrease
475    /// the measured temperature by 0.1 °C.
476    ///
477    /// If you install this Bricklet into an enclosure and you want to measure the ambient
478    /// temperature, you may have to decrease the measured temperature by some value to
479    /// compensate for the error because of the heating inside of the enclosure.
480    ///
481    /// We recommend that you leave the parts in the enclosure running for at least
482    /// 24 hours such that a temperature equilibrium can be reached. After that you can measure
483    /// the temperature directly outside of enclosure and set the difference as offset.
484    ///
485    /// This temperature offset is used to calculate the relative humidity and
486    /// CO2 concentration. In case the Bricklet is installed in an enclosure, we
487    /// recommend to measure and set the temperature offset to improve the accuracy of
488    /// the measurements.
489    ///
490    /// It is sufficient to set the temperature offset once. The offset is saved in
491    /// non-volatile memory and is applied again after a power loss.
492    pub async fn set_temperature_offset(&mut self, offset: u16) -> Result<(), TinkerforgeError> {
493        let mut payload = [0; 2];
494        offset.write_to_slice(&mut payload[0..2]);
495
496        #[allow(unused_variables)]
497        let result = self.device.set(u8::from(Co2V2BrickletFunction::SetTemperatureOffset), &payload).await?;
498        Ok(())
499    }
500
501    /// Returns the temperature offset as set by
502    /// [`set_temperature_offset`].
503    pub async fn get_temperature_offset(&mut self) -> Result<u16, TinkerforgeError> {
504        let payload = [0; 0];
505
506        #[allow(unused_variables)]
507        let result = self.device.get(u8::from(Co2V2BrickletFunction::GetTemperatureOffset), &payload).await?;
508        Ok(u16::from_le_byte_slice(result.body()))
509    }
510
511    /// The period is the period with which the [`get_all_values_callback_receiver`]
512    /// receiver is triggered periodically. A value of 0 turns the receiver off.
513    ///
514    /// If the `value has to change`-parameter is set to true, the receiver is only
515    /// triggered after at least one of the values has changed. If the values didn't
516    /// change within the period, the receiver is triggered immediately on change.
517    ///
518    /// If it is set to false, the receiver is continuously triggered with the period,
519    /// independent of the value.
520    pub async fn set_all_values_callback_configuration(&mut self, period: u32, value_has_to_change: bool) -> Result<(), TinkerforgeError> {
521        let mut payload = [0; 5];
522        period.write_to_slice(&mut payload[0..4]);
523        value_has_to_change.write_to_slice(&mut payload[4..5]);
524
525        #[allow(unused_variables)]
526        let result = self.device.set(u8::from(Co2V2BrickletFunction::SetAllValuesCallbackConfiguration), &payload).await?;
527        Ok(())
528    }
529
530    /// Returns the receiver configuration as set by
531    /// [`set_all_values_callback_configuration`].
532    pub async fn get_all_values_callback_configuration(&mut self) -> Result<AllValuesCallbackConfiguration, TinkerforgeError> {
533        let payload = [0; 0];
534
535        #[allow(unused_variables)]
536        let result = self.device.get(u8::from(Co2V2BrickletFunction::GetAllValuesCallbackConfiguration), &payload).await?;
537        Ok(AllValuesCallbackConfiguration::from_le_byte_slice(result.body()))
538    }
539
540    /// Returns CO2 concentration.
541    ///
542    ///
543    /// If you want to get the value periodically, it is recommended to use the
544    /// [`get_co2_concentration_callback_receiver`] receiver. You can set the receiver configuration
545    /// with [`set_co2_concentration_callback_configuration`].
546    pub async fn get_co2_concentration(&mut self) -> Result<u16, TinkerforgeError> {
547        let payload = [0; 0];
548
549        #[allow(unused_variables)]
550        let result = self.device.get(u8::from(Co2V2BrickletFunction::GetCo2Concentration), &payload).await?;
551        Ok(u16::from_le_byte_slice(result.body()))
552    }
553
554    /// The period is the period with which the [`get_co2_concentration_callback_receiver`] receiver is triggered
555    /// periodically. A value of 0 turns the receiver off.
556    ///
557    /// If the `value has to change`-parameter is set to true, the receiver is only
558    /// triggered after the value has changed. If the value didn't change
559    /// within the period, the receiver is triggered immediately on change.
560    ///
561    /// If it is set to false, the receiver is continuously triggered with the period,
562    /// independent of the value.
563    ///
564    /// It is furthermore possible to constrain the receiver with thresholds.
565    ///
566    /// The `option`-parameter together with min/max sets a threshold for the [`get_co2_concentration_callback_receiver`] receiver.
567    ///
568    /// The following options are possible:
569    ///
570    ///  Option| Description
571    ///  --- | ---
572    ///  'x'|    Threshold is turned off
573    ///  'o'|    Threshold is triggered when the value is *outside* the min and max values
574    ///  'i'|    Threshold is triggered when the value is *inside* or equal to the min and max values
575    ///  '<'|    Threshold is triggered when the value is smaller than the min value (max is ignored)
576    ///  '>'|    Threshold is triggered when the value is greater than the min value (max is ignored)
577    ///
578    /// If the option is set to 'x' (threshold turned off) the receiver is triggered with the fixed period.
579    ///
580    /// Associated constants:
581    /// * CO2_V2_BRICKLET_THRESHOLD_OPTION_OFF
582    ///	* CO2_V2_BRICKLET_THRESHOLD_OPTION_OUTSIDE
583    ///	* CO2_V2_BRICKLET_THRESHOLD_OPTION_INSIDE
584    ///	* CO2_V2_BRICKLET_THRESHOLD_OPTION_SMALLER
585    ///	* CO2_V2_BRICKLET_THRESHOLD_OPTION_GREATER
586    pub async fn set_co2_concentration_callback_configuration(
587        &mut self,
588        period: u32,
589        value_has_to_change: bool,
590        option: char,
591        min: u16,
592        max: u16,
593    ) -> Result<(), TinkerforgeError> {
594        let mut payload = [0; 10];
595        period.write_to_slice(&mut payload[0..4]);
596        value_has_to_change.write_to_slice(&mut payload[4..5]);
597        option.write_to_slice(&mut payload[5..6]);
598        min.write_to_slice(&mut payload[6..8]);
599        max.write_to_slice(&mut payload[8..10]);
600
601        #[allow(unused_variables)]
602        let result = self.device.set(u8::from(Co2V2BrickletFunction::SetCo2ConcentrationCallbackConfiguration), &payload).await?;
603        Ok(())
604    }
605
606    /// Returns the receiver configuration as set by [`set_co2_concentration_callback_configuration`].
607    ///
608    /// Associated constants:
609    /// * CO2_V2_BRICKLET_THRESHOLD_OPTION_OFF
610    ///	* CO2_V2_BRICKLET_THRESHOLD_OPTION_OUTSIDE
611    ///	* CO2_V2_BRICKLET_THRESHOLD_OPTION_INSIDE
612    ///	* CO2_V2_BRICKLET_THRESHOLD_OPTION_SMALLER
613    ///	* CO2_V2_BRICKLET_THRESHOLD_OPTION_GREATER
614    pub async fn get_co2_concentration_callback_configuration(
615        &mut self,
616    ) -> Result<Co2ConcentrationCallbackConfiguration, TinkerforgeError> {
617        let payload = [0; 0];
618
619        #[allow(unused_variables)]
620        let result = self.device.get(u8::from(Co2V2BrickletFunction::GetCo2ConcentrationCallbackConfiguration), &payload).await?;
621        Ok(Co2ConcentrationCallbackConfiguration::from_le_byte_slice(result.body()))
622    }
623
624    /// Returns temperature.
625    ///
626    /// # Note
627    ///  The sensor is able to messure up to 120 °C. However it is only specified up to 70 °C.
628    ///  Exposing the Bricklet to higher temperatures might result in permanent damage.
629    ///
630    ///
631    /// If you want to get the value periodically, it is recommended to use the
632    /// [`get_temperature_callback_receiver`] receiver. You can set the receiver configuration
633    /// with [`set_temperature_callback_configuration`].
634    pub async fn get_temperature(&mut self) -> Result<i16, TinkerforgeError> {
635        let payload = [0; 0];
636
637        #[allow(unused_variables)]
638        let result = self.device.get(u8::from(Co2V2BrickletFunction::GetTemperature), &payload).await?;
639        Ok(i16::from_le_byte_slice(result.body()))
640    }
641
642    /// The period is the period with which the [`get_temperature_callback_receiver`] receiver is triggered
643    /// periodically. A value of 0 turns the receiver off.
644    ///
645    /// If the `value has to change`-parameter is set to true, the receiver is only
646    /// triggered after the value has changed. If the value didn't change
647    /// within the period, the receiver is triggered immediately on change.
648    ///
649    /// If it is set to false, the receiver is continuously triggered with the period,
650    /// independent of the value.
651    ///
652    /// It is furthermore possible to constrain the receiver with thresholds.
653    ///
654    /// The `option`-parameter together with min/max sets a threshold for the [`get_temperature_callback_receiver`] receiver.
655    ///
656    /// The following options are possible:
657    ///
658    ///  Option| Description
659    ///  --- | ---
660    ///  'x'|    Threshold is turned off
661    ///  'o'|    Threshold is triggered when the value is *outside* the min and max values
662    ///  'i'|    Threshold is triggered when the value is *inside* or equal to the min and max values
663    ///  '<'|    Threshold is triggered when the value is smaller than the min value (max is ignored)
664    ///  '>'|    Threshold is triggered when the value is greater than the min value (max is ignored)
665    ///
666    /// If the option is set to 'x' (threshold turned off) the receiver is triggered with the fixed period.
667    ///
668    /// Associated constants:
669    /// * CO2_V2_BRICKLET_THRESHOLD_OPTION_OFF
670    ///	* CO2_V2_BRICKLET_THRESHOLD_OPTION_OUTSIDE
671    ///	* CO2_V2_BRICKLET_THRESHOLD_OPTION_INSIDE
672    ///	* CO2_V2_BRICKLET_THRESHOLD_OPTION_SMALLER
673    ///	* CO2_V2_BRICKLET_THRESHOLD_OPTION_GREATER
674    pub async fn set_temperature_callback_configuration(
675        &mut self,
676        period: u32,
677        value_has_to_change: bool,
678        option: char,
679        min: i16,
680        max: i16,
681    ) -> Result<(), TinkerforgeError> {
682        let mut payload = [0; 10];
683        period.write_to_slice(&mut payload[0..4]);
684        value_has_to_change.write_to_slice(&mut payload[4..5]);
685        option.write_to_slice(&mut payload[5..6]);
686        min.write_to_slice(&mut payload[6..8]);
687        max.write_to_slice(&mut payload[8..10]);
688
689        #[allow(unused_variables)]
690        let result = self.device.set(u8::from(Co2V2BrickletFunction::SetTemperatureCallbackConfiguration), &payload).await?;
691        Ok(())
692    }
693
694    /// Returns the receiver configuration as set by [`set_temperature_callback_configuration`].
695    ///
696    /// Associated constants:
697    /// * CO2_V2_BRICKLET_THRESHOLD_OPTION_OFF
698    ///	* CO2_V2_BRICKLET_THRESHOLD_OPTION_OUTSIDE
699    ///	* CO2_V2_BRICKLET_THRESHOLD_OPTION_INSIDE
700    ///	* CO2_V2_BRICKLET_THRESHOLD_OPTION_SMALLER
701    ///	* CO2_V2_BRICKLET_THRESHOLD_OPTION_GREATER
702    pub async fn get_temperature_callback_configuration(&mut self) -> Result<TemperatureCallbackConfiguration, TinkerforgeError> {
703        let payload = [0; 0];
704
705        #[allow(unused_variables)]
706        let result = self.device.get(u8::from(Co2V2BrickletFunction::GetTemperatureCallbackConfiguration), &payload).await?;
707        Ok(TemperatureCallbackConfiguration::from_le_byte_slice(result.body()))
708    }
709
710    /// Returns relative humidity.
711    ///
712    ///
713    /// If you want to get the value periodically, it is recommended to use the
714    /// [`get_humidity_callback_receiver`] receiver. You can set the receiver configuration
715    /// with [`set_humidity_callback_configuration`].
716    pub async fn get_humidity(&mut self) -> Result<u16, TinkerforgeError> {
717        let payload = [0; 0];
718
719        #[allow(unused_variables)]
720        let result = self.device.get(u8::from(Co2V2BrickletFunction::GetHumidity), &payload).await?;
721        Ok(u16::from_le_byte_slice(result.body()))
722    }
723
724    /// The period is the period with which the [`get_humidity_callback_receiver`] receiver is triggered
725    /// periodically. A value of 0 turns the receiver off.
726    ///
727    /// If the `value has to change`-parameter is set to true, the receiver is only
728    /// triggered after the value has changed. If the value didn't change
729    /// within the period, the receiver is triggered immediately on change.
730    ///
731    /// If it is set to false, the receiver is continuously triggered with the period,
732    /// independent of the value.
733    ///
734    /// It is furthermore possible to constrain the receiver with thresholds.
735    ///
736    /// The `option`-parameter together with min/max sets a threshold for the [`get_humidity_callback_receiver`] receiver.
737    ///
738    /// The following options are possible:
739    ///
740    ///  Option| Description
741    ///  --- | ---
742    ///  'x'|    Threshold is turned off
743    ///  'o'|    Threshold is triggered when the value is *outside* the min and max values
744    ///  'i'|    Threshold is triggered when the value is *inside* or equal to the min and max values
745    ///  '<'|    Threshold is triggered when the value is smaller than the min value (max is ignored)
746    ///  '>'|    Threshold is triggered when the value is greater than the min value (max is ignored)
747    ///
748    /// If the option is set to 'x' (threshold turned off) the receiver is triggered with the fixed period.
749    ///
750    /// Associated constants:
751    /// * CO2_V2_BRICKLET_THRESHOLD_OPTION_OFF
752    ///	* CO2_V2_BRICKLET_THRESHOLD_OPTION_OUTSIDE
753    ///	* CO2_V2_BRICKLET_THRESHOLD_OPTION_INSIDE
754    ///	* CO2_V2_BRICKLET_THRESHOLD_OPTION_SMALLER
755    ///	* CO2_V2_BRICKLET_THRESHOLD_OPTION_GREATER
756    pub async fn set_humidity_callback_configuration(
757        &mut self,
758        period: u32,
759        value_has_to_change: bool,
760        option: char,
761        min: u16,
762        max: u16,
763    ) -> Result<(), TinkerforgeError> {
764        let mut payload = [0; 10];
765        period.write_to_slice(&mut payload[0..4]);
766        value_has_to_change.write_to_slice(&mut payload[4..5]);
767        option.write_to_slice(&mut payload[5..6]);
768        min.write_to_slice(&mut payload[6..8]);
769        max.write_to_slice(&mut payload[8..10]);
770
771        #[allow(unused_variables)]
772        let result = self.device.set(u8::from(Co2V2BrickletFunction::SetHumidityCallbackConfiguration), &payload).await?;
773        Ok(())
774    }
775
776    /// Returns the receiver configuration as set by [`set_humidity_callback_configuration`].
777    ///
778    /// Associated constants:
779    /// * CO2_V2_BRICKLET_THRESHOLD_OPTION_OFF
780    ///	* CO2_V2_BRICKLET_THRESHOLD_OPTION_OUTSIDE
781    ///	* CO2_V2_BRICKLET_THRESHOLD_OPTION_INSIDE
782    ///	* CO2_V2_BRICKLET_THRESHOLD_OPTION_SMALLER
783    ///	* CO2_V2_BRICKLET_THRESHOLD_OPTION_GREATER
784    pub async fn get_humidity_callback_configuration(&mut self) -> Result<HumidityCallbackConfiguration, TinkerforgeError> {
785        let payload = [0; 0];
786
787        #[allow(unused_variables)]
788        let result = self.device.get(u8::from(Co2V2BrickletFunction::GetHumidityCallbackConfiguration), &payload).await?;
789        Ok(HumidityCallbackConfiguration::from_le_byte_slice(result.body()))
790    }
791
792    /// Returns the error count for the communication between Brick and Bricklet.
793    ///
794    /// The errors are divided into
795    ///
796    /// * ACK checksum errors,
797    /// * message checksum errors,
798    /// * framing errors and
799    /// * overflow errors.
800    ///
801    /// The errors counts are for errors that occur on the Bricklet side. All
802    /// Bricks have a similar function that returns the errors on the Brick side.
803    pub async fn get_spitfp_error_count(&mut self) -> Result<SpitfpErrorCount, TinkerforgeError> {
804        let payload = [0; 0];
805
806        #[allow(unused_variables)]
807        let result = self.device.get(u8::from(Co2V2BrickletFunction::GetSpitfpErrorCount), &payload).await?;
808        Ok(SpitfpErrorCount::from_le_byte_slice(result.body()))
809    }
810
811    /// Sets the bootloader mode and returns the status after the requested
812    /// mode change was instigated.
813    ///
814    /// You can change from bootloader mode to firmware mode and vice versa. A change
815    /// from bootloader mode to firmware mode will only take place if the entry function,
816    /// device identifier and CRC are present and correct.
817    ///
818    /// This function is used by Brick Viewer during flashing. It should not be
819    /// necessary to call it in a normal user program.
820    ///
821    /// Associated constants:
822    /// * CO2_V2_BRICKLET_BOOTLOADER_MODE_BOOTLOADER
823    ///	* CO2_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE
824    ///	* CO2_V2_BRICKLET_BOOTLOADER_MODE_BOOTLOADER_WAIT_FOR_REBOOT
825    ///	* CO2_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_REBOOT
826    ///	* CO2_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_ERASE_AND_REBOOT
827    ///	* CO2_V2_BRICKLET_BOOTLOADER_STATUS_OK
828    ///	* CO2_V2_BRICKLET_BOOTLOADER_STATUS_INVALID_MODE
829    ///	* CO2_V2_BRICKLET_BOOTLOADER_STATUS_NO_CHANGE
830    ///	* CO2_V2_BRICKLET_BOOTLOADER_STATUS_ENTRY_FUNCTION_NOT_PRESENT
831    ///	* CO2_V2_BRICKLET_BOOTLOADER_STATUS_DEVICE_IDENTIFIER_INCORRECT
832    ///	* CO2_V2_BRICKLET_BOOTLOADER_STATUS_CRC_MISMATCH
833    pub async fn set_bootloader_mode(&mut self, mode: u8) -> Result<u8, TinkerforgeError> {
834        let mut payload = [0; 1];
835        mode.write_to_slice(&mut payload[0..1]);
836
837        #[allow(unused_variables)]
838        let result = self.device.get(u8::from(Co2V2BrickletFunction::SetBootloaderMode), &payload).await?;
839        Ok(u8::from_le_byte_slice(result.body()))
840    }
841
842    /// Returns the current bootloader mode, see [`set_bootloader_mode`].
843    ///
844    /// Associated constants:
845    /// * CO2_V2_BRICKLET_BOOTLOADER_MODE_BOOTLOADER
846    ///	* CO2_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE
847    ///	* CO2_V2_BRICKLET_BOOTLOADER_MODE_BOOTLOADER_WAIT_FOR_REBOOT
848    ///	* CO2_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_REBOOT
849    ///	* CO2_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_ERASE_AND_REBOOT
850    pub async fn get_bootloader_mode(&mut self) -> Result<u8, TinkerforgeError> {
851        let payload = [0; 0];
852
853        #[allow(unused_variables)]
854        let result = self.device.get(u8::from(Co2V2BrickletFunction::GetBootloaderMode), &payload).await?;
855        Ok(u8::from_le_byte_slice(result.body()))
856    }
857
858    /// Sets the firmware pointer for [`write_firmware`]. The pointer has
859    /// to be increased by chunks of size 64. The data is written to flash
860    /// every 4 chunks (which equals to one page of size 256).
861    ///
862    /// This function is used by Brick Viewer during flashing. It should not be
863    /// necessary to call it in a normal user program.
864    pub async fn set_write_firmware_pointer(&mut self, pointer: u32) -> Result<(), TinkerforgeError> {
865        let mut payload = [0; 4];
866        pointer.write_to_slice(&mut payload[0..4]);
867
868        #[allow(unused_variables)]
869        let result = self.device.set(u8::from(Co2V2BrickletFunction::SetWriteFirmwarePointer), &payload).await?;
870        Ok(())
871    }
872
873    /// Writes 64 Bytes of firmware at the position as written by
874    /// [`set_write_firmware_pointer`] before. The firmware is written
875    /// to flash every 4 chunks.
876    ///
877    /// You can only write firmware in bootloader mode.
878    ///
879    /// This function is used by Brick Viewer during flashing. It should not be
880    /// necessary to call it in a normal user program.
881    pub async fn write_firmware(&mut self, data: &[u8; 64]) -> Result<u8, TinkerforgeError> {
882        let mut payload = [0; 64];
883        data.write_to_slice(&mut payload[0..64]);
884
885        #[allow(unused_variables)]
886        let result = self.device.get(u8::from(Co2V2BrickletFunction::WriteFirmware), &payload).await?;
887        Ok(u8::from_le_byte_slice(result.body()))
888    }
889
890    /// Sets the status LED configuration. By default the LED shows
891    /// communication traffic between Brick and Bricklet, it flickers once
892    /// for every 10 received data packets.
893    ///
894    /// You can also turn the LED permanently on/off or show a heartbeat.
895    ///
896    /// If the Bricklet is in bootloader mode, the LED is will show heartbeat by default.
897    ///
898    /// Associated constants:
899    /// * CO2_V2_BRICKLET_STATUS_LED_CONFIG_OFF
900    ///	* CO2_V2_BRICKLET_STATUS_LED_CONFIG_ON
901    ///	* CO2_V2_BRICKLET_STATUS_LED_CONFIG_SHOW_HEARTBEAT
902    ///	* CO2_V2_BRICKLET_STATUS_LED_CONFIG_SHOW_STATUS
903    pub async fn set_status_led_config(&mut self, config: u8) -> Result<(), TinkerforgeError> {
904        let mut payload = [0; 1];
905        config.write_to_slice(&mut payload[0..1]);
906
907        #[allow(unused_variables)]
908        let result = self.device.set(u8::from(Co2V2BrickletFunction::SetStatusLedConfig), &payload).await?;
909        Ok(())
910    }
911
912    /// Returns the configuration as set by [`set_status_led_config`]
913    ///
914    /// Associated constants:
915    /// * CO2_V2_BRICKLET_STATUS_LED_CONFIG_OFF
916    ///	* CO2_V2_BRICKLET_STATUS_LED_CONFIG_ON
917    ///	* CO2_V2_BRICKLET_STATUS_LED_CONFIG_SHOW_HEARTBEAT
918    ///	* CO2_V2_BRICKLET_STATUS_LED_CONFIG_SHOW_STATUS
919    pub async fn get_status_led_config(&mut self) -> Result<u8, TinkerforgeError> {
920        let payload = [0; 0];
921
922        #[allow(unused_variables)]
923        let result = self.device.get(u8::from(Co2V2BrickletFunction::GetStatusLedConfig), &payload).await?;
924        Ok(u8::from_le_byte_slice(result.body()))
925    }
926
927    /// Returns the temperature as measured inside the microcontroller. The
928    /// value returned is not the ambient temperature!
929    ///
930    /// The temperature is only proportional to the real temperature and it has bad
931    /// accuracy. Practically it is only useful as an indicator for
932    /// temperature changes.
933    pub async fn get_chip_temperature(&mut self) -> Result<i16, TinkerforgeError> {
934        let payload = [0; 0];
935
936        #[allow(unused_variables)]
937        let result = self.device.get(u8::from(Co2V2BrickletFunction::GetChipTemperature), &payload).await?;
938        Ok(i16::from_le_byte_slice(result.body()))
939    }
940
941    /// Calling this function will reset the Bricklet. All configurations
942    /// will be lost.
943    ///
944    /// After a reset you have to create new device objects,
945    /// calling functions on the existing ones will result in
946    /// undefined behavior!
947    pub async fn reset(&mut self) -> Result<(), TinkerforgeError> {
948        let payload = [0; 0];
949
950        #[allow(unused_variables)]
951        let result = self.device.set(u8::from(Co2V2BrickletFunction::Reset), &payload).await?;
952        Ok(())
953    }
954
955    /// Writes a new UID into flash. If you want to set a new UID
956    /// you have to decode the Base58 encoded UID string into an
957    /// integer first.
958    ///
959    /// We recommend that you use Brick Viewer to change the UID.
960    pub async fn write_uid(&mut self, uid: u32) -> Result<(), TinkerforgeError> {
961        let mut payload = [0; 4];
962        uid.write_to_slice(&mut payload[0..4]);
963
964        #[allow(unused_variables)]
965        let result = self.device.set(u8::from(Co2V2BrickletFunction::WriteUid), &payload).await?;
966        Ok(())
967    }
968
969    /// Returns the current UID as an integer. Encode as
970    /// Base58 to get the usual string version.
971    pub async fn read_uid(&mut self) -> Result<u32, TinkerforgeError> {
972        let payload = [0; 0];
973
974        #[allow(unused_variables)]
975        let result = self.device.get(u8::from(Co2V2BrickletFunction::ReadUid), &payload).await?;
976        Ok(u32::from_le_byte_slice(result.body()))
977    }
978
979    /// Returns the UID, the UID where the Bricklet is connected to,
980    /// the position, the hardware and firmware version as well as the
981    /// device identifier.
982    ///
983    /// The position can be 'a', 'b', 'c', 'd', 'e', 'f', 'g' or 'h' (Bricklet Port).
984    /// A Bricklet connected to an [Isolator Bricklet](isolator_bricklet) is always at
985    /// position 'z'.
986    ///
987    /// The device identifier numbers can be found [here](device_identifier).
988    /// |device_identifier_constant|
989    pub async fn get_identity(&mut self) -> Result<Identity, TinkerforgeError> {
990        let payload = [0; 0];
991
992        #[allow(unused_variables)]
993        let result = self.device.get(u8::from(Co2V2BrickletFunction::GetIdentity), &payload).await?;
994        Ok(Identity::from_le_byte_slice(result.body()))
995    }
996}