tinkerforge_async/bindings/
distance_ir_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 distance up to 150cm with infrared light.
12//!
13//! See also the documentation [here](https://www.tinkerforge.com/en/doc/Software/Bricklets/DistanceIR_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 DistanceIrBrickletFunction {
24    GetDistance,
25    GetAnalogValue,
26    SetSamplingPoint,
27    GetSamplingPoint,
28    SetDistanceCallbackPeriod,
29    GetDistanceCallbackPeriod,
30    SetAnalogValueCallbackPeriod,
31    GetAnalogValueCallbackPeriod,
32    SetDistanceCallbackThreshold,
33    GetDistanceCallbackThreshold,
34    SetAnalogValueCallbackThreshold,
35    GetAnalogValueCallbackThreshold,
36    SetDebouncePeriod,
37    GetDebouncePeriod,
38    GetIdentity,
39    CallbackDistance,
40    CallbackAnalogValue,
41    CallbackDistanceReached,
42    CallbackAnalogValueReached,
43}
44impl From<DistanceIrBrickletFunction> for u8 {
45    fn from(fun: DistanceIrBrickletFunction) -> Self {
46        match fun {
47            DistanceIrBrickletFunction::GetDistance => 1,
48            DistanceIrBrickletFunction::GetAnalogValue => 2,
49            DistanceIrBrickletFunction::SetSamplingPoint => 3,
50            DistanceIrBrickletFunction::GetSamplingPoint => 4,
51            DistanceIrBrickletFunction::SetDistanceCallbackPeriod => 5,
52            DistanceIrBrickletFunction::GetDistanceCallbackPeriod => 6,
53            DistanceIrBrickletFunction::SetAnalogValueCallbackPeriod => 7,
54            DistanceIrBrickletFunction::GetAnalogValueCallbackPeriod => 8,
55            DistanceIrBrickletFunction::SetDistanceCallbackThreshold => 9,
56            DistanceIrBrickletFunction::GetDistanceCallbackThreshold => 10,
57            DistanceIrBrickletFunction::SetAnalogValueCallbackThreshold => 11,
58            DistanceIrBrickletFunction::GetAnalogValueCallbackThreshold => 12,
59            DistanceIrBrickletFunction::SetDebouncePeriod => 13,
60            DistanceIrBrickletFunction::GetDebouncePeriod => 14,
61            DistanceIrBrickletFunction::GetIdentity => 255,
62            DistanceIrBrickletFunction::CallbackDistance => 15,
63            DistanceIrBrickletFunction::CallbackAnalogValue => 16,
64            DistanceIrBrickletFunction::CallbackDistanceReached => 17,
65            DistanceIrBrickletFunction::CallbackAnalogValueReached => 18,
66        }
67    }
68}
69pub const DISTANCE_IR_BRICKLET_THRESHOLD_OPTION_OFF: char = 'x';
70pub const DISTANCE_IR_BRICKLET_THRESHOLD_OPTION_OUTSIDE: char = 'o';
71pub const DISTANCE_IR_BRICKLET_THRESHOLD_OPTION_INSIDE: char = 'i';
72pub const DISTANCE_IR_BRICKLET_THRESHOLD_OPTION_SMALLER: char = '<';
73pub const DISTANCE_IR_BRICKLET_THRESHOLD_OPTION_GREATER: char = '>';
74
75#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
76pub struct DistanceCallbackThreshold {
77    pub option: char,
78    pub min: u16,
79    pub max: u16,
80}
81impl FromByteSlice for DistanceCallbackThreshold {
82    fn bytes_expected() -> usize {
83        5
84    }
85    fn from_le_byte_slice(bytes: &[u8]) -> DistanceCallbackThreshold {
86        DistanceCallbackThreshold {
87            option: <char>::from_le_byte_slice(&bytes[0..1]),
88            min: <u16>::from_le_byte_slice(&bytes[1..3]),
89            max: <u16>::from_le_byte_slice(&bytes[3..5]),
90        }
91    }
92}
93
94#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
95pub struct AnalogValueCallbackThreshold {
96    pub option: char,
97    pub min: u16,
98    pub max: u16,
99}
100impl FromByteSlice for AnalogValueCallbackThreshold {
101    fn bytes_expected() -> usize {
102        5
103    }
104    fn from_le_byte_slice(bytes: &[u8]) -> AnalogValueCallbackThreshold {
105        AnalogValueCallbackThreshold {
106            option: <char>::from_le_byte_slice(&bytes[0..1]),
107            min: <u16>::from_le_byte_slice(&bytes[1..3]),
108            max: <u16>::from_le_byte_slice(&bytes[3..5]),
109        }
110    }
111}
112
113#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
114pub struct Identity {
115    pub uid: String,
116    pub connected_uid: String,
117    pub position: char,
118    pub hardware_version: [u8; 3],
119    pub firmware_version: [u8; 3],
120    pub device_identifier: u16,
121}
122impl FromByteSlice for Identity {
123    fn bytes_expected() -> usize {
124        25
125    }
126    fn from_le_byte_slice(bytes: &[u8]) -> Identity {
127        Identity {
128            uid: <String>::from_le_byte_slice(&bytes[0..8]),
129            connected_uid: <String>::from_le_byte_slice(&bytes[8..16]),
130            position: <char>::from_le_byte_slice(&bytes[16..17]),
131            hardware_version: <[u8; 3]>::from_le_byte_slice(&bytes[17..20]),
132            firmware_version: <[u8; 3]>::from_le_byte_slice(&bytes[20..23]),
133            device_identifier: <u16>::from_le_byte_slice(&bytes[23..25]),
134        }
135    }
136}
137
138/// Measures distance up to 150cm with infrared light
139#[derive(Clone)]
140pub struct DistanceIrBricklet {
141    device: Device,
142}
143impl DistanceIrBricklet {
144    pub const DEVICE_IDENTIFIER: u16 = 25;
145    pub const DEVICE_DISPLAY_NAME: &'static str = "Distance IR Bricklet";
146    /// Creates an object with the unique device ID `uid`. This object can then be used after the IP Connection `ip_connection` is connected.
147    pub fn new(uid: Uid, connection: AsyncIpConnection) -> DistanceIrBricklet {
148        let mut result = DistanceIrBricklet { device: Device::new([2, 0, 10], uid, connection, Self::DEVICE_DISPLAY_NAME) };
149        result.device.response_expected[u8::from(DistanceIrBrickletFunction::GetDistance) as usize] = ResponseExpectedFlag::AlwaysTrue;
150        result.device.response_expected[u8::from(DistanceIrBrickletFunction::GetAnalogValue) as usize] = ResponseExpectedFlag::AlwaysTrue;
151        result.device.response_expected[u8::from(DistanceIrBrickletFunction::SetSamplingPoint) as usize] = ResponseExpectedFlag::False;
152        result.device.response_expected[u8::from(DistanceIrBrickletFunction::GetSamplingPoint) as usize] = ResponseExpectedFlag::AlwaysTrue;
153        result.device.response_expected[u8::from(DistanceIrBrickletFunction::SetDistanceCallbackPeriod) as usize] =
154            ResponseExpectedFlag::True;
155        result.device.response_expected[u8::from(DistanceIrBrickletFunction::GetDistanceCallbackPeriod) as usize] =
156            ResponseExpectedFlag::AlwaysTrue;
157        result.device.response_expected[u8::from(DistanceIrBrickletFunction::SetAnalogValueCallbackPeriod) as usize] =
158            ResponseExpectedFlag::True;
159        result.device.response_expected[u8::from(DistanceIrBrickletFunction::GetAnalogValueCallbackPeriod) as usize] =
160            ResponseExpectedFlag::AlwaysTrue;
161        result.device.response_expected[u8::from(DistanceIrBrickletFunction::SetDistanceCallbackThreshold) as usize] =
162            ResponseExpectedFlag::True;
163        result.device.response_expected[u8::from(DistanceIrBrickletFunction::GetDistanceCallbackThreshold) as usize] =
164            ResponseExpectedFlag::AlwaysTrue;
165        result.device.response_expected[u8::from(DistanceIrBrickletFunction::SetAnalogValueCallbackThreshold) as usize] =
166            ResponseExpectedFlag::True;
167        result.device.response_expected[u8::from(DistanceIrBrickletFunction::GetAnalogValueCallbackThreshold) as usize] =
168            ResponseExpectedFlag::AlwaysTrue;
169        result.device.response_expected[u8::from(DistanceIrBrickletFunction::SetDebouncePeriod) as usize] = ResponseExpectedFlag::True;
170        result.device.response_expected[u8::from(DistanceIrBrickletFunction::GetDebouncePeriod) as usize] =
171            ResponseExpectedFlag::AlwaysTrue;
172        result.device.response_expected[u8::from(DistanceIrBrickletFunction::GetIdentity) as usize] = ResponseExpectedFlag::AlwaysTrue;
173        result
174    }
175
176    /// Returns the response expected flag for the function specified by the function ID parameter.
177    /// It is true if the function is expected to send a response, false otherwise.
178    ///
179    /// For getter functions this is enabled by default and cannot be disabled, because those
180    /// functions will always send a response. For callback configuration functions it is enabled
181    /// by default too, but can be disabled by [`set_response_expected`](crate::distance_ir_bricklet::DistanceIrBricklet::set_response_expected).
182    /// For setter functions it is disabled by default and can be enabled.
183    ///
184    /// Enabling the response expected flag for a setter function allows to detect timeouts
185    /// and other error conditions calls of this setter as well. The device will then send a response
186    /// for this purpose. If this flag is disabled for a setter function then no response is sent
187    /// and errors are silently ignored, because they cannot be detected.
188    ///
189    /// See [`set_response_expected`](crate::distance_ir_bricklet::DistanceIrBricklet::set_response_expected) for the list of function ID constants available for this function.
190    pub fn get_response_expected(&mut self, fun: DistanceIrBrickletFunction) -> Result<bool, GetResponseExpectedError> {
191        self.device.get_response_expected(u8::from(fun))
192    }
193
194    /// Changes the response expected flag of the function specified by the function ID parameter.
195    /// This flag can only be changed for setter (default value: false) and callback configuration
196    /// functions (default value: true). For getter functions it is always enabled.
197    ///
198    /// Enabling the response expected flag for a setter function allows to detect timeouts and
199    /// other error conditions calls of this setter as well. The device will then send a response
200    /// for this purpose. If this flag is disabled for a setter function then no response is sent
201    /// and errors are silently ignored, because they cannot be detected.
202    pub fn set_response_expected(
203        &mut self,
204        fun: DistanceIrBrickletFunction,
205        response_expected: bool,
206    ) -> Result<(), SetResponseExpectedError> {
207        self.device.set_response_expected(u8::from(fun), response_expected)
208    }
209
210    /// Changes the response expected flag for all setter and callback configuration functions of this device at once.
211    pub fn set_response_expected_all(&mut self, response_expected: bool) {
212        self.device.set_response_expected_all(response_expected)
213    }
214
215    /// Returns the version of the API definition (major, minor, revision) implemented by this API bindings.
216    /// This is neither the release version of this API bindings nor does it tell you anything about the represented Brick or Bricklet.
217    pub fn get_api_version(&self) -> [u8; 3] {
218        self.device.api_version
219    }
220
221    /// This receiver is triggered periodically with the period that is set by
222    /// [`set_distance_callback_period`]. The parameter is the distance of the
223    /// sensor.
224    ///
225    /// The [`get_distance_callback_receiver`] receiver is only triggered if the distance has changed since the
226    /// last triggering.
227    ///
228    /// [`set_distance_callback_period`]: #method.set_distance_callback_period
229    /// [`get_distance_callback_receiver`]: #method.get_distance_callback_receiver
230    pub async fn get_distance_callback_receiver(&mut self) -> impl Stream<Item = u16> {
231        self.device
232            .get_callback_receiver(u8::from(DistanceIrBrickletFunction::CallbackDistance))
233            .await
234            .map(|p| u16::from_le_byte_slice(p.body()))
235    }
236
237    /// This receiver is triggered periodically with the period that is set by
238    /// [`set_analog_value_callback_period`]. The parameter is the analog value of the
239    /// sensor.
240    ///
241    /// The [`get_analog_value_callback_receiver`] receiver is only triggered if the analog value has changed
242    /// since the last triggering.
243    pub async fn get_analog_value_callback_receiver(&mut self) -> impl Stream<Item = u16> {
244        self.device
245            .get_callback_receiver(u8::from(DistanceIrBrickletFunction::CallbackAnalogValue))
246            .await
247            .map(|p| u16::from_le_byte_slice(p.body()))
248    }
249
250    /// This receiver is triggered when the threshold as set by
251    /// [`set_distance_callback_threshold`] is reached.
252    /// The parameter is the distance of the sensor.
253    ///
254    /// If the threshold keeps being reached, the receiver is triggered periodically
255    /// with the period as set by [`set_debounce_period`].
256    pub async fn get_distance_reached_callback_receiver(&mut self) -> impl Stream<Item = u16> {
257        self.device
258            .get_callback_receiver(u8::from(DistanceIrBrickletFunction::CallbackDistanceReached))
259            .await
260            .map(|p| u16::from_le_byte_slice(p.body()))
261    }
262
263    /// This receiver is triggered when the threshold as set by
264    /// [`set_analog_value_callback_threshold`] is reached.
265    /// The parameter is the analog value of the sensor.
266    ///
267    /// If the threshold keeps being reached, the receiver is triggered periodically
268    /// with the period as set by [`set_debounce_period`].
269    pub async fn get_analog_value_reached_callback_receiver(&mut self) -> impl Stream<Item = u16> {
270        self.device
271            .get_callback_receiver(u8::from(DistanceIrBrickletFunction::CallbackAnalogValueReached))
272            .await
273            .map(|p| u16::from_le_byte_slice(p.body()))
274    }
275
276    /// Returns the distance measured by the sensor. Possible
277    /// distance ranges are 40 to 300, 100 to 800 and 200 to 1500, depending on the
278    /// selected IR sensor.
279    ///
280    /// If you want to get the distance periodically, it is recommended to use the
281    /// [`get_distance_callback_receiver`] receiver and set the period with
282    /// [`set_distance_callback_period`].
283    pub async fn get_distance(&mut self) -> Result<u16, TinkerforgeError> {
284        let payload = [0; 0];
285
286        #[allow(unused_variables)]
287        let result = self.device.get(u8::from(DistanceIrBrickletFunction::GetDistance), &payload).await?;
288        Ok(u16::from_le_byte_slice(result.body()))
289    }
290
291    /// Returns the value as read by a 12-bit analog-to-digital converter.
292    ///
293    /// # Note
294    ///  The value returned by [`get_distance`] is averaged over several samples
295    ///  to yield less noise, while [`get_analog_value`] gives back raw
296    ///  unfiltered analog values. The only reason to use [`get_analog_value`] is,
297    ///  if you need the full resolution of the analog-to-digital converter.
298    ///
299    /// If you want the analog value periodically, it is recommended to use the
300    /// [`get_analog_value_callback_receiver`] receiver and set the period with
301    /// [`set_analog_value_callback_period`].
302    pub async fn get_analog_value(&mut self) -> Result<u16, TinkerforgeError> {
303        let payload = [0; 0];
304
305        #[allow(unused_variables)]
306        let result = self.device.get(u8::from(DistanceIrBrickletFunction::GetAnalogValue), &payload).await?;
307        Ok(u16::from_le_byte_slice(result.body()))
308    }
309
310    /// Sets a sampling point value to a specific position of the lookup table.
311    /// The lookup table comprises 128 equidistant analog values with
312    /// corresponding distances.
313    ///
314    /// If you measure a distance of 50cm at the analog value 2048, you
315    /// should call this function with (64, 5000). The utilized analog-to-digital
316    /// converter has a resolution of 12 bit. With 128 sampling points on the
317    /// whole range, this means that every sampling point has a size of 32
318    /// analog values. Thus the analog value 2048 has the corresponding sampling
319    /// point 64 = 2048/32.
320    ///
321    /// Sampling points are saved on the EEPROM of the Distance IR Bricklet and
322    /// loaded again on startup.
323    ///
324    /// # Note
325    ///  An easy way to calibrate the sampling points of the Distance IR Bricklet is
326    ///  implemented in the Brick Viewer. If you want to calibrate your Bricklet it is
327    ///  highly recommended to use this implementation.
328    pub async fn set_sampling_point(&mut self, position: u8, distance: u16) -> Result<(), TinkerforgeError> {
329        let mut payload = [0; 3];
330        position.write_to_slice(&mut payload[0..1]);
331        distance.write_to_slice(&mut payload[1..3]);
332
333        #[allow(unused_variables)]
334        let result = self.device.set(u8::from(DistanceIrBrickletFunction::SetSamplingPoint), &payload).await?;
335        Ok(())
336    }
337
338    /// Returns the distance to a sampling point position as set by
339    /// [`set_sampling_point`].
340    pub async fn get_sampling_point(&mut self, position: u8) -> Result<u16, TinkerforgeError> {
341        let mut payload = [0; 1];
342        position.write_to_slice(&mut payload[0..1]);
343
344        #[allow(unused_variables)]
345        let result = self.device.get(u8::from(DistanceIrBrickletFunction::GetSamplingPoint), &payload).await?;
346        Ok(u16::from_le_byte_slice(result.body()))
347    }
348
349    /// Sets the period with which the [`get_distance_callback_receiver`] receiver is triggered
350    /// periodically. A value of 0 turns the receiver off.
351    ///
352    /// The [`get_distance_callback_receiver`] receiver is only triggered if the distance has changed since the
353    /// last triggering.
354    pub async fn set_distance_callback_period(&mut self, period: u32) -> Result<(), TinkerforgeError> {
355        let mut payload = [0; 4];
356        period.write_to_slice(&mut payload[0..4]);
357
358        #[allow(unused_variables)]
359        let result = self.device.set(u8::from(DistanceIrBrickletFunction::SetDistanceCallbackPeriod), &payload).await?;
360        Ok(())
361    }
362
363    /// Returns the period as set by [`set_distance_callback_period`].
364    pub async fn get_distance_callback_period(&mut self) -> Result<u32, TinkerforgeError> {
365        let payload = [0; 0];
366
367        #[allow(unused_variables)]
368        let result = self.device.get(u8::from(DistanceIrBrickletFunction::GetDistanceCallbackPeriod), &payload).await?;
369        Ok(u32::from_le_byte_slice(result.body()))
370    }
371
372    /// Sets the period with which the [`get_analog_value_callback_receiver`] receiver is triggered
373    /// periodically. A value of 0 turns the receiver off.
374    ///
375    /// The [`get_analog_value_callback_receiver`] receiver is only triggered if the analog value has
376    /// changed since the last triggering.
377    pub async fn set_analog_value_callback_period(&mut self, period: u32) -> Result<(), TinkerforgeError> {
378        let mut payload = [0; 4];
379        period.write_to_slice(&mut payload[0..4]);
380
381        #[allow(unused_variables)]
382        let result = self.device.set(u8::from(DistanceIrBrickletFunction::SetAnalogValueCallbackPeriod), &payload).await?;
383        Ok(())
384    }
385
386    /// Returns the period as set by [`set_analog_value_callback_period`].
387    pub async fn get_analog_value_callback_period(&mut self) -> Result<u32, TinkerforgeError> {
388        let payload = [0; 0];
389
390        #[allow(unused_variables)]
391        let result = self.device.get(u8::from(DistanceIrBrickletFunction::GetAnalogValueCallbackPeriod), &payload).await?;
392        Ok(u32::from_le_byte_slice(result.body()))
393    }
394
395    /// Sets the thresholds for the [`get_distance_reached_callback_receiver`] receiver.
396    ///
397    /// The following options are possible:
398    ///
399    ///  Option| Description
400    ///  --- | ---
401    ///  'x'|    Receiver is turned off
402    ///  'o'|    Receiver is triggered when the distance is *outside* the min and max values
403    ///  'i'|    Receiver is triggered when the distance is *inside* the min and max values
404    ///  '<'|    Receiver is triggered when the distance is smaller than the min value (max is ignored)
405    ///  '>'|    Receiver is triggered when the distance is greater than the min value (max is ignored)
406    ///
407    /// Associated constants:
408    /// * DISTANCE_IR_BRICKLET_THRESHOLD_OPTION_OFF
409    ///	* DISTANCE_IR_BRICKLET_THRESHOLD_OPTION_OUTSIDE
410    ///	* DISTANCE_IR_BRICKLET_THRESHOLD_OPTION_INSIDE
411    ///	* DISTANCE_IR_BRICKLET_THRESHOLD_OPTION_SMALLER
412    ///	* DISTANCE_IR_BRICKLET_THRESHOLD_OPTION_GREATER
413    pub async fn set_distance_callback_threshold(&mut self, option: char, min: u16, max: u16) -> Result<(), TinkerforgeError> {
414        let mut payload = [0; 5];
415        option.write_to_slice(&mut payload[0..1]);
416        min.write_to_slice(&mut payload[1..3]);
417        max.write_to_slice(&mut payload[3..5]);
418
419        #[allow(unused_variables)]
420        let result = self.device.set(u8::from(DistanceIrBrickletFunction::SetDistanceCallbackThreshold), &payload).await?;
421        Ok(())
422    }
423
424    /// Returns the threshold as set by [`set_distance_callback_threshold`].
425    ///
426    /// Associated constants:
427    /// * DISTANCE_IR_BRICKLET_THRESHOLD_OPTION_OFF
428    ///	* DISTANCE_IR_BRICKLET_THRESHOLD_OPTION_OUTSIDE
429    ///	* DISTANCE_IR_BRICKLET_THRESHOLD_OPTION_INSIDE
430    ///	* DISTANCE_IR_BRICKLET_THRESHOLD_OPTION_SMALLER
431    ///	* DISTANCE_IR_BRICKLET_THRESHOLD_OPTION_GREATER
432    pub async fn get_distance_callback_threshold(&mut self) -> Result<DistanceCallbackThreshold, TinkerforgeError> {
433        let payload = [0; 0];
434
435        #[allow(unused_variables)]
436        let result = self.device.get(u8::from(DistanceIrBrickletFunction::GetDistanceCallbackThreshold), &payload).await?;
437        Ok(DistanceCallbackThreshold::from_le_byte_slice(result.body()))
438    }
439
440    /// Sets the thresholds for the [`get_analog_value_reached_callback_receiver`] receiver.
441    ///
442    /// The following options are possible:
443    ///
444    ///  Option| Description
445    ///  --- | ---
446    ///  'x'|    Receiver is turned off
447    ///  'o'|    Receiver is triggered when the analog value is *outside* the min and max values
448    ///  'i'|    Receiver is triggered when the analog value is *inside* the min and max values
449    ///  '<'|    Receiver is triggered when the analog value is smaller than the min value (max is ignored)
450    ///  '>'|    Receiver is triggered when the analog value is greater than the min value (max is ignored)
451    ///
452    /// Associated constants:
453    /// * DISTANCE_IR_BRICKLET_THRESHOLD_OPTION_OFF
454    ///	* DISTANCE_IR_BRICKLET_THRESHOLD_OPTION_OUTSIDE
455    ///	* DISTANCE_IR_BRICKLET_THRESHOLD_OPTION_INSIDE
456    ///	* DISTANCE_IR_BRICKLET_THRESHOLD_OPTION_SMALLER
457    ///	* DISTANCE_IR_BRICKLET_THRESHOLD_OPTION_GREATER
458    pub async fn set_analog_value_callback_threshold(&mut self, option: char, min: u16, max: u16) -> Result<(), TinkerforgeError> {
459        let mut payload = [0; 5];
460        option.write_to_slice(&mut payload[0..1]);
461        min.write_to_slice(&mut payload[1..3]);
462        max.write_to_slice(&mut payload[3..5]);
463
464        #[allow(unused_variables)]
465        let result = self.device.set(u8::from(DistanceIrBrickletFunction::SetAnalogValueCallbackThreshold), &payload).await?;
466        Ok(())
467    }
468
469    /// Returns the threshold as set by [`set_analog_value_callback_threshold`].
470    ///
471    /// Associated constants:
472    /// * DISTANCE_IR_BRICKLET_THRESHOLD_OPTION_OFF
473    ///	* DISTANCE_IR_BRICKLET_THRESHOLD_OPTION_OUTSIDE
474    ///	* DISTANCE_IR_BRICKLET_THRESHOLD_OPTION_INSIDE
475    ///	* DISTANCE_IR_BRICKLET_THRESHOLD_OPTION_SMALLER
476    ///	* DISTANCE_IR_BRICKLET_THRESHOLD_OPTION_GREATER
477    pub async fn get_analog_value_callback_threshold(&mut self) -> Result<AnalogValueCallbackThreshold, TinkerforgeError> {
478        let payload = [0; 0];
479
480        #[allow(unused_variables)]
481        let result = self.device.get(u8::from(DistanceIrBrickletFunction::GetAnalogValueCallbackThreshold), &payload).await?;
482        Ok(AnalogValueCallbackThreshold::from_le_byte_slice(result.body()))
483    }
484
485    /// Sets the period with which the threshold receivers
486    ///
487    /// * [`get_distance_reached_callback_receiver`],
488    /// * [`get_analog_value_reached_callback_receiver`]
489    ///
490    /// are triggered, if the thresholds
491    ///
492    /// * [`set_distance_callback_threshold`],
493    /// * [`set_analog_value_callback_threshold`]
494    ///
495    /// keep being reached.
496    pub async fn set_debounce_period(&mut self, debounce: u32) -> Result<(), TinkerforgeError> {
497        let mut payload = [0; 4];
498        debounce.write_to_slice(&mut payload[0..4]);
499
500        #[allow(unused_variables)]
501        let result = self.device.set(u8::from(DistanceIrBrickletFunction::SetDebouncePeriod), &payload).await?;
502        Ok(())
503    }
504
505    /// Returns the debounce period as set by [`set_debounce_period`].
506    pub async fn get_debounce_period(&mut self) -> Result<u32, TinkerforgeError> {
507        let payload = [0; 0];
508
509        #[allow(unused_variables)]
510        let result = self.device.get(u8::from(DistanceIrBrickletFunction::GetDebouncePeriod), &payload).await?;
511        Ok(u32::from_le_byte_slice(result.body()))
512    }
513
514    /// Returns the UID, the UID where the Bricklet is connected to,
515    /// the position, the hardware and firmware version as well as the
516    /// device identifier.
517    ///
518    /// The position can be 'a', 'b', 'c', 'd', 'e', 'f', 'g' or 'h' (Bricklet Port).
519    /// A Bricklet connected to an [Isolator Bricklet](isolator_bricklet) is always at
520    /// position 'z'.
521    ///
522    /// The device identifier numbers can be found [here](device_identifier).
523    /// |device_identifier_constant|
524    pub async fn get_identity(&mut self) -> Result<Identity, TinkerforgeError> {
525        let payload = [0; 0];
526
527        #[allow(unused_variables)]
528        let result = self.device.get(u8::from(DistanceIrBrickletFunction::GetIdentity), &payload).await?;
529        Ok(Identity::from_le_byte_slice(result.body()))
530    }
531}