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