tinkerforge_async/bindings/
laser_range_finder_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 distance up to 40m with laser light.
12//!
13//! See also the documentation [here](https://www.tinkerforge.com/en/doc/Software/Bricklets/LaserRangeFinderV2_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 LaserRangeFinderV2BrickletFunction {
24    GetDistance,
25    SetDistanceCallbackConfiguration,
26    GetDistanceCallbackConfiguration,
27    GetVelocity,
28    SetVelocityCallbackConfiguration,
29    GetVelocityCallbackConfiguration,
30    SetEnable,
31    GetEnable,
32    SetConfiguration,
33    GetConfiguration,
34    SetMovingAverage,
35    GetMovingAverage,
36    SetOffsetCalibration,
37    GetOffsetCalibration,
38    SetDistanceLedConfig,
39    GetDistanceLedConfig,
40    GetSpitfpErrorCount,
41    SetBootloaderMode,
42    GetBootloaderMode,
43    SetWriteFirmwarePointer,
44    WriteFirmware,
45    SetStatusLedConfig,
46    GetStatusLedConfig,
47    GetChipTemperature,
48    Reset,
49    WriteUid,
50    ReadUid,
51    GetIdentity,
52    CallbackDistance,
53    CallbackVelocity,
54}
55impl From<LaserRangeFinderV2BrickletFunction> for u8 {
56    fn from(fun: LaserRangeFinderV2BrickletFunction) -> Self {
57        match fun {
58            LaserRangeFinderV2BrickletFunction::GetDistance => 1,
59            LaserRangeFinderV2BrickletFunction::SetDistanceCallbackConfiguration => 2,
60            LaserRangeFinderV2BrickletFunction::GetDistanceCallbackConfiguration => 3,
61            LaserRangeFinderV2BrickletFunction::GetVelocity => 5,
62            LaserRangeFinderV2BrickletFunction::SetVelocityCallbackConfiguration => 6,
63            LaserRangeFinderV2BrickletFunction::GetVelocityCallbackConfiguration => 7,
64            LaserRangeFinderV2BrickletFunction::SetEnable => 9,
65            LaserRangeFinderV2BrickletFunction::GetEnable => 10,
66            LaserRangeFinderV2BrickletFunction::SetConfiguration => 11,
67            LaserRangeFinderV2BrickletFunction::GetConfiguration => 12,
68            LaserRangeFinderV2BrickletFunction::SetMovingAverage => 13,
69            LaserRangeFinderV2BrickletFunction::GetMovingAverage => 14,
70            LaserRangeFinderV2BrickletFunction::SetOffsetCalibration => 15,
71            LaserRangeFinderV2BrickletFunction::GetOffsetCalibration => 16,
72            LaserRangeFinderV2BrickletFunction::SetDistanceLedConfig => 17,
73            LaserRangeFinderV2BrickletFunction::GetDistanceLedConfig => 18,
74            LaserRangeFinderV2BrickletFunction::GetSpitfpErrorCount => 234,
75            LaserRangeFinderV2BrickletFunction::SetBootloaderMode => 235,
76            LaserRangeFinderV2BrickletFunction::GetBootloaderMode => 236,
77            LaserRangeFinderV2BrickletFunction::SetWriteFirmwarePointer => 237,
78            LaserRangeFinderV2BrickletFunction::WriteFirmware => 238,
79            LaserRangeFinderV2BrickletFunction::SetStatusLedConfig => 239,
80            LaserRangeFinderV2BrickletFunction::GetStatusLedConfig => 240,
81            LaserRangeFinderV2BrickletFunction::GetChipTemperature => 242,
82            LaserRangeFinderV2BrickletFunction::Reset => 243,
83            LaserRangeFinderV2BrickletFunction::WriteUid => 248,
84            LaserRangeFinderV2BrickletFunction::ReadUid => 249,
85            LaserRangeFinderV2BrickletFunction::GetIdentity => 255,
86            LaserRangeFinderV2BrickletFunction::CallbackDistance => 4,
87            LaserRangeFinderV2BrickletFunction::CallbackVelocity => 8,
88        }
89    }
90}
91pub const LASER_RANGE_FINDER_V2_BRICKLET_THRESHOLD_OPTION_OFF: char = 'x';
92pub const LASER_RANGE_FINDER_V2_BRICKLET_THRESHOLD_OPTION_OUTSIDE: char = 'o';
93pub const LASER_RANGE_FINDER_V2_BRICKLET_THRESHOLD_OPTION_INSIDE: char = 'i';
94pub const LASER_RANGE_FINDER_V2_BRICKLET_THRESHOLD_OPTION_SMALLER: char = '<';
95pub const LASER_RANGE_FINDER_V2_BRICKLET_THRESHOLD_OPTION_GREATER: char = '>';
96pub const LASER_RANGE_FINDER_V2_BRICKLET_DISTANCE_LED_CONFIG_OFF: u8 = 0;
97pub const LASER_RANGE_FINDER_V2_BRICKLET_DISTANCE_LED_CONFIG_ON: u8 = 1;
98pub const LASER_RANGE_FINDER_V2_BRICKLET_DISTANCE_LED_CONFIG_SHOW_HEARTBEAT: u8 = 2;
99pub const LASER_RANGE_FINDER_V2_BRICKLET_DISTANCE_LED_CONFIG_SHOW_DISTANCE: u8 = 3;
100pub const LASER_RANGE_FINDER_V2_BRICKLET_BOOTLOADER_MODE_BOOTLOADER: u8 = 0;
101pub const LASER_RANGE_FINDER_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE: u8 = 1;
102pub const LASER_RANGE_FINDER_V2_BRICKLET_BOOTLOADER_MODE_BOOTLOADER_WAIT_FOR_REBOOT: u8 = 2;
103pub const LASER_RANGE_FINDER_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_REBOOT: u8 = 3;
104pub const LASER_RANGE_FINDER_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_ERASE_AND_REBOOT: u8 = 4;
105pub const LASER_RANGE_FINDER_V2_BRICKLET_BOOTLOADER_STATUS_OK: u8 = 0;
106pub const LASER_RANGE_FINDER_V2_BRICKLET_BOOTLOADER_STATUS_INVALID_MODE: u8 = 1;
107pub const LASER_RANGE_FINDER_V2_BRICKLET_BOOTLOADER_STATUS_NO_CHANGE: u8 = 2;
108pub const LASER_RANGE_FINDER_V2_BRICKLET_BOOTLOADER_STATUS_ENTRY_FUNCTION_NOT_PRESENT: u8 = 3;
109pub const LASER_RANGE_FINDER_V2_BRICKLET_BOOTLOADER_STATUS_DEVICE_IDENTIFIER_INCORRECT: u8 = 4;
110pub const LASER_RANGE_FINDER_V2_BRICKLET_BOOTLOADER_STATUS_CRC_MISMATCH: u8 = 5;
111pub const LASER_RANGE_FINDER_V2_BRICKLET_STATUS_LED_CONFIG_OFF: u8 = 0;
112pub const LASER_RANGE_FINDER_V2_BRICKLET_STATUS_LED_CONFIG_ON: u8 = 1;
113pub const LASER_RANGE_FINDER_V2_BRICKLET_STATUS_LED_CONFIG_SHOW_HEARTBEAT: u8 = 2;
114pub const LASER_RANGE_FINDER_V2_BRICKLET_STATUS_LED_CONFIG_SHOW_STATUS: u8 = 3;
115
116#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
117pub struct DistanceCallbackConfiguration {
118    pub period: u32,
119    pub value_has_to_change: bool,
120    pub option: char,
121    pub min: i16,
122    pub max: i16,
123}
124impl FromByteSlice for DistanceCallbackConfiguration {
125    fn bytes_expected() -> usize {
126        10
127    }
128    fn from_le_byte_slice(bytes: &[u8]) -> DistanceCallbackConfiguration {
129        DistanceCallbackConfiguration {
130            period: <u32>::from_le_byte_slice(&bytes[0..4]),
131            value_has_to_change: <bool>::from_le_byte_slice(&bytes[4..5]),
132            option: <char>::from_le_byte_slice(&bytes[5..6]),
133            min: <i16>::from_le_byte_slice(&bytes[6..8]),
134            max: <i16>::from_le_byte_slice(&bytes[8..10]),
135        }
136    }
137}
138
139#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
140pub struct VelocityCallbackConfiguration {
141    pub period: u32,
142    pub value_has_to_change: bool,
143    pub option: char,
144    pub min: i16,
145    pub max: i16,
146}
147impl FromByteSlice for VelocityCallbackConfiguration {
148    fn bytes_expected() -> usize {
149        10
150    }
151    fn from_le_byte_slice(bytes: &[u8]) -> VelocityCallbackConfiguration {
152        VelocityCallbackConfiguration {
153            period: <u32>::from_le_byte_slice(&bytes[0..4]),
154            value_has_to_change: <bool>::from_le_byte_slice(&bytes[4..5]),
155            option: <char>::from_le_byte_slice(&bytes[5..6]),
156            min: <i16>::from_le_byte_slice(&bytes[6..8]),
157            max: <i16>::from_le_byte_slice(&bytes[8..10]),
158        }
159    }
160}
161
162#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
163pub struct Configuration {
164    pub acquisition_count: u8,
165    pub enable_quick_termination: bool,
166    pub threshold_value: u8,
167    pub measurement_frequency: u16,
168}
169impl FromByteSlice for Configuration {
170    fn bytes_expected() -> usize {
171        5
172    }
173    fn from_le_byte_slice(bytes: &[u8]) -> Configuration {
174        Configuration {
175            acquisition_count: <u8>::from_le_byte_slice(&bytes[0..1]),
176            enable_quick_termination: <bool>::from_le_byte_slice(&bytes[1..2]),
177            threshold_value: <u8>::from_le_byte_slice(&bytes[2..3]),
178            measurement_frequency: <u16>::from_le_byte_slice(&bytes[3..5]),
179        }
180    }
181}
182
183#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
184pub struct MovingAverage {
185    pub distance_average_length: u8,
186    pub velocity_average_length: u8,
187}
188impl FromByteSlice for MovingAverage {
189    fn bytes_expected() -> usize {
190        2
191    }
192    fn from_le_byte_slice(bytes: &[u8]) -> MovingAverage {
193        MovingAverage {
194            distance_average_length: <u8>::from_le_byte_slice(&bytes[0..1]),
195            velocity_average_length: <u8>::from_le_byte_slice(&bytes[1..2]),
196        }
197    }
198}
199
200#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
201pub struct SpitfpErrorCount {
202    pub error_count_ack_checksum: u32,
203    pub error_count_message_checksum: u32,
204    pub error_count_frame: u32,
205    pub error_count_overflow: u32,
206}
207impl FromByteSlice for SpitfpErrorCount {
208    fn bytes_expected() -> usize {
209        16
210    }
211    fn from_le_byte_slice(bytes: &[u8]) -> SpitfpErrorCount {
212        SpitfpErrorCount {
213            error_count_ack_checksum: <u32>::from_le_byte_slice(&bytes[0..4]),
214            error_count_message_checksum: <u32>::from_le_byte_slice(&bytes[4..8]),
215            error_count_frame: <u32>::from_le_byte_slice(&bytes[8..12]),
216            error_count_overflow: <u32>::from_le_byte_slice(&bytes[12..16]),
217        }
218    }
219}
220
221#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
222pub struct Identity {
223    pub uid: String,
224    pub connected_uid: String,
225    pub position: char,
226    pub hardware_version: [u8; 3],
227    pub firmware_version: [u8; 3],
228    pub device_identifier: u16,
229}
230impl FromByteSlice for Identity {
231    fn bytes_expected() -> usize {
232        25
233    }
234    fn from_le_byte_slice(bytes: &[u8]) -> Identity {
235        Identity {
236            uid: <String>::from_le_byte_slice(&bytes[0..8]),
237            connected_uid: <String>::from_le_byte_slice(&bytes[8..16]),
238            position: <char>::from_le_byte_slice(&bytes[16..17]),
239            hardware_version: <[u8; 3]>::from_le_byte_slice(&bytes[17..20]),
240            firmware_version: <[u8; 3]>::from_le_byte_slice(&bytes[20..23]),
241            device_identifier: <u16>::from_le_byte_slice(&bytes[23..25]),
242        }
243    }
244}
245
246/// Measures distance up to 40m with laser light
247#[derive(Clone)]
248pub struct LaserRangeFinderV2Bricklet {
249    device: Device,
250}
251impl LaserRangeFinderV2Bricklet {
252    pub const DEVICE_IDENTIFIER: u16 = 2144;
253    pub const DEVICE_DISPLAY_NAME: &'static str = "Laser Range Finder Bricklet 2.0";
254    /// Creates an object with the unique device ID `uid`. This object can then be used after the IP Connection `ip_connection` is connected.
255    pub fn new(uid: Uid, connection: AsyncIpConnection) -> LaserRangeFinderV2Bricklet {
256        let mut result = LaserRangeFinderV2Bricklet { device: Device::new([2, 0, 10], uid, connection, Self::DEVICE_DISPLAY_NAME) };
257        result.device.response_expected[u8::from(LaserRangeFinderV2BrickletFunction::GetDistance) as usize] =
258            ResponseExpectedFlag::AlwaysTrue;
259        result.device.response_expected[u8::from(LaserRangeFinderV2BrickletFunction::SetDistanceCallbackConfiguration) as usize] =
260            ResponseExpectedFlag::True;
261        result.device.response_expected[u8::from(LaserRangeFinderV2BrickletFunction::GetDistanceCallbackConfiguration) as usize] =
262            ResponseExpectedFlag::AlwaysTrue;
263        result.device.response_expected[u8::from(LaserRangeFinderV2BrickletFunction::GetVelocity) as usize] =
264            ResponseExpectedFlag::AlwaysTrue;
265        result.device.response_expected[u8::from(LaserRangeFinderV2BrickletFunction::SetVelocityCallbackConfiguration) as usize] =
266            ResponseExpectedFlag::True;
267        result.device.response_expected[u8::from(LaserRangeFinderV2BrickletFunction::GetVelocityCallbackConfiguration) as usize] =
268            ResponseExpectedFlag::AlwaysTrue;
269        result.device.response_expected[u8::from(LaserRangeFinderV2BrickletFunction::SetEnable) as usize] = ResponseExpectedFlag::False;
270        result.device.response_expected[u8::from(LaserRangeFinderV2BrickletFunction::GetEnable) as usize] =
271            ResponseExpectedFlag::AlwaysTrue;
272        result.device.response_expected[u8::from(LaserRangeFinderV2BrickletFunction::SetConfiguration) as usize] =
273            ResponseExpectedFlag::False;
274        result.device.response_expected[u8::from(LaserRangeFinderV2BrickletFunction::GetConfiguration) as usize] =
275            ResponseExpectedFlag::AlwaysTrue;
276        result.device.response_expected[u8::from(LaserRangeFinderV2BrickletFunction::SetMovingAverage) as usize] =
277            ResponseExpectedFlag::False;
278        result.device.response_expected[u8::from(LaserRangeFinderV2BrickletFunction::GetMovingAverage) as usize] =
279            ResponseExpectedFlag::AlwaysTrue;
280        result.device.response_expected[u8::from(LaserRangeFinderV2BrickletFunction::SetOffsetCalibration) as usize] =
281            ResponseExpectedFlag::False;
282        result.device.response_expected[u8::from(LaserRangeFinderV2BrickletFunction::GetOffsetCalibration) as usize] =
283            ResponseExpectedFlag::AlwaysTrue;
284        result.device.response_expected[u8::from(LaserRangeFinderV2BrickletFunction::SetDistanceLedConfig) as usize] =
285            ResponseExpectedFlag::False;
286        result.device.response_expected[u8::from(LaserRangeFinderV2BrickletFunction::GetDistanceLedConfig) as usize] =
287            ResponseExpectedFlag::AlwaysTrue;
288        result.device.response_expected[u8::from(LaserRangeFinderV2BrickletFunction::GetSpitfpErrorCount) as usize] =
289            ResponseExpectedFlag::AlwaysTrue;
290        result.device.response_expected[u8::from(LaserRangeFinderV2BrickletFunction::SetBootloaderMode) as usize] =
291            ResponseExpectedFlag::AlwaysTrue;
292        result.device.response_expected[u8::from(LaserRangeFinderV2BrickletFunction::GetBootloaderMode) as usize] =
293            ResponseExpectedFlag::AlwaysTrue;
294        result.device.response_expected[u8::from(LaserRangeFinderV2BrickletFunction::SetWriteFirmwarePointer) as usize] =
295            ResponseExpectedFlag::False;
296        result.device.response_expected[u8::from(LaserRangeFinderV2BrickletFunction::WriteFirmware) as usize] =
297            ResponseExpectedFlag::AlwaysTrue;
298        result.device.response_expected[u8::from(LaserRangeFinderV2BrickletFunction::SetStatusLedConfig) as usize] =
299            ResponseExpectedFlag::False;
300        result.device.response_expected[u8::from(LaserRangeFinderV2BrickletFunction::GetStatusLedConfig) as usize] =
301            ResponseExpectedFlag::AlwaysTrue;
302        result.device.response_expected[u8::from(LaserRangeFinderV2BrickletFunction::GetChipTemperature) as usize] =
303            ResponseExpectedFlag::AlwaysTrue;
304        result.device.response_expected[u8::from(LaserRangeFinderV2BrickletFunction::Reset) as usize] = ResponseExpectedFlag::False;
305        result.device.response_expected[u8::from(LaserRangeFinderV2BrickletFunction::WriteUid) as usize] = ResponseExpectedFlag::False;
306        result.device.response_expected[u8::from(LaserRangeFinderV2BrickletFunction::ReadUid) as usize] = ResponseExpectedFlag::AlwaysTrue;
307        result.device.response_expected[u8::from(LaserRangeFinderV2BrickletFunction::GetIdentity) as usize] =
308            ResponseExpectedFlag::AlwaysTrue;
309        result
310    }
311
312    /// Returns the response expected flag for the function specified by the function ID parameter.
313    /// It is true if the function is expected to send a response, false otherwise.
314    ///
315    /// For getter functions this is enabled by default and cannot be disabled, because those
316    /// functions will always send a response. For callback configuration functions it is enabled
317    /// by default too, but can be disabled by [`set_response_expected`](crate::laser_range_finder_v2_bricklet::LaserRangeFinderV2Bricklet::set_response_expected).
318    /// For setter functions it is disabled by default and can be enabled.
319    ///
320    /// Enabling the response expected flag for a setter function allows to detect timeouts
321    /// and other error conditions calls of this setter as well. The device will then send a response
322    /// for this purpose. If this flag is disabled for a setter function then no response is sent
323    /// and errors are silently ignored, because they cannot be detected.
324    ///
325    /// See [`set_response_expected`](crate::laser_range_finder_v2_bricklet::LaserRangeFinderV2Bricklet::set_response_expected) for the list of function ID constants available for this function.
326    pub fn get_response_expected(&mut self, fun: LaserRangeFinderV2BrickletFunction) -> Result<bool, GetResponseExpectedError> {
327        self.device.get_response_expected(u8::from(fun))
328    }
329
330    /// Changes the response expected flag of the function specified by the function ID parameter.
331    /// This flag can only be changed for setter (default value: false) and callback configuration
332    /// functions (default value: true). For getter functions it is always enabled.
333    ///
334    /// Enabling the response expected flag for a setter function allows to detect timeouts and
335    /// other error conditions calls of this setter as well. The device will then send a response
336    /// for this purpose. If this flag is disabled for a setter function then no response is sent
337    /// and errors are silently ignored, because they cannot be detected.
338    pub fn set_response_expected(
339        &mut self,
340        fun: LaserRangeFinderV2BrickletFunction,
341        response_expected: bool,
342    ) -> Result<(), SetResponseExpectedError> {
343        self.device.set_response_expected(u8::from(fun), response_expected)
344    }
345
346    /// Changes the response expected flag for all setter and callback configuration functions of this device at once.
347    pub fn set_response_expected_all(&mut self, response_expected: bool) {
348        self.device.set_response_expected_all(response_expected)
349    }
350
351    /// Returns the version of the API definition (major, minor, revision) implemented by this API bindings.
352    /// This is neither the release version of this API bindings nor does it tell you anything about the represented Brick or Bricklet.
353    pub fn get_api_version(&self) -> [u8; 3] {
354        self.device.api_version
355    }
356
357    /// This receiver is triggered periodically according to the configuration set by
358    /// [`set_distance_callback_configuration`].
359    ///
360    /// The parameter is the same as [`get_distance`].
361    ///
362    /// [`get_distance`]: #method.get_distance
363    /// [`set_distance_callback_configuration`]: #method.set_distance_callback_configuration
364    pub async fn get_distance_callback_receiver(&mut self) -> impl Stream<Item = i16> {
365        self.device
366            .get_callback_receiver(u8::from(LaserRangeFinderV2BrickletFunction::CallbackDistance))
367            .await
368            .map(|p| i16::from_le_byte_slice(p.body()))
369    }
370
371    /// This receiver is triggered periodically according to the configuration set by
372    /// [`set_velocity_callback_configuration`].
373    ///
374    /// The parameter is the same as [`get_velocity`].
375    pub async fn get_velocity_callback_receiver(&mut self) -> impl Stream<Item = i16> {
376        self.device
377            .get_callback_receiver(u8::from(LaserRangeFinderV2BrickletFunction::CallbackVelocity))
378            .await
379            .map(|p| i16::from_le_byte_slice(p.body()))
380    }
381
382    /// Returns the measured distance.
383    ///
384    /// The laser has to be enabled, see [`set_enable`].
385    ///
386    ///
387    /// If you want to get the value periodically, it is recommended to use the
388    /// [`get_distance_callback_receiver`] receiver. You can set the receiver configuration
389    /// with [`set_distance_callback_configuration`].
390    pub async fn get_distance(&mut self) -> Result<i16, TinkerforgeError> {
391        let payload = [0; 0];
392
393        #[allow(unused_variables)]
394        let result = self.device.get(u8::from(LaserRangeFinderV2BrickletFunction::GetDistance), &payload).await?;
395        Ok(i16::from_le_byte_slice(result.body()))
396    }
397
398    /// The period is the period with which the [`get_distance_callback_receiver`] receiver is triggered
399    /// periodically. A value of 0 turns the receiver off.
400    ///
401    /// If the `value has to change`-parameter is set to true, the receiver is only
402    /// triggered after the value has changed. If the value didn't change
403    /// within the period, the receiver is triggered immediately on change.
404    ///
405    /// If it is set to false, the receiver is continuously triggered with the period,
406    /// independent of the value.
407    ///
408    /// It is furthermore possible to constrain the receiver with thresholds.
409    ///
410    /// The `option`-parameter together with min/max sets a threshold for the [`get_distance_callback_receiver`] receiver.
411    ///
412    /// The following options are possible:
413    ///
414    ///  Option| Description
415    ///  --- | ---
416    ///  'x'|    Threshold is turned off
417    ///  'o'|    Threshold is triggered when the value is *outside* the min and max values
418    ///  'i'|    Threshold is triggered when the value is *inside* or equal to the min and max values
419    ///  '<'|    Threshold is triggered when the value is smaller than the min value (max is ignored)
420    ///  '>'|    Threshold is triggered when the value is greater than the min value (max is ignored)
421    ///
422    /// If the option is set to 'x' (threshold turned off) the receiver is triggered with the fixed period.
423    ///
424    /// Associated constants:
425    /// * LASER_RANGE_FINDER_V2_BRICKLET_THRESHOLD_OPTION_OFF
426    ///	* LASER_RANGE_FINDER_V2_BRICKLET_THRESHOLD_OPTION_OUTSIDE
427    ///	* LASER_RANGE_FINDER_V2_BRICKLET_THRESHOLD_OPTION_INSIDE
428    ///	* LASER_RANGE_FINDER_V2_BRICKLET_THRESHOLD_OPTION_SMALLER
429    ///	* LASER_RANGE_FINDER_V2_BRICKLET_THRESHOLD_OPTION_GREATER
430    pub async fn set_distance_callback_configuration(
431        &mut self,
432        period: u32,
433        value_has_to_change: bool,
434        option: char,
435        min: i16,
436        max: i16,
437    ) -> Result<(), TinkerforgeError> {
438        let mut payload = [0; 10];
439        period.write_to_slice(&mut payload[0..4]);
440        value_has_to_change.write_to_slice(&mut payload[4..5]);
441        option.write_to_slice(&mut payload[5..6]);
442        min.write_to_slice(&mut payload[6..8]);
443        max.write_to_slice(&mut payload[8..10]);
444
445        #[allow(unused_variables)]
446        let result = self.device.set(u8::from(LaserRangeFinderV2BrickletFunction::SetDistanceCallbackConfiguration), &payload).await?;
447        Ok(())
448    }
449
450    /// Returns the receiver configuration as set by [`set_distance_callback_configuration`].
451    ///
452    /// Associated constants:
453    /// * LASER_RANGE_FINDER_V2_BRICKLET_THRESHOLD_OPTION_OFF
454    ///	* LASER_RANGE_FINDER_V2_BRICKLET_THRESHOLD_OPTION_OUTSIDE
455    ///	* LASER_RANGE_FINDER_V2_BRICKLET_THRESHOLD_OPTION_INSIDE
456    ///	* LASER_RANGE_FINDER_V2_BRICKLET_THRESHOLD_OPTION_SMALLER
457    ///	* LASER_RANGE_FINDER_V2_BRICKLET_THRESHOLD_OPTION_GREATER
458    pub async fn get_distance_callback_configuration(&mut self) -> Result<DistanceCallbackConfiguration, TinkerforgeError> {
459        let payload = [0; 0];
460
461        #[allow(unused_variables)]
462        let result = self.device.get(u8::from(LaserRangeFinderV2BrickletFunction::GetDistanceCallbackConfiguration), &payload).await?;
463        Ok(DistanceCallbackConfiguration::from_le_byte_slice(result.body()))
464    }
465
466    /// Returns the measured velocity. The value has a range of -12800 to 12700
467    /// and is given in 1/100 m/s.
468    ///
469    /// The velocity measurement only produces stables results if a fixed
470    /// measurement rate (see [`set_configuration`]) is configured. Also the laser
471    /// has to be enabled, see [`set_enable`].
472    ///
473    ///
474    /// If you want to get the value periodically, it is recommended to use the
475    /// [`get_velocity_callback_receiver`] receiver. You can set the receiver configuration
476    /// with [`set_velocity_callback_configuration`].
477    pub async fn get_velocity(&mut self) -> Result<i16, TinkerforgeError> {
478        let payload = [0; 0];
479
480        #[allow(unused_variables)]
481        let result = self.device.get(u8::from(LaserRangeFinderV2BrickletFunction::GetVelocity), &payload).await?;
482        Ok(i16::from_le_byte_slice(result.body()))
483    }
484
485    /// The period is the period with which the [`get_velocity_callback_receiver`] receiver is triggered
486    /// periodically. A value of 0 turns the receiver off.
487    ///
488    /// If the `value has to change`-parameter is set to true, the receiver is only
489    /// triggered after the value has changed. If the value didn't change
490    /// within the period, the receiver is triggered immediately on change.
491    ///
492    /// If it is set to false, the receiver is continuously triggered with the period,
493    /// independent of the value.
494    ///
495    /// It is furthermore possible to constrain the receiver with thresholds.
496    ///
497    /// The `option`-parameter together with min/max sets a threshold for the [`get_velocity_callback_receiver`] receiver.
498    ///
499    /// The following options are possible:
500    ///
501    ///  Option| Description
502    ///  --- | ---
503    ///  'x'|    Threshold is turned off
504    ///  'o'|    Threshold is triggered when the value is *outside* the min and max values
505    ///  'i'|    Threshold is triggered when the value is *inside* or equal to the min and max values
506    ///  '<'|    Threshold is triggered when the value is smaller than the min value (max is ignored)
507    ///  '>'|    Threshold is triggered when the value is greater than the min value (max is ignored)
508    ///
509    /// If the option is set to 'x' (threshold turned off) the receiver is triggered with the fixed period.
510    ///
511    /// Associated constants:
512    /// * LASER_RANGE_FINDER_V2_BRICKLET_THRESHOLD_OPTION_OFF
513    ///	* LASER_RANGE_FINDER_V2_BRICKLET_THRESHOLD_OPTION_OUTSIDE
514    ///	* LASER_RANGE_FINDER_V2_BRICKLET_THRESHOLD_OPTION_INSIDE
515    ///	* LASER_RANGE_FINDER_V2_BRICKLET_THRESHOLD_OPTION_SMALLER
516    ///	* LASER_RANGE_FINDER_V2_BRICKLET_THRESHOLD_OPTION_GREATER
517    pub async fn set_velocity_callback_configuration(
518        &mut self,
519        period: u32,
520        value_has_to_change: bool,
521        option: char,
522        min: i16,
523        max: i16,
524    ) -> Result<(), TinkerforgeError> {
525        let mut payload = [0; 10];
526        period.write_to_slice(&mut payload[0..4]);
527        value_has_to_change.write_to_slice(&mut payload[4..5]);
528        option.write_to_slice(&mut payload[5..6]);
529        min.write_to_slice(&mut payload[6..8]);
530        max.write_to_slice(&mut payload[8..10]);
531
532        #[allow(unused_variables)]
533        let result = self.device.set(u8::from(LaserRangeFinderV2BrickletFunction::SetVelocityCallbackConfiguration), &payload).await?;
534        Ok(())
535    }
536
537    /// Returns the receiver configuration as set by [`set_velocity_callback_configuration`].
538    ///
539    /// Associated constants:
540    /// * LASER_RANGE_FINDER_V2_BRICKLET_THRESHOLD_OPTION_OFF
541    ///	* LASER_RANGE_FINDER_V2_BRICKLET_THRESHOLD_OPTION_OUTSIDE
542    ///	* LASER_RANGE_FINDER_V2_BRICKLET_THRESHOLD_OPTION_INSIDE
543    ///	* LASER_RANGE_FINDER_V2_BRICKLET_THRESHOLD_OPTION_SMALLER
544    ///	* LASER_RANGE_FINDER_V2_BRICKLET_THRESHOLD_OPTION_GREATER
545    pub async fn get_velocity_callback_configuration(&mut self) -> Result<VelocityCallbackConfiguration, TinkerforgeError> {
546        let payload = [0; 0];
547
548        #[allow(unused_variables)]
549        let result = self.device.get(u8::from(LaserRangeFinderV2BrickletFunction::GetVelocityCallbackConfiguration), &payload).await?;
550        Ok(VelocityCallbackConfiguration::from_le_byte_slice(result.body()))
551    }
552
553    /// Enables the laser of the LIDAR if set to *true*.
554    ///
555    /// We recommend that you wait 250ms after enabling the laser before
556    /// the first call of [`get_distance`] to ensure stable measurements.
557    pub async fn set_enable(&mut self, enable: bool) -> Result<(), TinkerforgeError> {
558        let mut payload = [0; 1];
559        enable.write_to_slice(&mut payload[0..1]);
560
561        #[allow(unused_variables)]
562        let result = self.device.set(u8::from(LaserRangeFinderV2BrickletFunction::SetEnable), &payload).await?;
563        Ok(())
564    }
565
566    /// Returns the value as set by [`set_enable`].
567    pub async fn get_enable(&mut self) -> Result<bool, TinkerforgeError> {
568        let payload = [0; 0];
569
570        #[allow(unused_variables)]
571        let result = self.device.get(u8::from(LaserRangeFinderV2BrickletFunction::GetEnable), &payload).await?;
572        Ok(bool::from_le_byte_slice(result.body()))
573    }
574
575    /// The **Acquisition Count** defines the number of times the Laser Range Finder Bricklet
576    /// will integrate acquisitions to find a correlation record peak. With a higher count,
577    /// the Bricklet can measure longer distances. With a lower count, the rate increases. The
578    /// allowed values are 1-255.
579    ///
580    /// If you set **Enable Quick Termination** to true, the distance measurement will be terminated
581    /// early if a high peak was already detected. This means that a higher measurement rate can be achieved
582    /// and long distances can be measured at the same time. However, the chance of false-positive
583    /// distance measurements increases.
584    ///
585    /// Normally the distance is calculated with a detection algorithm that uses peak value,
586    /// signal strength and noise. You can however also define a fixed **Threshold Value**.
587    /// Set this to a low value if you want to measure the distance to something that has
588    /// very little reflection (e.g. glass) and set it to a high value if you want to measure
589    /// the distance to something with a very high reflection (e.g. mirror). Set this to 0 to
590    /// use the default algorithm. The other allowed values are 1-255.
591    ///
592    /// Set the **Measurement Frequency** to force a fixed measurement rate. If set to 0,
593    /// the Laser Range Finder Bricklet will use the optimal frequency according to the other
594    /// configurations and the actual measured distance. Since the rate is not fixed in this case,
595    /// the velocity measurement is not stable. For a stable velocity measurement you should
596    /// set a fixed measurement frequency. The lower the frequency, the higher is the resolution
597    /// of the calculated velocity. The allowed values are 10Hz-500Hz (and 0 to turn the fixed
598    /// frequency off).
599    ///
600    /// The default values for Acquisition Count, Enable Quick Termination, Threshold Value and
601    /// Measurement Frequency are 128, false, 0 and 0.
602    pub async fn set_configuration(
603        &mut self,
604        acquisition_count: u8,
605        enable_quick_termination: bool,
606        threshold_value: u8,
607        measurement_frequency: u16,
608    ) -> Result<(), TinkerforgeError> {
609        let mut payload = [0; 5];
610        acquisition_count.write_to_slice(&mut payload[0..1]);
611        enable_quick_termination.write_to_slice(&mut payload[1..2]);
612        threshold_value.write_to_slice(&mut payload[2..3]);
613        measurement_frequency.write_to_slice(&mut payload[3..5]);
614
615        #[allow(unused_variables)]
616        let result = self.device.set(u8::from(LaserRangeFinderV2BrickletFunction::SetConfiguration), &payload).await?;
617        Ok(())
618    }
619
620    /// Returns the configuration as set by [`set_configuration`].
621    pub async fn get_configuration(&mut self) -> Result<Configuration, TinkerforgeError> {
622        let payload = [0; 0];
623
624        #[allow(unused_variables)]
625        let result = self.device.get(u8::from(LaserRangeFinderV2BrickletFunction::GetConfiguration), &payload).await?;
626        Ok(Configuration::from_le_byte_slice(result.body()))
627    }
628
629    /// Sets the length of a [moving averaging](https://en.wikipedia.org/wiki/Moving_average)__
630    /// for the distance and velocity.
631    ///
632    /// Setting the length to 0 will turn the averaging completely off. With less
633    /// averaging, there is more noise on the data.
634    pub async fn set_moving_average(&mut self, distance_average_length: u8, velocity_average_length: u8) -> Result<(), TinkerforgeError> {
635        let mut payload = [0; 2];
636        distance_average_length.write_to_slice(&mut payload[0..1]);
637        velocity_average_length.write_to_slice(&mut payload[1..2]);
638
639        #[allow(unused_variables)]
640        let result = self.device.set(u8::from(LaserRangeFinderV2BrickletFunction::SetMovingAverage), &payload).await?;
641        Ok(())
642    }
643
644    /// Returns the length moving average as set by [`set_moving_average`].
645    pub async fn get_moving_average(&mut self) -> Result<MovingAverage, TinkerforgeError> {
646        let payload = [0; 0];
647
648        #[allow(unused_variables)]
649        let result = self.device.get(u8::from(LaserRangeFinderV2BrickletFunction::GetMovingAverage), &payload).await?;
650        Ok(MovingAverage::from_le_byte_slice(result.body()))
651    }
652
653    /// The offset is added to the measured distance.
654    /// It is saved in non-volatile memory, you only have to set it once.
655    ///
656    /// The Bricklet comes with a per-sensor factory-calibrated offset value,
657    /// you should not have to call this function.
658    ///
659    /// If you want to re-calibrate the offset you first have to set it to 0.
660    /// Calculate the offset by measuring the distance to a known distance
661    /// and set it again.
662    pub async fn set_offset_calibration(&mut self, offset: i16) -> Result<(), TinkerforgeError> {
663        let mut payload = [0; 2];
664        offset.write_to_slice(&mut payload[0..2]);
665
666        #[allow(unused_variables)]
667        let result = self.device.set(u8::from(LaserRangeFinderV2BrickletFunction::SetOffsetCalibration), &payload).await?;
668        Ok(())
669    }
670
671    /// Returns the offset value as set by [`set_offset_calibration`].
672    pub async fn get_offset_calibration(&mut self) -> Result<i16, TinkerforgeError> {
673        let payload = [0; 0];
674
675        #[allow(unused_variables)]
676        let result = self.device.get(u8::from(LaserRangeFinderV2BrickletFunction::GetOffsetCalibration), &payload).await?;
677        Ok(i16::from_le_byte_slice(result.body()))
678    }
679
680    /// Configures the distance LED to be either turned off, turned on, blink in
681    /// heartbeat mode or show the distance (brighter = object is nearer).
682    ///
683    /// Associated constants:
684    /// * LASER_RANGE_FINDER_V2_BRICKLET_DISTANCE_LED_CONFIG_OFF
685    ///	* LASER_RANGE_FINDER_V2_BRICKLET_DISTANCE_LED_CONFIG_ON
686    ///	* LASER_RANGE_FINDER_V2_BRICKLET_DISTANCE_LED_CONFIG_SHOW_HEARTBEAT
687    ///	* LASER_RANGE_FINDER_V2_BRICKLET_DISTANCE_LED_CONFIG_SHOW_DISTANCE
688    pub async fn set_distance_led_config(&mut self, config: u8) -> Result<(), TinkerforgeError> {
689        let mut payload = [0; 1];
690        config.write_to_slice(&mut payload[0..1]);
691
692        #[allow(unused_variables)]
693        let result = self.device.set(u8::from(LaserRangeFinderV2BrickletFunction::SetDistanceLedConfig), &payload).await?;
694        Ok(())
695    }
696
697    /// Returns the LED configuration as set by [`set_distance_led_config`]
698    ///
699    /// Associated constants:
700    /// * LASER_RANGE_FINDER_V2_BRICKLET_DISTANCE_LED_CONFIG_OFF
701    ///	* LASER_RANGE_FINDER_V2_BRICKLET_DISTANCE_LED_CONFIG_ON
702    ///	* LASER_RANGE_FINDER_V2_BRICKLET_DISTANCE_LED_CONFIG_SHOW_HEARTBEAT
703    ///	* LASER_RANGE_FINDER_V2_BRICKLET_DISTANCE_LED_CONFIG_SHOW_DISTANCE
704    pub async fn get_distance_led_config(&mut self) -> Result<u8, TinkerforgeError> {
705        let payload = [0; 0];
706
707        #[allow(unused_variables)]
708        let result = self.device.get(u8::from(LaserRangeFinderV2BrickletFunction::GetDistanceLedConfig), &payload).await?;
709        Ok(u8::from_le_byte_slice(result.body()))
710    }
711
712    /// Returns the error count for the communication between Brick and Bricklet.
713    ///
714    /// The errors are divided into
715    ///
716    /// * ACK checksum errors,
717    /// * message checksum errors,
718    /// * framing errors and
719    /// * overflow errors.
720    ///
721    /// The errors counts are for errors that occur on the Bricklet side. All
722    /// Bricks have a similar function that returns the errors on the Brick side.
723    pub async fn get_spitfp_error_count(&mut self) -> Result<SpitfpErrorCount, TinkerforgeError> {
724        let payload = [0; 0];
725
726        #[allow(unused_variables)]
727        let result = self.device.get(u8::from(LaserRangeFinderV2BrickletFunction::GetSpitfpErrorCount), &payload).await?;
728        Ok(SpitfpErrorCount::from_le_byte_slice(result.body()))
729    }
730
731    /// Sets the bootloader mode and returns the status after the requested
732    /// mode change was instigated.
733    ///
734    /// You can change from bootloader mode to firmware mode and vice versa. A change
735    /// from bootloader mode to firmware mode will only take place if the entry function,
736    /// device identifier and CRC are present and correct.
737    ///
738    /// This function is used by Brick Viewer during flashing. It should not be
739    /// necessary to call it in a normal user program.
740    ///
741    /// Associated constants:
742    /// * LASER_RANGE_FINDER_V2_BRICKLET_BOOTLOADER_MODE_BOOTLOADER
743    ///	* LASER_RANGE_FINDER_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE
744    ///	* LASER_RANGE_FINDER_V2_BRICKLET_BOOTLOADER_MODE_BOOTLOADER_WAIT_FOR_REBOOT
745    ///	* LASER_RANGE_FINDER_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_REBOOT
746    ///	* LASER_RANGE_FINDER_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_ERASE_AND_REBOOT
747    ///	* LASER_RANGE_FINDER_V2_BRICKLET_BOOTLOADER_STATUS_OK
748    ///	* LASER_RANGE_FINDER_V2_BRICKLET_BOOTLOADER_STATUS_INVALID_MODE
749    ///	* LASER_RANGE_FINDER_V2_BRICKLET_BOOTLOADER_STATUS_NO_CHANGE
750    ///	* LASER_RANGE_FINDER_V2_BRICKLET_BOOTLOADER_STATUS_ENTRY_FUNCTION_NOT_PRESENT
751    ///	* LASER_RANGE_FINDER_V2_BRICKLET_BOOTLOADER_STATUS_DEVICE_IDENTIFIER_INCORRECT
752    ///	* LASER_RANGE_FINDER_V2_BRICKLET_BOOTLOADER_STATUS_CRC_MISMATCH
753    pub async fn set_bootloader_mode(&mut self, mode: u8) -> Result<u8, TinkerforgeError> {
754        let mut payload = [0; 1];
755        mode.write_to_slice(&mut payload[0..1]);
756
757        #[allow(unused_variables)]
758        let result = self.device.get(u8::from(LaserRangeFinderV2BrickletFunction::SetBootloaderMode), &payload).await?;
759        Ok(u8::from_le_byte_slice(result.body()))
760    }
761
762    /// Returns the current bootloader mode, see [`set_bootloader_mode`].
763    ///
764    /// Associated constants:
765    /// * LASER_RANGE_FINDER_V2_BRICKLET_BOOTLOADER_MODE_BOOTLOADER
766    ///	* LASER_RANGE_FINDER_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE
767    ///	* LASER_RANGE_FINDER_V2_BRICKLET_BOOTLOADER_MODE_BOOTLOADER_WAIT_FOR_REBOOT
768    ///	* LASER_RANGE_FINDER_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_REBOOT
769    ///	* LASER_RANGE_FINDER_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_ERASE_AND_REBOOT
770    pub async fn get_bootloader_mode(&mut self) -> Result<u8, TinkerforgeError> {
771        let payload = [0; 0];
772
773        #[allow(unused_variables)]
774        let result = self.device.get(u8::from(LaserRangeFinderV2BrickletFunction::GetBootloaderMode), &payload).await?;
775        Ok(u8::from_le_byte_slice(result.body()))
776    }
777
778    /// Sets the firmware pointer for [`write_firmware`]. The pointer has
779    /// to be increased by chunks of size 64. The data is written to flash
780    /// every 4 chunks (which equals to one page of size 256).
781    ///
782    /// This function is used by Brick Viewer during flashing. It should not be
783    /// necessary to call it in a normal user program.
784    pub async fn set_write_firmware_pointer(&mut self, pointer: u32) -> Result<(), TinkerforgeError> {
785        let mut payload = [0; 4];
786        pointer.write_to_slice(&mut payload[0..4]);
787
788        #[allow(unused_variables)]
789        let result = self.device.set(u8::from(LaserRangeFinderV2BrickletFunction::SetWriteFirmwarePointer), &payload).await?;
790        Ok(())
791    }
792
793    /// Writes 64 Bytes of firmware at the position as written by
794    /// [`set_write_firmware_pointer`] before. The firmware is written
795    /// to flash every 4 chunks.
796    ///
797    /// You can only write firmware in bootloader mode.
798    ///
799    /// This function is used by Brick Viewer during flashing. It should not be
800    /// necessary to call it in a normal user program.
801    pub async fn write_firmware(&mut self, data: &[u8; 64]) -> Result<u8, TinkerforgeError> {
802        let mut payload = [0; 64];
803        data.write_to_slice(&mut payload[0..64]);
804
805        #[allow(unused_variables)]
806        let result = self.device.get(u8::from(LaserRangeFinderV2BrickletFunction::WriteFirmware), &payload).await?;
807        Ok(u8::from_le_byte_slice(result.body()))
808    }
809
810    /// Sets the status LED configuration. By default the LED shows
811    /// communication traffic between Brick and Bricklet, it flickers once
812    /// for every 10 received data packets.
813    ///
814    /// You can also turn the LED permanently on/off or show a heartbeat.
815    ///
816    /// If the Bricklet is in bootloader mode, the LED is will show heartbeat by default.
817    ///
818    /// Associated constants:
819    /// * LASER_RANGE_FINDER_V2_BRICKLET_STATUS_LED_CONFIG_OFF
820    ///	* LASER_RANGE_FINDER_V2_BRICKLET_STATUS_LED_CONFIG_ON
821    ///	* LASER_RANGE_FINDER_V2_BRICKLET_STATUS_LED_CONFIG_SHOW_HEARTBEAT
822    ///	* LASER_RANGE_FINDER_V2_BRICKLET_STATUS_LED_CONFIG_SHOW_STATUS
823    pub async fn set_status_led_config(&mut self, config: u8) -> Result<(), TinkerforgeError> {
824        let mut payload = [0; 1];
825        config.write_to_slice(&mut payload[0..1]);
826
827        #[allow(unused_variables)]
828        let result = self.device.set(u8::from(LaserRangeFinderV2BrickletFunction::SetStatusLedConfig), &payload).await?;
829        Ok(())
830    }
831
832    /// Returns the configuration as set by [`set_status_led_config`]
833    ///
834    /// Associated constants:
835    /// * LASER_RANGE_FINDER_V2_BRICKLET_STATUS_LED_CONFIG_OFF
836    ///	* LASER_RANGE_FINDER_V2_BRICKLET_STATUS_LED_CONFIG_ON
837    ///	* LASER_RANGE_FINDER_V2_BRICKLET_STATUS_LED_CONFIG_SHOW_HEARTBEAT
838    ///	* LASER_RANGE_FINDER_V2_BRICKLET_STATUS_LED_CONFIG_SHOW_STATUS
839    pub async fn get_status_led_config(&mut self) -> Result<u8, TinkerforgeError> {
840        let payload = [0; 0];
841
842        #[allow(unused_variables)]
843        let result = self.device.get(u8::from(LaserRangeFinderV2BrickletFunction::GetStatusLedConfig), &payload).await?;
844        Ok(u8::from_le_byte_slice(result.body()))
845    }
846
847    /// Returns the temperature as measured inside the microcontroller. The
848    /// value returned is not the ambient temperature!
849    ///
850    /// The temperature is only proportional to the real temperature and it has bad
851    /// accuracy. Practically it is only useful as an indicator for
852    /// temperature changes.
853    pub async fn get_chip_temperature(&mut self) -> Result<i16, TinkerforgeError> {
854        let payload = [0; 0];
855
856        #[allow(unused_variables)]
857        let result = self.device.get(u8::from(LaserRangeFinderV2BrickletFunction::GetChipTemperature), &payload).await?;
858        Ok(i16::from_le_byte_slice(result.body()))
859    }
860
861    /// Calling this function will reset the Bricklet. All configurations
862    /// will be lost.
863    ///
864    /// After a reset you have to create new device objects,
865    /// calling functions on the existing ones will result in
866    /// undefined behavior!
867    pub async fn reset(&mut self) -> Result<(), TinkerforgeError> {
868        let payload = [0; 0];
869
870        #[allow(unused_variables)]
871        let result = self.device.set(u8::from(LaserRangeFinderV2BrickletFunction::Reset), &payload).await?;
872        Ok(())
873    }
874
875    /// Writes a new UID into flash. If you want to set a new UID
876    /// you have to decode the Base58 encoded UID string into an
877    /// integer first.
878    ///
879    /// We recommend that you use Brick Viewer to change the UID.
880    pub async fn write_uid(&mut self, uid: u32) -> Result<(), TinkerforgeError> {
881        let mut payload = [0; 4];
882        uid.write_to_slice(&mut payload[0..4]);
883
884        #[allow(unused_variables)]
885        let result = self.device.set(u8::from(LaserRangeFinderV2BrickletFunction::WriteUid), &payload).await?;
886        Ok(())
887    }
888
889    /// Returns the current UID as an integer. Encode as
890    /// Base58 to get the usual string version.
891    pub async fn read_uid(&mut self) -> Result<u32, TinkerforgeError> {
892        let payload = [0; 0];
893
894        #[allow(unused_variables)]
895        let result = self.device.get(u8::from(LaserRangeFinderV2BrickletFunction::ReadUid), &payload).await?;
896        Ok(u32::from_le_byte_slice(result.body()))
897    }
898
899    /// Returns the UID, the UID where the Bricklet is connected to,
900    /// the position, the hardware and firmware version as well as the
901    /// device identifier.
902    ///
903    /// The position can be 'a', 'b', 'c', 'd', 'e', 'f', 'g' or 'h' (Bricklet Port).
904    /// A Bricklet connected to an [Isolator Bricklet](isolator_bricklet) is always at
905    /// position 'z'.
906    ///
907    /// The device identifier numbers can be found [here](device_identifier).
908    /// |device_identifier_constant|
909    pub async fn get_identity(&mut self) -> Result<Identity, TinkerforgeError> {
910        let payload = [0; 0];
911
912        #[allow(unused_variables)]
913        let result = self.device.get(u8::from(LaserRangeFinderV2BrickletFunction::GetIdentity), &payload).await?;
914        Ok(Identity::from_le_byte_slice(result.body()))
915    }
916}