tinkerforge_async/bindings/
analog_in_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 DC voltage between 0V and 45V.
12//!
13//! See also the documentation [here](https://www.tinkerforge.com/en/doc/Software/Bricklets/AnalogIn_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 AnalogInBrickletFunction {
24    GetVoltage,
25    GetAnalogValue,
26    SetVoltageCallbackPeriod,
27    GetVoltageCallbackPeriod,
28    SetAnalogValueCallbackPeriod,
29    GetAnalogValueCallbackPeriod,
30    SetVoltageCallbackThreshold,
31    GetVoltageCallbackThreshold,
32    SetAnalogValueCallbackThreshold,
33    GetAnalogValueCallbackThreshold,
34    SetDebouncePeriod,
35    GetDebouncePeriod,
36    SetRange,
37    GetRange,
38    SetAveraging,
39    GetAveraging,
40    GetIdentity,
41    CallbackVoltage,
42    CallbackAnalogValue,
43    CallbackVoltageReached,
44    CallbackAnalogValueReached,
45}
46impl From<AnalogInBrickletFunction> for u8 {
47    fn from(fun: AnalogInBrickletFunction) -> Self {
48        match fun {
49            AnalogInBrickletFunction::GetVoltage => 1,
50            AnalogInBrickletFunction::GetAnalogValue => 2,
51            AnalogInBrickletFunction::SetVoltageCallbackPeriod => 3,
52            AnalogInBrickletFunction::GetVoltageCallbackPeriod => 4,
53            AnalogInBrickletFunction::SetAnalogValueCallbackPeriod => 5,
54            AnalogInBrickletFunction::GetAnalogValueCallbackPeriod => 6,
55            AnalogInBrickletFunction::SetVoltageCallbackThreshold => 7,
56            AnalogInBrickletFunction::GetVoltageCallbackThreshold => 8,
57            AnalogInBrickletFunction::SetAnalogValueCallbackThreshold => 9,
58            AnalogInBrickletFunction::GetAnalogValueCallbackThreshold => 10,
59            AnalogInBrickletFunction::SetDebouncePeriod => 11,
60            AnalogInBrickletFunction::GetDebouncePeriod => 12,
61            AnalogInBrickletFunction::SetRange => 17,
62            AnalogInBrickletFunction::GetRange => 18,
63            AnalogInBrickletFunction::SetAveraging => 19,
64            AnalogInBrickletFunction::GetAveraging => 20,
65            AnalogInBrickletFunction::GetIdentity => 255,
66            AnalogInBrickletFunction::CallbackVoltage => 13,
67            AnalogInBrickletFunction::CallbackAnalogValue => 14,
68            AnalogInBrickletFunction::CallbackVoltageReached => 15,
69            AnalogInBrickletFunction::CallbackAnalogValueReached => 16,
70        }
71    }
72}
73pub const ANALOG_IN_BRICKLET_THRESHOLD_OPTION_OFF: char = 'x';
74pub const ANALOG_IN_BRICKLET_THRESHOLD_OPTION_OUTSIDE: char = 'o';
75pub const ANALOG_IN_BRICKLET_THRESHOLD_OPTION_INSIDE: char = 'i';
76pub const ANALOG_IN_BRICKLET_THRESHOLD_OPTION_SMALLER: char = '<';
77pub const ANALOG_IN_BRICKLET_THRESHOLD_OPTION_GREATER: char = '>';
78pub const ANALOG_IN_BRICKLET_RANGE_AUTOMATIC: u8 = 0;
79pub const ANALOG_IN_BRICKLET_RANGE_UP_TO_6V: u8 = 1;
80pub const ANALOG_IN_BRICKLET_RANGE_UP_TO_10V: u8 = 2;
81pub const ANALOG_IN_BRICKLET_RANGE_UP_TO_36V: u8 = 3;
82pub const ANALOG_IN_BRICKLET_RANGE_UP_TO_45V: u8 = 4;
83pub const ANALOG_IN_BRICKLET_RANGE_UP_TO_3V: u8 = 5;
84
85#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
86pub struct VoltageCallbackThreshold {
87    pub option: char,
88    pub min: u16,
89    pub max: u16,
90}
91impl FromByteSlice for VoltageCallbackThreshold {
92    fn bytes_expected() -> usize {
93        5
94    }
95    fn from_le_byte_slice(bytes: &[u8]) -> VoltageCallbackThreshold {
96        VoltageCallbackThreshold {
97            option: <char>::from_le_byte_slice(&bytes[0..1]),
98            min: <u16>::from_le_byte_slice(&bytes[1..3]),
99            max: <u16>::from_le_byte_slice(&bytes[3..5]),
100        }
101    }
102}
103
104#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
105pub struct AnalogValueCallbackThreshold {
106    pub option: char,
107    pub min: u16,
108    pub max: u16,
109}
110impl FromByteSlice for AnalogValueCallbackThreshold {
111    fn bytes_expected() -> usize {
112        5
113    }
114    fn from_le_byte_slice(bytes: &[u8]) -> AnalogValueCallbackThreshold {
115        AnalogValueCallbackThreshold {
116            option: <char>::from_le_byte_slice(&bytes[0..1]),
117            min: <u16>::from_le_byte_slice(&bytes[1..3]),
118            max: <u16>::from_le_byte_slice(&bytes[3..5]),
119        }
120    }
121}
122
123#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
124pub struct Identity {
125    pub uid: String,
126    pub connected_uid: String,
127    pub position: char,
128    pub hardware_version: [u8; 3],
129    pub firmware_version: [u8; 3],
130    pub device_identifier: u16,
131}
132impl FromByteSlice for Identity {
133    fn bytes_expected() -> usize {
134        25
135    }
136    fn from_le_byte_slice(bytes: &[u8]) -> Identity {
137        Identity {
138            uid: <String>::from_le_byte_slice(&bytes[0..8]),
139            connected_uid: <String>::from_le_byte_slice(&bytes[8..16]),
140            position: <char>::from_le_byte_slice(&bytes[16..17]),
141            hardware_version: <[u8; 3]>::from_le_byte_slice(&bytes[17..20]),
142            firmware_version: <[u8; 3]>::from_le_byte_slice(&bytes[20..23]),
143            device_identifier: <u16>::from_le_byte_slice(&bytes[23..25]),
144        }
145    }
146}
147
148/// Measures DC voltage between 0V and 45V
149#[derive(Clone)]
150pub struct AnalogInBricklet {
151    device: Device,
152}
153impl AnalogInBricklet {
154    pub const DEVICE_IDENTIFIER: u16 = 219;
155    pub const DEVICE_DISPLAY_NAME: &'static str = "Analog In Bricklet";
156    /// Creates an object with the unique device ID `uid`. This object can then be used after the IP Connection `ip_connection` is connected.
157    pub fn new(uid: Uid, connection: AsyncIpConnection) -> AnalogInBricklet {
158        let mut result = AnalogInBricklet { device: Device::new([2, 0, 10], uid, connection, Self::DEVICE_DISPLAY_NAME) };
159        result.device.response_expected[u8::from(AnalogInBrickletFunction::GetVoltage) as usize] = ResponseExpectedFlag::AlwaysTrue;
160        result.device.response_expected[u8::from(AnalogInBrickletFunction::GetAnalogValue) as usize] = ResponseExpectedFlag::AlwaysTrue;
161        result.device.response_expected[u8::from(AnalogInBrickletFunction::SetVoltageCallbackPeriod) as usize] = ResponseExpectedFlag::True;
162        result.device.response_expected[u8::from(AnalogInBrickletFunction::GetVoltageCallbackPeriod) as usize] =
163            ResponseExpectedFlag::AlwaysTrue;
164        result.device.response_expected[u8::from(AnalogInBrickletFunction::SetAnalogValueCallbackPeriod) as usize] =
165            ResponseExpectedFlag::True;
166        result.device.response_expected[u8::from(AnalogInBrickletFunction::GetAnalogValueCallbackPeriod) as usize] =
167            ResponseExpectedFlag::AlwaysTrue;
168        result.device.response_expected[u8::from(AnalogInBrickletFunction::SetVoltageCallbackThreshold) as usize] =
169            ResponseExpectedFlag::True;
170        result.device.response_expected[u8::from(AnalogInBrickletFunction::GetVoltageCallbackThreshold) as usize] =
171            ResponseExpectedFlag::AlwaysTrue;
172        result.device.response_expected[u8::from(AnalogInBrickletFunction::SetAnalogValueCallbackThreshold) as usize] =
173            ResponseExpectedFlag::True;
174        result.device.response_expected[u8::from(AnalogInBrickletFunction::GetAnalogValueCallbackThreshold) as usize] =
175            ResponseExpectedFlag::AlwaysTrue;
176        result.device.response_expected[u8::from(AnalogInBrickletFunction::SetDebouncePeriod) as usize] = ResponseExpectedFlag::True;
177        result.device.response_expected[u8::from(AnalogInBrickletFunction::GetDebouncePeriod) as usize] = ResponseExpectedFlag::AlwaysTrue;
178        result.device.response_expected[u8::from(AnalogInBrickletFunction::SetRange) as usize] = ResponseExpectedFlag::False;
179        result.device.response_expected[u8::from(AnalogInBrickletFunction::GetRange) as usize] = ResponseExpectedFlag::AlwaysTrue;
180        result.device.response_expected[u8::from(AnalogInBrickletFunction::SetAveraging) as usize] = ResponseExpectedFlag::False;
181        result.device.response_expected[u8::from(AnalogInBrickletFunction::GetAveraging) as usize] = ResponseExpectedFlag::AlwaysTrue;
182        result.device.response_expected[u8::from(AnalogInBrickletFunction::GetIdentity) as usize] = ResponseExpectedFlag::AlwaysTrue;
183        result
184    }
185
186    /// Returns the response expected flag for the function specified by the function ID parameter.
187    /// It is true if the function is expected to send a response, false otherwise.
188    ///
189    /// For getter functions this is enabled by default and cannot be disabled, because those
190    /// functions will always send a response. For callback configuration functions it is enabled
191    /// by default too, but can be disabled by [`set_response_expected`](crate::analog_in_bricklet::AnalogInBricklet::set_response_expected).
192    /// For setter functions it is disabled by default and can be enabled.
193    ///
194    /// Enabling the response expected flag for a setter function allows to detect timeouts
195    /// and other error conditions calls of this setter as well. The device will then send a response
196    /// for this purpose. If this flag is disabled for a setter function then no response is sent
197    /// and errors are silently ignored, because they cannot be detected.
198    ///
199    /// See [`set_response_expected`](crate::analog_in_bricklet::AnalogInBricklet::set_response_expected) for the list of function ID constants available for this function.
200    pub fn get_response_expected(&mut self, fun: AnalogInBrickletFunction) -> Result<bool, GetResponseExpectedError> {
201        self.device.get_response_expected(u8::from(fun))
202    }
203
204    /// Changes the response expected flag of the function specified by the function ID parameter.
205    /// This flag can only be changed for setter (default value: false) and callback configuration
206    /// functions (default value: true). For getter functions it is always enabled.
207    ///
208    /// Enabling the response expected flag for a setter function allows to detect timeouts and
209    /// other error conditions calls of this setter as well. The device will then send a response
210    /// for this purpose. If this flag is disabled for a setter function then no response is sent
211    /// and errors are silently ignored, because they cannot be detected.
212    pub fn set_response_expected(
213        &mut self,
214        fun: AnalogInBrickletFunction,
215        response_expected: bool,
216    ) -> Result<(), SetResponseExpectedError> {
217        self.device.set_response_expected(u8::from(fun), response_expected)
218    }
219
220    /// Changes the response expected flag for all setter and callback configuration functions of this device at once.
221    pub fn set_response_expected_all(&mut self, response_expected: bool) {
222        self.device.set_response_expected_all(response_expected)
223    }
224
225    /// Returns the version of the API definition (major, minor, revision) implemented by this API bindings.
226    /// This is neither the release version of this API bindings nor does it tell you anything about the represented Brick or Bricklet.
227    pub fn get_api_version(&self) -> [u8; 3] {
228        self.device.api_version
229    }
230
231    /// This receiver is triggered periodically with the period that is set by
232    /// [`set_voltage_callback_period`]. The parameter is the voltage of the
233    /// sensor.
234    ///
235    /// The [`get_voltage_callback_receiver`] receiver is only triggered if the voltage has changed since
236    /// the last triggering.
237    ///
238    /// [`set_voltage_callback_period`]: #method.set_voltage_callback_period
239    /// [`get_voltage_callback_receiver`]: #method.get_voltage_callback_receiver
240    pub async fn get_voltage_callback_receiver(&mut self) -> impl Stream<Item = u16> {
241        self.device
242            .get_callback_receiver(u8::from(AnalogInBrickletFunction::CallbackVoltage))
243            .await
244            .map(|p| u16::from_le_byte_slice(p.body()))
245    }
246
247    /// This receiver is triggered periodically with the period that is set by
248    /// [`set_analog_value_callback_period`]. The parameter is the analog
249    /// value of the sensor.
250    ///
251    /// The [`get_analog_value_callback_receiver`] receiver is only triggered if the voltage has changed
252    /// since the last triggering.
253    pub async fn get_analog_value_callback_receiver(&mut self) -> impl Stream<Item = u16> {
254        self.device
255            .get_callback_receiver(u8::from(AnalogInBrickletFunction::CallbackAnalogValue))
256            .await
257            .map(|p| u16::from_le_byte_slice(p.body()))
258    }
259
260    /// This receiver is triggered when the threshold as set by
261    /// [`set_voltage_callback_threshold`] is reached.
262    /// The parameter is the voltage of the sensor.
263    ///
264    /// If the threshold keeps being reached, the receiver is triggered periodically
265    /// with the period as set by [`set_debounce_period`].
266    pub async fn get_voltage_reached_callback_receiver(&mut self) -> impl Stream<Item = u16> {
267        self.device
268            .get_callback_receiver(u8::from(AnalogInBrickletFunction::CallbackVoltageReached))
269            .await
270            .map(|p| u16::from_le_byte_slice(p.body()))
271    }
272
273    /// This receiver is triggered when the threshold as set by
274    /// [`set_analog_value_callback_threshold`] is reached.
275    /// The parameter is the analog value of the sensor.
276    ///
277    /// If the threshold keeps being reached, the receiver is triggered periodically
278    /// with the period as set by [`set_debounce_period`].
279    pub async fn get_analog_value_reached_callback_receiver(&mut self) -> impl Stream<Item = u16> {
280        self.device
281            .get_callback_receiver(u8::from(AnalogInBrickletFunction::CallbackAnalogValueReached))
282            .await
283            .map(|p| u16::from_le_byte_slice(p.body()))
284    }
285
286    /// Returns the voltage of the sensor. The resolution between 0 and 6V is about 2mV.
287    /// Between 6 and 45V the resolution is about 10mV.
288    ///
289    /// If you want to get the voltage periodically, it is recommended to use the
290    /// [`get_voltage_callback_receiver`] receiver and set the period with
291    /// [`set_voltage_callback_period`].
292    pub async fn get_voltage(&mut self) -> Result<u16, TinkerforgeError> {
293        let payload = [0; 0];
294
295        #[allow(unused_variables)]
296        let result = self.device.get(u8::from(AnalogInBrickletFunction::GetVoltage), &payload).await?;
297        Ok(u16::from_le_byte_slice(result.body()))
298    }
299
300    /// Returns the value as read by a 12-bit analog-to-digital converter.
301    ///
302    /// # Note
303    ///  The value returned by [`get_voltage`] is averaged over several samples
304    ///  to yield less noise, while [`get_analog_value`] gives back raw
305    ///  unfiltered analog values. The only reason to use [`get_analog_value`] is,
306    ///  if you need the full resolution of the analog-to-digital converter.
307    ///
308    /// If you want the analog value periodically, it is recommended to use the
309    /// [`get_analog_value_callback_receiver`] receiver and set the period with
310    /// [`set_analog_value_callback_period`].
311    pub async fn get_analog_value(&mut self) -> Result<u16, TinkerforgeError> {
312        let payload = [0; 0];
313
314        #[allow(unused_variables)]
315        let result = self.device.get(u8::from(AnalogInBrickletFunction::GetAnalogValue), &payload).await?;
316        Ok(u16::from_le_byte_slice(result.body()))
317    }
318
319    /// Sets the period with which the [`get_voltage_callback_receiver`] receiver is triggered
320    /// periodically. A value of 0 turns the receiver off.
321    ///
322    /// The [`get_voltage_callback_receiver`] receiver is only triggered if the voltage has changed since
323    /// the last triggering.
324    pub async fn set_voltage_callback_period(&mut self, period: u32) -> Result<(), TinkerforgeError> {
325        let mut payload = [0; 4];
326        period.write_to_slice(&mut payload[0..4]);
327
328        #[allow(unused_variables)]
329        let result = self.device.set(u8::from(AnalogInBrickletFunction::SetVoltageCallbackPeriod), &payload).await?;
330        Ok(())
331    }
332
333    /// Returns the period as set by [`set_voltage_callback_period`].
334    pub async fn get_voltage_callback_period(&mut self) -> Result<u32, TinkerforgeError> {
335        let payload = [0; 0];
336
337        #[allow(unused_variables)]
338        let result = self.device.get(u8::from(AnalogInBrickletFunction::GetVoltageCallbackPeriod), &payload).await?;
339        Ok(u32::from_le_byte_slice(result.body()))
340    }
341
342    /// Sets the period with which the [`get_analog_value_callback_receiver`] receiver is triggered
343    /// periodically. A value of 0 turns the receiver off.
344    ///
345    /// The [`get_analog_value_callback_receiver`] receiver is only triggered if the analog value has
346    /// changed since the last triggering.
347    pub async fn set_analog_value_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(AnalogInBrickletFunction::SetAnalogValueCallbackPeriod), &payload).await?;
353        Ok(())
354    }
355
356    /// Returns the period as set by [`set_analog_value_callback_period`].
357    pub async fn get_analog_value_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(AnalogInBrickletFunction::GetAnalogValueCallbackPeriod), &payload).await?;
362        Ok(u32::from_le_byte_slice(result.body()))
363    }
364
365    /// Sets the thresholds for the [`get_voltage_reached_callback_receiver`] receiver.
366    ///
367    /// The following options are possible:
368    ///
369    ///  Option| Description
370    ///  --- | ---
371    ///  'x'|    Receiver is turned off
372    ///  'o'|    Receiver is triggered when the voltage is *outside* the min and max values
373    ///  'i'|    Receiver is triggered when the voltage is *inside* the min and max values
374    ///  '<'|    Receiver is triggered when the voltage is smaller than the min value (max is ignored)
375    ///  '>'|    Receiver is triggered when the voltage is greater than the min value (max is ignored)
376    ///
377    /// Associated constants:
378    /// * ANALOG_IN_BRICKLET_THRESHOLD_OPTION_OFF
379    ///	* ANALOG_IN_BRICKLET_THRESHOLD_OPTION_OUTSIDE
380    ///	* ANALOG_IN_BRICKLET_THRESHOLD_OPTION_INSIDE
381    ///	* ANALOG_IN_BRICKLET_THRESHOLD_OPTION_SMALLER
382    ///	* ANALOG_IN_BRICKLET_THRESHOLD_OPTION_GREATER
383    pub async fn set_voltage_callback_threshold(&mut self, option: char, min: u16, max: u16) -> Result<(), TinkerforgeError> {
384        let mut payload = [0; 5];
385        option.write_to_slice(&mut payload[0..1]);
386        min.write_to_slice(&mut payload[1..3]);
387        max.write_to_slice(&mut payload[3..5]);
388
389        #[allow(unused_variables)]
390        let result = self.device.set(u8::from(AnalogInBrickletFunction::SetVoltageCallbackThreshold), &payload).await?;
391        Ok(())
392    }
393
394    /// Returns the threshold as set by [`set_voltage_callback_threshold`].
395    ///
396    /// Associated constants:
397    /// * ANALOG_IN_BRICKLET_THRESHOLD_OPTION_OFF
398    ///	* ANALOG_IN_BRICKLET_THRESHOLD_OPTION_OUTSIDE
399    ///	* ANALOG_IN_BRICKLET_THRESHOLD_OPTION_INSIDE
400    ///	* ANALOG_IN_BRICKLET_THRESHOLD_OPTION_SMALLER
401    ///	* ANALOG_IN_BRICKLET_THRESHOLD_OPTION_GREATER
402    pub async fn get_voltage_callback_threshold(&mut self) -> Result<VoltageCallbackThreshold, TinkerforgeError> {
403        let payload = [0; 0];
404
405        #[allow(unused_variables)]
406        let result = self.device.get(u8::from(AnalogInBrickletFunction::GetVoltageCallbackThreshold), &payload).await?;
407        Ok(VoltageCallbackThreshold::from_le_byte_slice(result.body()))
408    }
409
410    /// Sets the thresholds for the [`get_analog_value_reached_callback_receiver`] receiver.
411    ///
412    /// The following options are possible:
413    ///
414    ///  Option| Description
415    ///  --- | ---
416    ///  'x'|    Receiver is turned off
417    ///  'o'|    Receiver is triggered when the analog value is *outside* the min and max values
418    ///  'i'|    Receiver is triggered when the analog value is *inside* the min and max values
419    ///  '<'|    Receiver is triggered when the analog value is smaller than the min value (max is ignored)
420    ///  '>'|    Receiver is triggered when the analog value is greater than the min value (max is ignored)
421    ///
422    /// Associated constants:
423    /// * ANALOG_IN_BRICKLET_THRESHOLD_OPTION_OFF
424    ///	* ANALOG_IN_BRICKLET_THRESHOLD_OPTION_OUTSIDE
425    ///	* ANALOG_IN_BRICKLET_THRESHOLD_OPTION_INSIDE
426    ///	* ANALOG_IN_BRICKLET_THRESHOLD_OPTION_SMALLER
427    ///	* ANALOG_IN_BRICKLET_THRESHOLD_OPTION_GREATER
428    pub async fn set_analog_value_callback_threshold(&mut self, option: char, min: u16, max: u16) -> Result<(), TinkerforgeError> {
429        let mut payload = [0; 5];
430        option.write_to_slice(&mut payload[0..1]);
431        min.write_to_slice(&mut payload[1..3]);
432        max.write_to_slice(&mut payload[3..5]);
433
434        #[allow(unused_variables)]
435        let result = self.device.set(u8::from(AnalogInBrickletFunction::SetAnalogValueCallbackThreshold), &payload).await?;
436        Ok(())
437    }
438
439    /// Returns the threshold as set by [`set_analog_value_callback_threshold`].
440    ///
441    /// Associated constants:
442    /// * ANALOG_IN_BRICKLET_THRESHOLD_OPTION_OFF
443    ///	* ANALOG_IN_BRICKLET_THRESHOLD_OPTION_OUTSIDE
444    ///	* ANALOG_IN_BRICKLET_THRESHOLD_OPTION_INSIDE
445    ///	* ANALOG_IN_BRICKLET_THRESHOLD_OPTION_SMALLER
446    ///	* ANALOG_IN_BRICKLET_THRESHOLD_OPTION_GREATER
447    pub async fn get_analog_value_callback_threshold(&mut self) -> Result<AnalogValueCallbackThreshold, TinkerforgeError> {
448        let payload = [0; 0];
449
450        #[allow(unused_variables)]
451        let result = self.device.get(u8::from(AnalogInBrickletFunction::GetAnalogValueCallbackThreshold), &payload).await?;
452        Ok(AnalogValueCallbackThreshold::from_le_byte_slice(result.body()))
453    }
454
455    /// Sets the period with which the threshold receivers
456    ///
457    /// * [`get_voltage_reached_callback_receiver`],
458    /// * [`get_analog_value_reached_callback_receiver`]
459    ///
460    /// are triggered, if the thresholds
461    ///
462    /// * [`set_voltage_callback_threshold`],
463    /// * [`set_analog_value_callback_threshold`]
464    ///
465    /// keep being reached.
466    pub async fn set_debounce_period(&mut self, debounce: u32) -> Result<(), TinkerforgeError> {
467        let mut payload = [0; 4];
468        debounce.write_to_slice(&mut payload[0..4]);
469
470        #[allow(unused_variables)]
471        let result = self.device.set(u8::from(AnalogInBrickletFunction::SetDebouncePeriod), &payload).await?;
472        Ok(())
473    }
474
475    /// Returns the debounce period as set by [`set_debounce_period`].
476    pub async fn get_debounce_period(&mut self) -> Result<u32, TinkerforgeError> {
477        let payload = [0; 0];
478
479        #[allow(unused_variables)]
480        let result = self.device.get(u8::from(AnalogInBrickletFunction::GetDebouncePeriod), &payload).await?;
481        Ok(u32::from_le_byte_slice(result.body()))
482    }
483
484    /// Sets the measurement range. Possible ranges:
485    ///
486    /// * 0: Automatically switched
487    /// * 1: 0V - 6.05V, ~1.48mV resolution
488    /// * 2: 0V - 10.32V, ~2.52mV resolution
489    /// * 3: 0V - 36.30V, ~8.86mV resolution
490    /// * 4: 0V - 45.00V, ~11.25mV resolution
491    /// * 5: 0V - 3.3V, ~0.81mV resolution, new in version 2.0.3$nbsp;(Plugin)
492    ///
493    ///
494    /// .. versionadded:: 2.0.1$nbsp;(Plugin)
495    ///
496    /// Associated constants:
497    /// * ANALOG_IN_BRICKLET_RANGE_AUTOMATIC
498    ///	* ANALOG_IN_BRICKLET_RANGE_UP_TO_6V
499    ///	* ANALOG_IN_BRICKLET_RANGE_UP_TO_10V
500    ///	* ANALOG_IN_BRICKLET_RANGE_UP_TO_36V
501    ///	* ANALOG_IN_BRICKLET_RANGE_UP_TO_45V
502    ///	* ANALOG_IN_BRICKLET_RANGE_UP_TO_3V
503    pub async fn set_range(&mut self, range: u8) -> Result<(), TinkerforgeError> {
504        let mut payload = [0; 1];
505        range.write_to_slice(&mut payload[0..1]);
506
507        #[allow(unused_variables)]
508        let result = self.device.set(u8::from(AnalogInBrickletFunction::SetRange), &payload).await?;
509        Ok(())
510    }
511
512    /// Returns the measurement range as set by [`set_range`].
513    ///
514    ///
515    /// .. versionadded:: 2.0.1$nbsp;(Plugin)
516    ///
517    /// Associated constants:
518    /// * ANALOG_IN_BRICKLET_RANGE_AUTOMATIC
519    ///	* ANALOG_IN_BRICKLET_RANGE_UP_TO_6V
520    ///	* ANALOG_IN_BRICKLET_RANGE_UP_TO_10V
521    ///	* ANALOG_IN_BRICKLET_RANGE_UP_TO_36V
522    ///	* ANALOG_IN_BRICKLET_RANGE_UP_TO_45V
523    ///	* ANALOG_IN_BRICKLET_RANGE_UP_TO_3V
524    pub async fn get_range(&mut self) -> Result<u8, TinkerforgeError> {
525        let payload = [0; 0];
526
527        #[allow(unused_variables)]
528        let result = self.device.get(u8::from(AnalogInBrickletFunction::GetRange), &payload).await?;
529        Ok(u8::from_le_byte_slice(result.body()))
530    }
531
532    /// Set the length of a averaging for the voltage value.
533    ///
534    /// Setting the length to 0 will turn the averaging completely off. If the
535    /// averaging is off, there is more noise on the data, but the data is without
536    /// delay.
537    ///
538    ///
539    /// .. versionadded:: 2.0.3$nbsp;(Plugin)
540    pub async fn set_averaging(&mut self, average: u8) -> Result<(), TinkerforgeError> {
541        let mut payload = [0; 1];
542        average.write_to_slice(&mut payload[0..1]);
543
544        #[allow(unused_variables)]
545        let result = self.device.set(u8::from(AnalogInBrickletFunction::SetAveraging), &payload).await?;
546        Ok(())
547    }
548
549    /// Returns the averaging configuration as set by [`set_averaging`].
550    ///
551    ///
552    /// .. versionadded:: 2.0.3$nbsp;(Plugin)
553    pub async fn get_averaging(&mut self) -> Result<u8, TinkerforgeError> {
554        let payload = [0; 0];
555
556        #[allow(unused_variables)]
557        let result = self.device.get(u8::from(AnalogInBrickletFunction::GetAveraging), &payload).await?;
558        Ok(u8::from_le_byte_slice(result.body()))
559    }
560
561    /// Returns the UID, the UID where the Bricklet is connected to,
562    /// the position, the hardware and firmware version as well as the
563    /// device identifier.
564    ///
565    /// The position can be 'a', 'b', 'c', 'd', 'e', 'f', 'g' or 'h' (Bricklet Port).
566    /// A Bricklet connected to an [Isolator Bricklet](isolator_bricklet) is always at
567    /// position 'z'.
568    ///
569    /// The device identifier numbers can be found [here](device_identifier).
570    /// |device_identifier_constant|
571    pub async fn get_identity(&mut self) -> Result<Identity, TinkerforgeError> {
572        let payload = [0; 0];
573
574        #[allow(unused_variables)]
575        let result = self.device.get(u8::from(AnalogInBrickletFunction::GetIdentity), &payload).await?;
576        Ok(Identity::from_le_byte_slice(result.body()))
577    }
578}