tinkerforge_async/bindings/
barometer_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/Barometer_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 BarometerBrickletFunction {
24    GetAirPressure,
25    GetAltitude,
26    SetAirPressureCallbackPeriod,
27    GetAirPressureCallbackPeriod,
28    SetAltitudeCallbackPeriod,
29    GetAltitudeCallbackPeriod,
30    SetAirPressureCallbackThreshold,
31    GetAirPressureCallbackThreshold,
32    SetAltitudeCallbackThreshold,
33    GetAltitudeCallbackThreshold,
34    SetDebouncePeriod,
35    GetDebouncePeriod,
36    SetReferenceAirPressure,
37    GetChipTemperature,
38    GetReferenceAirPressure,
39    SetAveraging,
40    GetAveraging,
41    SetI2cMode,
42    GetI2cMode,
43    GetIdentity,
44    CallbackAirPressure,
45    CallbackAltitude,
46    CallbackAirPressureReached,
47    CallbackAltitudeReached,
48}
49impl From<BarometerBrickletFunction> for u8 {
50    fn from(fun: BarometerBrickletFunction) -> Self {
51        match fun {
52            BarometerBrickletFunction::GetAirPressure => 1,
53            BarometerBrickletFunction::GetAltitude => 2,
54            BarometerBrickletFunction::SetAirPressureCallbackPeriod => 3,
55            BarometerBrickletFunction::GetAirPressureCallbackPeriod => 4,
56            BarometerBrickletFunction::SetAltitudeCallbackPeriod => 5,
57            BarometerBrickletFunction::GetAltitudeCallbackPeriod => 6,
58            BarometerBrickletFunction::SetAirPressureCallbackThreshold => 7,
59            BarometerBrickletFunction::GetAirPressureCallbackThreshold => 8,
60            BarometerBrickletFunction::SetAltitudeCallbackThreshold => 9,
61            BarometerBrickletFunction::GetAltitudeCallbackThreshold => 10,
62            BarometerBrickletFunction::SetDebouncePeriod => 11,
63            BarometerBrickletFunction::GetDebouncePeriod => 12,
64            BarometerBrickletFunction::SetReferenceAirPressure => 13,
65            BarometerBrickletFunction::GetChipTemperature => 14,
66            BarometerBrickletFunction::GetReferenceAirPressure => 19,
67            BarometerBrickletFunction::SetAveraging => 20,
68            BarometerBrickletFunction::GetAveraging => 21,
69            BarometerBrickletFunction::SetI2cMode => 22,
70            BarometerBrickletFunction::GetI2cMode => 23,
71            BarometerBrickletFunction::GetIdentity => 255,
72            BarometerBrickletFunction::CallbackAirPressure => 15,
73            BarometerBrickletFunction::CallbackAltitude => 16,
74            BarometerBrickletFunction::CallbackAirPressureReached => 17,
75            BarometerBrickletFunction::CallbackAltitudeReached => 18,
76        }
77    }
78}
79pub const BAROMETER_BRICKLET_THRESHOLD_OPTION_OFF: char = 'x';
80pub const BAROMETER_BRICKLET_THRESHOLD_OPTION_OUTSIDE: char = 'o';
81pub const BAROMETER_BRICKLET_THRESHOLD_OPTION_INSIDE: char = 'i';
82pub const BAROMETER_BRICKLET_THRESHOLD_OPTION_SMALLER: char = '<';
83pub const BAROMETER_BRICKLET_THRESHOLD_OPTION_GREATER: char = '>';
84pub const BAROMETER_BRICKLET_I2C_MODE_FAST: u8 = 0;
85pub const BAROMETER_BRICKLET_I2C_MODE_SLOW: u8 = 1;
86
87#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
88pub struct AirPressureCallbackThreshold {
89    pub option: char,
90    pub min: i32,
91    pub max: i32,
92}
93impl FromByteSlice for AirPressureCallbackThreshold {
94    fn bytes_expected() -> usize {
95        9
96    }
97    fn from_le_byte_slice(bytes: &[u8]) -> AirPressureCallbackThreshold {
98        AirPressureCallbackThreshold {
99            option: <char>::from_le_byte_slice(&bytes[0..1]),
100            min: <i32>::from_le_byte_slice(&bytes[1..5]),
101            max: <i32>::from_le_byte_slice(&bytes[5..9]),
102        }
103    }
104}
105
106#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
107pub struct AltitudeCallbackThreshold {
108    pub option: char,
109    pub min: i32,
110    pub max: i32,
111}
112impl FromByteSlice for AltitudeCallbackThreshold {
113    fn bytes_expected() -> usize {
114        9
115    }
116    fn from_le_byte_slice(bytes: &[u8]) -> AltitudeCallbackThreshold {
117        AltitudeCallbackThreshold {
118            option: <char>::from_le_byte_slice(&bytes[0..1]),
119            min: <i32>::from_le_byte_slice(&bytes[1..5]),
120            max: <i32>::from_le_byte_slice(&bytes[5..9]),
121        }
122    }
123}
124
125#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
126pub struct Averaging {
127    pub moving_average_pressure: u8,
128    pub average_pressure: u8,
129    pub average_temperature: u8,
130}
131impl FromByteSlice for Averaging {
132    fn bytes_expected() -> usize {
133        3
134    }
135    fn from_le_byte_slice(bytes: &[u8]) -> Averaging {
136        Averaging {
137            moving_average_pressure: <u8>::from_le_byte_slice(&bytes[0..1]),
138            average_pressure: <u8>::from_le_byte_slice(&bytes[1..2]),
139            average_temperature: <u8>::from_le_byte_slice(&bytes[2..3]),
140        }
141    }
142}
143
144#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
145pub struct Identity {
146    pub uid: String,
147    pub connected_uid: String,
148    pub position: char,
149    pub hardware_version: [u8; 3],
150    pub firmware_version: [u8; 3],
151    pub device_identifier: u16,
152}
153impl FromByteSlice for Identity {
154    fn bytes_expected() -> usize {
155        25
156    }
157    fn from_le_byte_slice(bytes: &[u8]) -> Identity {
158        Identity {
159            uid: <String>::from_le_byte_slice(&bytes[0..8]),
160            connected_uid: <String>::from_le_byte_slice(&bytes[8..16]),
161            position: <char>::from_le_byte_slice(&bytes[16..17]),
162            hardware_version: <[u8; 3]>::from_le_byte_slice(&bytes[17..20]),
163            firmware_version: <[u8; 3]>::from_le_byte_slice(&bytes[20..23]),
164            device_identifier: <u16>::from_le_byte_slice(&bytes[23..25]),
165        }
166    }
167}
168
169/// Measures air pressure and altitude changes
170#[derive(Clone)]
171pub struct BarometerBricklet {
172    device: Device,
173}
174impl BarometerBricklet {
175    pub const DEVICE_IDENTIFIER: u16 = 221;
176    pub const DEVICE_DISPLAY_NAME: &'static str = "Barometer Bricklet";
177    /// Creates an object with the unique device ID `uid`. This object can then be used after the IP Connection `ip_connection` is connected.
178    pub fn new(uid: Uid, connection: AsyncIpConnection) -> BarometerBricklet {
179        let mut result = BarometerBricklet { device: Device::new([2, 0, 10], uid, connection, Self::DEVICE_DISPLAY_NAME) };
180        result.device.response_expected[u8::from(BarometerBrickletFunction::GetAirPressure) as usize] = ResponseExpectedFlag::AlwaysTrue;
181        result.device.response_expected[u8::from(BarometerBrickletFunction::GetAltitude) as usize] = ResponseExpectedFlag::AlwaysTrue;
182        result.device.response_expected[u8::from(BarometerBrickletFunction::SetAirPressureCallbackPeriod) as usize] =
183            ResponseExpectedFlag::True;
184        result.device.response_expected[u8::from(BarometerBrickletFunction::GetAirPressureCallbackPeriod) as usize] =
185            ResponseExpectedFlag::AlwaysTrue;
186        result.device.response_expected[u8::from(BarometerBrickletFunction::SetAltitudeCallbackPeriod) as usize] =
187            ResponseExpectedFlag::True;
188        result.device.response_expected[u8::from(BarometerBrickletFunction::GetAltitudeCallbackPeriod) as usize] =
189            ResponseExpectedFlag::AlwaysTrue;
190        result.device.response_expected[u8::from(BarometerBrickletFunction::SetAirPressureCallbackThreshold) as usize] =
191            ResponseExpectedFlag::True;
192        result.device.response_expected[u8::from(BarometerBrickletFunction::GetAirPressureCallbackThreshold) as usize] =
193            ResponseExpectedFlag::AlwaysTrue;
194        result.device.response_expected[u8::from(BarometerBrickletFunction::SetAltitudeCallbackThreshold) as usize] =
195            ResponseExpectedFlag::True;
196        result.device.response_expected[u8::from(BarometerBrickletFunction::GetAltitudeCallbackThreshold) as usize] =
197            ResponseExpectedFlag::AlwaysTrue;
198        result.device.response_expected[u8::from(BarometerBrickletFunction::SetDebouncePeriod) as usize] = ResponseExpectedFlag::True;
199        result.device.response_expected[u8::from(BarometerBrickletFunction::GetDebouncePeriod) as usize] = ResponseExpectedFlag::AlwaysTrue;
200        result.device.response_expected[u8::from(BarometerBrickletFunction::SetReferenceAirPressure) as usize] =
201            ResponseExpectedFlag::False;
202        result.device.response_expected[u8::from(BarometerBrickletFunction::GetChipTemperature) as usize] =
203            ResponseExpectedFlag::AlwaysTrue;
204        result.device.response_expected[u8::from(BarometerBrickletFunction::GetReferenceAirPressure) as usize] =
205            ResponseExpectedFlag::AlwaysTrue;
206        result.device.response_expected[u8::from(BarometerBrickletFunction::SetAveraging) as usize] = ResponseExpectedFlag::False;
207        result.device.response_expected[u8::from(BarometerBrickletFunction::GetAveraging) as usize] = ResponseExpectedFlag::AlwaysTrue;
208        result.device.response_expected[u8::from(BarometerBrickletFunction::SetI2cMode) as usize] = ResponseExpectedFlag::False;
209        result.device.response_expected[u8::from(BarometerBrickletFunction::GetI2cMode) as usize] = ResponseExpectedFlag::AlwaysTrue;
210        result.device.response_expected[u8::from(BarometerBrickletFunction::GetIdentity) as usize] = ResponseExpectedFlag::AlwaysTrue;
211        result
212    }
213
214    /// Returns the response expected flag for the function specified by the function ID parameter.
215    /// It is true if the function is expected to send a response, false otherwise.
216    ///
217    /// For getter functions this is enabled by default and cannot be disabled, because those
218    /// functions will always send a response. For callback configuration functions it is enabled
219    /// by default too, but can be disabled by [`set_response_expected`](crate::barometer_bricklet::BarometerBricklet::set_response_expected).
220    /// For setter functions it is disabled by default and can be enabled.
221    ///
222    /// Enabling the response expected flag for a setter function allows to detect timeouts
223    /// and other error conditions calls of this setter as well. The device will then send a response
224    /// for this purpose. If this flag is disabled for a setter function then no response is sent
225    /// and errors are silently ignored, because they cannot be detected.
226    ///
227    /// See [`set_response_expected`](crate::barometer_bricklet::BarometerBricklet::set_response_expected) for the list of function ID constants available for this function.
228    pub fn get_response_expected(&mut self, fun: BarometerBrickletFunction) -> Result<bool, GetResponseExpectedError> {
229        self.device.get_response_expected(u8::from(fun))
230    }
231
232    /// Changes the response expected flag of the function specified by the function ID parameter.
233    /// This flag can only be changed for setter (default value: false) and callback configuration
234    /// functions (default value: true). For getter functions it is always enabled.
235    ///
236    /// Enabling the response expected flag for a setter function allows to detect timeouts and
237    /// other error conditions calls of this setter as well. The device will then send a response
238    /// for this purpose. If this flag is disabled for a setter function then no response is sent
239    /// and errors are silently ignored, because they cannot be detected.
240    pub fn set_response_expected(
241        &mut self,
242        fun: BarometerBrickletFunction,
243        response_expected: bool,
244    ) -> Result<(), SetResponseExpectedError> {
245        self.device.set_response_expected(u8::from(fun), response_expected)
246    }
247
248    /// Changes the response expected flag for all setter and callback configuration functions of this device at once.
249    pub fn set_response_expected_all(&mut self, response_expected: bool) {
250        self.device.set_response_expected_all(response_expected)
251    }
252
253    /// Returns the version of the API definition (major, minor, revision) implemented by this API bindings.
254    /// This is neither the release version of this API bindings nor does it tell you anything about the represented Brick or Bricklet.
255    pub fn get_api_version(&self) -> [u8; 3] {
256        self.device.api_version
257    }
258
259    /// This receiver is triggered periodically with the period that is set by
260    /// [`set_air_pressure_callback_period`]. The parameter is the air
261    /// pressure of the air pressure sensor.
262    ///
263    /// The [`get_air_pressure_callback_receiver`] receiver is only triggered if the air pressure has
264    /// changed since the last triggering.
265    ///
266    /// [`set_air_pressure_callback_period`]: #method.set_air_pressure_callback_period
267    /// [`get_air_pressure_callback_receiver`]: #method.get_air_pressure_callback_receiver
268    pub async fn get_air_pressure_callback_receiver(&mut self) -> impl Stream<Item = i32> {
269        self.device
270            .get_callback_receiver(u8::from(BarometerBrickletFunction::CallbackAirPressure))
271            .await
272            .map(|p| i32::from_le_byte_slice(p.body()))
273    }
274
275    /// This receiver is triggered periodically with the period that is set by
276    /// [`set_altitude_callback_period`]. The parameter is the altitude of
277    /// the air pressure sensor.
278    ///
279    /// The [`get_altitude_callback_receiver`] receiver is only triggered if the altitude has changed since
280    /// the last triggering.
281    pub async fn get_altitude_callback_receiver(&mut self) -> impl Stream<Item = i32> {
282        self.device
283            .get_callback_receiver(u8::from(BarometerBrickletFunction::CallbackAltitude))
284            .await
285            .map(|p| i32::from_le_byte_slice(p.body()))
286    }
287
288    /// This receiver is triggered when the threshold as set by
289    /// [`set_air_pressure_callback_threshold`] is reached.
290    /// The parameter is the air pressure of the air pressure sensor.
291    ///
292    /// If the threshold keeps being reached, the receiver is triggered periodically
293    /// with the period as set by [`set_debounce_period`].
294    pub async fn get_air_pressure_reached_callback_receiver(&mut self) -> impl Stream<Item = i32> {
295        self.device
296            .get_callback_receiver(u8::from(BarometerBrickletFunction::CallbackAirPressureReached))
297            .await
298            .map(|p| i32::from_le_byte_slice(p.body()))
299    }
300
301    /// This receiver is triggered when the threshold as set by
302    /// [`set_altitude_callback_threshold`] is reached.
303    /// The parameter is the altitude of the air pressure sensor.
304    ///
305    /// If the threshold keeps being reached, the receiver is triggered periodically
306    /// with the period as set by [`set_debounce_period`].
307    pub async fn get_altitude_reached_callback_receiver(&mut self) -> impl Stream<Item = i32> {
308        self.device
309            .get_callback_receiver(u8::from(BarometerBrickletFunction::CallbackAltitudeReached))
310            .await
311            .map(|p| i32::from_le_byte_slice(p.body()))
312    }
313
314    /// Returns the air pressure of the air pressure sensor.
315    ///
316    /// If you want to get the air pressure periodically, it is recommended to use the
317    /// [`get_air_pressure_callback_receiver`] receiver and set the period with
318    /// [`set_air_pressure_callback_period`].
319    pub async fn get_air_pressure(&mut self) -> Result<i32, TinkerforgeError> {
320        let payload = [0; 0];
321
322        #[allow(unused_variables)]
323        let result = self.device.get(u8::from(BarometerBrickletFunction::GetAirPressure), &payload).await?;
324        Ok(i32::from_le_byte_slice(result.body()))
325    }
326
327    /// Returns the relative altitude of the air pressure sensor. The value is
328    /// calculated based on the difference between the current air pressure
329    /// and the reference air pressure that can be set with [`set_reference_air_pressure`].
330    ///
331    /// If you want to get the altitude periodically, it is recommended to use the
332    /// [`get_altitude_callback_receiver`] receiver and set the period with
333    /// [`set_altitude_callback_period`].
334    pub async fn get_altitude(&mut self) -> Result<i32, TinkerforgeError> {
335        let payload = [0; 0];
336
337        #[allow(unused_variables)]
338        let result = self.device.get(u8::from(BarometerBrickletFunction::GetAltitude), &payload).await?;
339        Ok(i32::from_le_byte_slice(result.body()))
340    }
341
342    /// Sets the period with which the [`get_air_pressure_callback_receiver`] receiver is triggered
343    /// periodically. A value of 0 turns the receiver off.
344    ///
345    /// The [`get_air_pressure_callback_receiver`] receiver is only triggered if the air pressure has
346    /// changed since the last triggering.
347    pub async fn set_air_pressure_callback_period(&mut self, period: u32) -> Result<(), TinkerforgeError> {
348        let mut payload = [0; 4];
349        period.write_to_slice(&mut payload[0..4]);
350
351        #[allow(unused_variables)]
352        let result = self.device.set(u8::from(BarometerBrickletFunction::SetAirPressureCallbackPeriod), &payload).await?;
353        Ok(())
354    }
355
356    /// Returns the period as set by [`set_air_pressure_callback_period`].
357    pub async fn get_air_pressure_callback_period(&mut self) -> Result<u32, TinkerforgeError> {
358        let payload = [0; 0];
359
360        #[allow(unused_variables)]
361        let result = self.device.get(u8::from(BarometerBrickletFunction::GetAirPressureCallbackPeriod), &payload).await?;
362        Ok(u32::from_le_byte_slice(result.body()))
363    }
364
365    /// Sets the period with which the [`get_altitude_callback_receiver`] receiver is triggered
366    /// periodically. A value of 0 turns the receiver off.
367    ///
368    /// The [`get_altitude_callback_receiver`] receiver is only triggered if the altitude has changed since
369    /// the last triggering.
370    pub async fn set_altitude_callback_period(&mut self, period: u32) -> Result<(), TinkerforgeError> {
371        let mut payload = [0; 4];
372        period.write_to_slice(&mut payload[0..4]);
373
374        #[allow(unused_variables)]
375        let result = self.device.set(u8::from(BarometerBrickletFunction::SetAltitudeCallbackPeriod), &payload).await?;
376        Ok(())
377    }
378
379    /// Returns the period as set by [`set_altitude_callback_period`].
380    pub async fn get_altitude_callback_period(&mut self) -> Result<u32, TinkerforgeError> {
381        let payload = [0; 0];
382
383        #[allow(unused_variables)]
384        let result = self.device.get(u8::from(BarometerBrickletFunction::GetAltitudeCallbackPeriod), &payload).await?;
385        Ok(u32::from_le_byte_slice(result.body()))
386    }
387
388    /// Sets the thresholds for the [`get_air_pressure_reached_callback_receiver`] receiver.
389    ///
390    /// The following options are possible:
391    ///
392    ///  Option| Description
393    ///  --- | ---
394    ///  'x'|    Receiver is turned off
395    ///  'o'|    Receiver is triggered when the air pressure is *outside* the min and max values
396    ///  'i'|    Receiver is triggered when the air pressure is *inside* the min and max values
397    ///  '<'|    Receiver is triggered when the air pressure is smaller than the min value (max is ignored)
398    ///  '>'|    Receiver is triggered when the air pressure is greater than the min value (max is ignored)
399    ///
400    /// Associated constants:
401    /// * BAROMETER_BRICKLET_THRESHOLD_OPTION_OFF
402    ///	* BAROMETER_BRICKLET_THRESHOLD_OPTION_OUTSIDE
403    ///	* BAROMETER_BRICKLET_THRESHOLD_OPTION_INSIDE
404    ///	* BAROMETER_BRICKLET_THRESHOLD_OPTION_SMALLER
405    ///	* BAROMETER_BRICKLET_THRESHOLD_OPTION_GREATER
406    pub async fn set_air_pressure_callback_threshold(&mut self, option: char, min: i32, max: i32) -> Result<(), TinkerforgeError> {
407        let mut payload = [0; 9];
408        option.write_to_slice(&mut payload[0..1]);
409        min.write_to_slice(&mut payload[1..5]);
410        max.write_to_slice(&mut payload[5..9]);
411
412        #[allow(unused_variables)]
413        let result = self.device.set(u8::from(BarometerBrickletFunction::SetAirPressureCallbackThreshold), &payload).await?;
414        Ok(())
415    }
416
417    /// Returns the threshold as set by [`set_air_pressure_callback_threshold`].
418    ///
419    /// Associated constants:
420    /// * BAROMETER_BRICKLET_THRESHOLD_OPTION_OFF
421    ///	* BAROMETER_BRICKLET_THRESHOLD_OPTION_OUTSIDE
422    ///	* BAROMETER_BRICKLET_THRESHOLD_OPTION_INSIDE
423    ///	* BAROMETER_BRICKLET_THRESHOLD_OPTION_SMALLER
424    ///	* BAROMETER_BRICKLET_THRESHOLD_OPTION_GREATER
425    pub async fn get_air_pressure_callback_threshold(&mut self) -> Result<AirPressureCallbackThreshold, TinkerforgeError> {
426        let payload = [0; 0];
427
428        #[allow(unused_variables)]
429        let result = self.device.get(u8::from(BarometerBrickletFunction::GetAirPressureCallbackThreshold), &payload).await?;
430        Ok(AirPressureCallbackThreshold::from_le_byte_slice(result.body()))
431    }
432
433    /// Sets the thresholds for the [`get_altitude_reached_callback_receiver`] receiver.
434    ///
435    /// The following options are possible:
436    ///
437    ///  Option| Description
438    ///  --- | ---
439    ///  'x'|    Receiver is turned off
440    ///  'o'|    Receiver is triggered when the altitude is *outside* the min and max values
441    ///  'i'|    Receiver is triggered when the altitude is *inside* the min and max values
442    ///  '<'|    Receiver is triggered when the altitude is smaller than the min value (max is ignored)
443    ///  '>'|    Receiver is triggered when the altitude is greater than the min value (max is ignored)
444    ///
445    /// Associated constants:
446    /// * BAROMETER_BRICKLET_THRESHOLD_OPTION_OFF
447    ///	* BAROMETER_BRICKLET_THRESHOLD_OPTION_OUTSIDE
448    ///	* BAROMETER_BRICKLET_THRESHOLD_OPTION_INSIDE
449    ///	* BAROMETER_BRICKLET_THRESHOLD_OPTION_SMALLER
450    ///	* BAROMETER_BRICKLET_THRESHOLD_OPTION_GREATER
451    pub async fn set_altitude_callback_threshold(&mut self, option: char, min: i32, max: i32) -> Result<(), TinkerforgeError> {
452        let mut payload = [0; 9];
453        option.write_to_slice(&mut payload[0..1]);
454        min.write_to_slice(&mut payload[1..5]);
455        max.write_to_slice(&mut payload[5..9]);
456
457        #[allow(unused_variables)]
458        let result = self.device.set(u8::from(BarometerBrickletFunction::SetAltitudeCallbackThreshold), &payload).await?;
459        Ok(())
460    }
461
462    /// Returns the threshold as set by [`set_altitude_callback_threshold`].
463    ///
464    /// Associated constants:
465    /// * BAROMETER_BRICKLET_THRESHOLD_OPTION_OFF
466    ///	* BAROMETER_BRICKLET_THRESHOLD_OPTION_OUTSIDE
467    ///	* BAROMETER_BRICKLET_THRESHOLD_OPTION_INSIDE
468    ///	* BAROMETER_BRICKLET_THRESHOLD_OPTION_SMALLER
469    ///	* BAROMETER_BRICKLET_THRESHOLD_OPTION_GREATER
470    pub async fn get_altitude_callback_threshold(&mut self) -> Result<AltitudeCallbackThreshold, TinkerforgeError> {
471        let payload = [0; 0];
472
473        #[allow(unused_variables)]
474        let result = self.device.get(u8::from(BarometerBrickletFunction::GetAltitudeCallbackThreshold), &payload).await?;
475        Ok(AltitudeCallbackThreshold::from_le_byte_slice(result.body()))
476    }
477
478    /// Sets the period with which the threshold receivers
479    ///
480    /// * [`get_air_pressure_reached_callback_receiver`],
481    /// * [`get_altitude_reached_callback_receiver`]
482    ///
483    /// are triggered, if the thresholds
484    ///
485    /// * [`set_air_pressure_callback_threshold`],
486    /// * [`set_altitude_callback_threshold`]
487    ///
488    /// keep being reached.
489    pub async fn set_debounce_period(&mut self, debounce: u32) -> Result<(), TinkerforgeError> {
490        let mut payload = [0; 4];
491        debounce.write_to_slice(&mut payload[0..4]);
492
493        #[allow(unused_variables)]
494        let result = self.device.set(u8::from(BarometerBrickletFunction::SetDebouncePeriod), &payload).await?;
495        Ok(())
496    }
497
498    /// Returns the debounce period as set by [`set_debounce_period`].
499    pub async fn get_debounce_period(&mut self) -> Result<u32, TinkerforgeError> {
500        let payload = [0; 0];
501
502        #[allow(unused_variables)]
503        let result = self.device.get(u8::from(BarometerBrickletFunction::GetDebouncePeriod), &payload).await?;
504        Ok(u32::from_le_byte_slice(result.body()))
505    }
506
507    /// Sets the reference air pressure for the altitude calculation.
508    /// Setting the reference to the current air pressure results in a calculated
509    /// altitude of 0cm. Passing 0 is a shortcut for passing the current air pressure as
510    /// reference.
511    ///
512    /// Well known reference values are the Q codes
513    /// [QNH](https://en.wikipedia.org/wiki/QNH)__ and
514    /// [QFE](https://en.wikipedia.org/wiki/Mean_sea_level_pressure#Mean_sea_level_pressure)__
515    /// used in aviation.
516    pub async fn set_reference_air_pressure(&mut self, air_pressure: i32) -> Result<(), TinkerforgeError> {
517        let mut payload = [0; 4];
518        air_pressure.write_to_slice(&mut payload[0..4]);
519
520        #[allow(unused_variables)]
521        let result = self.device.set(u8::from(BarometerBrickletFunction::SetReferenceAirPressure), &payload).await?;
522        Ok(())
523    }
524
525    /// Returns the temperature of the air pressure sensor.
526    ///
527    /// This temperature is used internally for temperature compensation of the air
528    /// pressure measurement. It is not as accurate as the temperature measured by the
529    /// `temperature_bricklet` or the `temperature_ir_bricklet`.
530    pub async fn get_chip_temperature(&mut self) -> Result<i16, TinkerforgeError> {
531        let payload = [0; 0];
532
533        #[allow(unused_variables)]
534        let result = self.device.get(u8::from(BarometerBrickletFunction::GetChipTemperature), &payload).await?;
535        Ok(i16::from_le_byte_slice(result.body()))
536    }
537
538    /// Returns the reference air pressure as set by [`set_reference_air_pressure`].
539    pub async fn get_reference_air_pressure(&mut self) -> Result<i32, TinkerforgeError> {
540        let payload = [0; 0];
541
542        #[allow(unused_variables)]
543        let result = self.device.get(u8::from(BarometerBrickletFunction::GetReferenceAirPressure), &payload).await?;
544        Ok(i32::from_le_byte_slice(result.body()))
545    }
546
547    /// Sets the different averaging parameters. It is possible to set
548    /// the length of a normal averaging for the temperature and pressure,
549    /// as well as an additional length of a
550    /// [moving average](https://en.wikipedia.org/wiki/Moving_average)__
551    /// for the pressure. The moving average is calculated from the normal
552    /// averages.  There is no moving average for the temperature.
553    ///
554    /// Setting the all three parameters to 0 will turn the averaging
555    /// completely off. If the averaging is off, there is lots of noise
556    /// on the data, but the data is without delay. Thus we recommend
557    /// to turn the averaging off if the Barometer Bricklet data is
558    /// to be used for sensor fusion with other sensors.
559    ///
560    ///
561    /// .. versionadded:: 2.0.1$nbsp;(Plugin)
562    pub async fn set_averaging(
563        &mut self,
564        moving_average_pressure: u8,
565        average_pressure: u8,
566        average_temperature: u8,
567    ) -> Result<(), TinkerforgeError> {
568        let mut payload = [0; 3];
569        moving_average_pressure.write_to_slice(&mut payload[0..1]);
570        average_pressure.write_to_slice(&mut payload[1..2]);
571        average_temperature.write_to_slice(&mut payload[2..3]);
572
573        #[allow(unused_variables)]
574        let result = self.device.set(u8::from(BarometerBrickletFunction::SetAveraging), &payload).await?;
575        Ok(())
576    }
577
578    /// Returns the averaging configuration as set by [`set_averaging`].
579    ///
580    ///
581    /// .. versionadded:: 2.0.1$nbsp;(Plugin)
582    pub async fn get_averaging(&mut self) -> Result<Averaging, TinkerforgeError> {
583        let payload = [0; 0];
584
585        #[allow(unused_variables)]
586        let result = self.device.get(u8::from(BarometerBrickletFunction::GetAveraging), &payload).await?;
587        Ok(Averaging::from_le_byte_slice(result.body()))
588    }
589
590    /// Sets the I2C mode. Possible modes are:
591    ///
592    /// * 0: Fast (400kHz)
593    /// * 1: Slow (100kHz)
594    ///
595    /// If you have problems with obvious outliers in the
596    /// Barometer Bricklet measurements, they may be caused by EMI issues.
597    /// In this case it may be helpful to lower the I2C speed.
598    ///
599    /// It is however not recommended to lower the I2C speed in applications where
600    /// a high throughput needs to be achieved.
601    ///
602    ///
603    /// .. versionadded:: 2.0.3$nbsp;(Plugin)
604    ///
605    /// Associated constants:
606    /// * BAROMETER_BRICKLET_I2C_MODE_FAST
607    ///	* BAROMETER_BRICKLET_I2C_MODE_SLOW
608    pub async fn set_i2c_mode(&mut self, mode: u8) -> Result<(), TinkerforgeError> {
609        let mut payload = [0; 1];
610        mode.write_to_slice(&mut payload[0..1]);
611
612        #[allow(unused_variables)]
613        let result = self.device.set(u8::from(BarometerBrickletFunction::SetI2cMode), &payload).await?;
614        Ok(())
615    }
616
617    /// Returns the I2C mode as set by [`set_i2c_mode`].
618    ///
619    ///
620    /// .. versionadded:: 2.0.3$nbsp;(Plugin)
621    ///
622    /// Associated constants:
623    /// * BAROMETER_BRICKLET_I2C_MODE_FAST
624    ///	* BAROMETER_BRICKLET_I2C_MODE_SLOW
625    pub async fn get_i2c_mode(&mut self) -> Result<u8, TinkerforgeError> {
626        let payload = [0; 0];
627
628        #[allow(unused_variables)]
629        let result = self.device.get(u8::from(BarometerBrickletFunction::GetI2cMode), &payload).await?;
630        Ok(u8::from_le_byte_slice(result.body()))
631    }
632
633    /// Returns the UID, the UID where the Bricklet is connected to,
634    /// the position, the hardware and firmware version as well as the
635    /// device identifier.
636    ///
637    /// The position can be 'a', 'b', 'c', 'd', 'e', 'f', 'g' or 'h' (Bricklet Port).
638    /// A Bricklet connected to an [Isolator Bricklet](isolator_bricklet) is always at
639    /// position 'z'.
640    ///
641    /// The device identifier numbers can be found [here](device_identifier).
642    /// |device_identifier_constant|
643    pub async fn get_identity(&mut self) -> Result<Identity, TinkerforgeError> {
644        let payload = [0; 0];
645
646        #[allow(unused_variables)]
647        let result = self.device.get(u8::from(BarometerBrickletFunction::GetIdentity), &payload).await?;
648        Ok(Identity::from_le_byte_slice(result.body()))
649    }
650}