tinkerforge/bindings/
laser_range_finder_bricklet.rs

1/* ***********************************************************
2 * This file was automatically generated on 2024-02-27.      *
3 *                                                           *
4 * Rust Bindings Version 2.0.21                              *
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/LaserRangeFinder_Bricklet_Rust.html).
14use crate::{
15    byte_converter::*, converting_callback_receiver::ConvertingCallbackReceiver, converting_receiver::ConvertingReceiver, device::*,
16    ip_connection::GetRequestSender,
17};
18pub enum LaserRangeFinderBrickletFunction {
19    GetDistance,
20    GetVelocity,
21    SetDistanceCallbackPeriod,
22    GetDistanceCallbackPeriod,
23    SetVelocityCallbackPeriod,
24    GetVelocityCallbackPeriod,
25    SetDistanceCallbackThreshold,
26    GetDistanceCallbackThreshold,
27    SetVelocityCallbackThreshold,
28    GetVelocityCallbackThreshold,
29    SetDebouncePeriod,
30    GetDebouncePeriod,
31    SetMovingAverage,
32    GetMovingAverage,
33    SetMode,
34    GetMode,
35    EnableLaser,
36    DisableLaser,
37    IsLaserEnabled,
38    GetSensorHardwareVersion,
39    SetConfiguration,
40    GetConfiguration,
41    GetIdentity,
42    CallbackDistance,
43    CallbackVelocity,
44    CallbackDistanceReached,
45    CallbackVelocityReached,
46}
47impl From<LaserRangeFinderBrickletFunction> for u8 {
48    fn from(fun: LaserRangeFinderBrickletFunction) -> Self {
49        match fun {
50            LaserRangeFinderBrickletFunction::GetDistance => 1,
51            LaserRangeFinderBrickletFunction::GetVelocity => 2,
52            LaserRangeFinderBrickletFunction::SetDistanceCallbackPeriod => 3,
53            LaserRangeFinderBrickletFunction::GetDistanceCallbackPeriod => 4,
54            LaserRangeFinderBrickletFunction::SetVelocityCallbackPeriod => 5,
55            LaserRangeFinderBrickletFunction::GetVelocityCallbackPeriod => 6,
56            LaserRangeFinderBrickletFunction::SetDistanceCallbackThreshold => 7,
57            LaserRangeFinderBrickletFunction::GetDistanceCallbackThreshold => 8,
58            LaserRangeFinderBrickletFunction::SetVelocityCallbackThreshold => 9,
59            LaserRangeFinderBrickletFunction::GetVelocityCallbackThreshold => 10,
60            LaserRangeFinderBrickletFunction::SetDebouncePeriod => 11,
61            LaserRangeFinderBrickletFunction::GetDebouncePeriod => 12,
62            LaserRangeFinderBrickletFunction::SetMovingAverage => 13,
63            LaserRangeFinderBrickletFunction::GetMovingAverage => 14,
64            LaserRangeFinderBrickletFunction::SetMode => 15,
65            LaserRangeFinderBrickletFunction::GetMode => 16,
66            LaserRangeFinderBrickletFunction::EnableLaser => 17,
67            LaserRangeFinderBrickletFunction::DisableLaser => 18,
68            LaserRangeFinderBrickletFunction::IsLaserEnabled => 19,
69            LaserRangeFinderBrickletFunction::GetSensorHardwareVersion => 24,
70            LaserRangeFinderBrickletFunction::SetConfiguration => 25,
71            LaserRangeFinderBrickletFunction::GetConfiguration => 26,
72            LaserRangeFinderBrickletFunction::GetIdentity => 255,
73            LaserRangeFinderBrickletFunction::CallbackDistance => 20,
74            LaserRangeFinderBrickletFunction::CallbackVelocity => 21,
75            LaserRangeFinderBrickletFunction::CallbackDistanceReached => 22,
76            LaserRangeFinderBrickletFunction::CallbackVelocityReached => 23,
77        }
78    }
79}
80pub const LASER_RANGE_FINDER_BRICKLET_THRESHOLD_OPTION_OFF: char = 'x';
81pub const LASER_RANGE_FINDER_BRICKLET_THRESHOLD_OPTION_OUTSIDE: char = 'o';
82pub const LASER_RANGE_FINDER_BRICKLET_THRESHOLD_OPTION_INSIDE: char = 'i';
83pub const LASER_RANGE_FINDER_BRICKLET_THRESHOLD_OPTION_SMALLER: char = '<';
84pub const LASER_RANGE_FINDER_BRICKLET_THRESHOLD_OPTION_GREATER: char = '>';
85pub const LASER_RANGE_FINDER_BRICKLET_MODE_DISTANCE: u8 = 0;
86pub const LASER_RANGE_FINDER_BRICKLET_MODE_VELOCITY_MAX_13MS: u8 = 1;
87pub const LASER_RANGE_FINDER_BRICKLET_MODE_VELOCITY_MAX_32MS: u8 = 2;
88pub const LASER_RANGE_FINDER_BRICKLET_MODE_VELOCITY_MAX_64MS: u8 = 3;
89pub const LASER_RANGE_FINDER_BRICKLET_MODE_VELOCITY_MAX_127MS: u8 = 4;
90pub const LASER_RANGE_FINDER_BRICKLET_VERSION_1: u8 = 1;
91pub const LASER_RANGE_FINDER_BRICKLET_VERSION_3: u8 = 3;
92
93#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
94pub struct DistanceCallbackThreshold {
95    pub option: char,
96    pub min: u16,
97    pub max: u16,
98}
99impl FromByteSlice for DistanceCallbackThreshold {
100    fn bytes_expected() -> usize { 5 }
101    fn from_le_byte_slice(bytes: &[u8]) -> DistanceCallbackThreshold {
102        DistanceCallbackThreshold {
103            option: <char>::from_le_byte_slice(&bytes[0..1]),
104            min: <u16>::from_le_byte_slice(&bytes[1..3]),
105            max: <u16>::from_le_byte_slice(&bytes[3..5]),
106        }
107    }
108}
109
110#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
111pub struct VelocityCallbackThreshold {
112    pub option: char,
113    pub min: i16,
114    pub max: i16,
115}
116impl FromByteSlice for VelocityCallbackThreshold {
117    fn bytes_expected() -> usize { 5 }
118    fn from_le_byte_slice(bytes: &[u8]) -> VelocityCallbackThreshold {
119        VelocityCallbackThreshold {
120            option: <char>::from_le_byte_slice(&bytes[0..1]),
121            min: <i16>::from_le_byte_slice(&bytes[1..3]),
122            max: <i16>::from_le_byte_slice(&bytes[3..5]),
123        }
124    }
125}
126
127#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
128pub struct MovingAverage {
129    pub distance_average_length: u8,
130    pub velocity_average_length: u8,
131}
132impl FromByteSlice for MovingAverage {
133    fn bytes_expected() -> usize { 2 }
134    fn from_le_byte_slice(bytes: &[u8]) -> MovingAverage {
135        MovingAverage {
136            distance_average_length: <u8>::from_le_byte_slice(&bytes[0..1]),
137            velocity_average_length: <u8>::from_le_byte_slice(&bytes[1..2]),
138        }
139    }
140}
141
142#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
143pub struct Configuration {
144    pub acquisition_count: u8,
145    pub enable_quick_termination: bool,
146    pub threshold_value: u8,
147    pub measurement_frequency: u16,
148}
149impl FromByteSlice for Configuration {
150    fn bytes_expected() -> usize { 5 }
151    fn from_le_byte_slice(bytes: &[u8]) -> Configuration {
152        Configuration {
153            acquisition_count: <u8>::from_le_byte_slice(&bytes[0..1]),
154            enable_quick_termination: <bool>::from_le_byte_slice(&bytes[1..2]),
155            threshold_value: <u8>::from_le_byte_slice(&bytes[2..3]),
156            measurement_frequency: <u16>::from_le_byte_slice(&bytes[3..5]),
157        }
158    }
159}
160
161#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
162pub struct Identity {
163    pub uid: String,
164    pub connected_uid: String,
165    pub position: char,
166    pub hardware_version: [u8; 3],
167    pub firmware_version: [u8; 3],
168    pub device_identifier: u16,
169}
170impl FromByteSlice for Identity {
171    fn bytes_expected() -> usize { 25 }
172    fn from_le_byte_slice(bytes: &[u8]) -> Identity {
173        Identity {
174            uid: <String>::from_le_byte_slice(&bytes[0..8]),
175            connected_uid: <String>::from_le_byte_slice(&bytes[8..16]),
176            position: <char>::from_le_byte_slice(&bytes[16..17]),
177            hardware_version: <[u8; 3]>::from_le_byte_slice(&bytes[17..20]),
178            firmware_version: <[u8; 3]>::from_le_byte_slice(&bytes[20..23]),
179            device_identifier: <u16>::from_le_byte_slice(&bytes[23..25]),
180        }
181    }
182}
183
184/// Measures distance up to 40m with laser light
185#[derive(Clone)]
186pub struct LaserRangeFinderBricklet {
187    device: Device,
188}
189impl LaserRangeFinderBricklet {
190    pub const DEVICE_IDENTIFIER: u16 = 255;
191    pub const DEVICE_DISPLAY_NAME: &'static str = "Laser Range Finder Bricklet";
192    /// Creates an object with the unique device ID `uid`. This object can then be used after the IP Connection `ip_connection` is connected.
193    pub fn new<T: GetRequestSender>(uid: &str, req_sender: T) -> LaserRangeFinderBricklet {
194        let mut result = LaserRangeFinderBricklet { device: Device::new([2, 0, 1], uid, req_sender, 0) };
195        result.device.response_expected[u8::from(LaserRangeFinderBrickletFunction::GetDistance) as usize] =
196            ResponseExpectedFlag::AlwaysTrue;
197        result.device.response_expected[u8::from(LaserRangeFinderBrickletFunction::GetVelocity) as usize] =
198            ResponseExpectedFlag::AlwaysTrue;
199        result.device.response_expected[u8::from(LaserRangeFinderBrickletFunction::SetDistanceCallbackPeriod) as usize] =
200            ResponseExpectedFlag::True;
201        result.device.response_expected[u8::from(LaserRangeFinderBrickletFunction::GetDistanceCallbackPeriod) as usize] =
202            ResponseExpectedFlag::AlwaysTrue;
203        result.device.response_expected[u8::from(LaserRangeFinderBrickletFunction::SetVelocityCallbackPeriod) as usize] =
204            ResponseExpectedFlag::True;
205        result.device.response_expected[u8::from(LaserRangeFinderBrickletFunction::GetVelocityCallbackPeriod) as usize] =
206            ResponseExpectedFlag::AlwaysTrue;
207        result.device.response_expected[u8::from(LaserRangeFinderBrickletFunction::SetDistanceCallbackThreshold) as usize] =
208            ResponseExpectedFlag::True;
209        result.device.response_expected[u8::from(LaserRangeFinderBrickletFunction::GetDistanceCallbackThreshold) as usize] =
210            ResponseExpectedFlag::AlwaysTrue;
211        result.device.response_expected[u8::from(LaserRangeFinderBrickletFunction::SetVelocityCallbackThreshold) as usize] =
212            ResponseExpectedFlag::True;
213        result.device.response_expected[u8::from(LaserRangeFinderBrickletFunction::GetVelocityCallbackThreshold) as usize] =
214            ResponseExpectedFlag::AlwaysTrue;
215        result.device.response_expected[u8::from(LaserRangeFinderBrickletFunction::SetDebouncePeriod) as usize] =
216            ResponseExpectedFlag::True;
217        result.device.response_expected[u8::from(LaserRangeFinderBrickletFunction::GetDebouncePeriod) as usize] =
218            ResponseExpectedFlag::AlwaysTrue;
219        result.device.response_expected[u8::from(LaserRangeFinderBrickletFunction::SetMovingAverage) as usize] =
220            ResponseExpectedFlag::False;
221        result.device.response_expected[u8::from(LaserRangeFinderBrickletFunction::GetMovingAverage) as usize] =
222            ResponseExpectedFlag::AlwaysTrue;
223        result.device.response_expected[u8::from(LaserRangeFinderBrickletFunction::SetMode) as usize] = ResponseExpectedFlag::False;
224        result.device.response_expected[u8::from(LaserRangeFinderBrickletFunction::GetMode) as usize] = ResponseExpectedFlag::AlwaysTrue;
225        result.device.response_expected[u8::from(LaserRangeFinderBrickletFunction::EnableLaser) as usize] = ResponseExpectedFlag::False;
226        result.device.response_expected[u8::from(LaserRangeFinderBrickletFunction::DisableLaser) as usize] = ResponseExpectedFlag::False;
227        result.device.response_expected[u8::from(LaserRangeFinderBrickletFunction::IsLaserEnabled) as usize] =
228            ResponseExpectedFlag::AlwaysTrue;
229        result.device.response_expected[u8::from(LaserRangeFinderBrickletFunction::GetSensorHardwareVersion) as usize] =
230            ResponseExpectedFlag::AlwaysTrue;
231        result.device.response_expected[u8::from(LaserRangeFinderBrickletFunction::SetConfiguration) as usize] =
232            ResponseExpectedFlag::False;
233        result.device.response_expected[u8::from(LaserRangeFinderBrickletFunction::GetConfiguration) as usize] =
234            ResponseExpectedFlag::AlwaysTrue;
235        result.device.response_expected[u8::from(LaserRangeFinderBrickletFunction::GetIdentity) as usize] =
236            ResponseExpectedFlag::AlwaysTrue;
237        result
238    }
239
240    /// Returns the response expected flag for the function specified by the function ID parameter.
241    /// It is true if the function is expected to send a response, false otherwise.
242    ///
243    /// For getter functions this is enabled by default and cannot be disabled, because those
244    /// functions will always send a response. For callback configuration functions it is enabled
245    /// by default too, but can be disabled by [`set_response_expected`](crate::laser_range_finder_bricklet::LaserRangeFinderBricklet::set_response_expected).
246    /// For setter functions it is disabled by default and can be enabled.
247    ///
248    /// Enabling the response expected flag for a setter function allows to detect timeouts
249    /// and other error conditions calls of this setter as well. The device will then send a response
250    /// for this purpose. If this flag is disabled for a setter function then no response is sent
251    /// and errors are silently ignored, because they cannot be detected.
252    ///
253    /// See [`set_response_expected`](crate::laser_range_finder_bricklet::LaserRangeFinderBricklet::set_response_expected) for the list of function ID constants available for this function.
254    pub fn get_response_expected(&mut self, fun: LaserRangeFinderBrickletFunction) -> Result<bool, GetResponseExpectedError> {
255        self.device.get_response_expected(u8::from(fun))
256    }
257
258    /// Changes the response expected flag of the function specified by the function ID parameter.
259    /// This flag can only be changed for setter (default value: false) and callback configuration
260    /// functions (default value: true). For getter functions it is always enabled.
261    ///
262    /// Enabling the response expected flag for a setter function allows to detect timeouts and
263    /// other error conditions calls of this setter as well. The device will then send a response
264    /// for this purpose. If this flag is disabled for a setter function then no response is sent
265    /// and errors are silently ignored, because they cannot be detected.
266    pub fn set_response_expected(
267        &mut self,
268        fun: LaserRangeFinderBrickletFunction,
269        response_expected: bool,
270    ) -> Result<(), SetResponseExpectedError> {
271        self.device.set_response_expected(u8::from(fun), response_expected)
272    }
273
274    /// Changes the response expected flag for all setter and callback configuration functions of this device at once.
275    pub fn set_response_expected_all(&mut self, response_expected: bool) { self.device.set_response_expected_all(response_expected) }
276
277    /// Returns the version of the API definition (major, minor, revision) implemented by this API bindings.
278    /// This is neither the release version of this API bindings nor does it tell you anything about the represented Brick or Bricklet.
279    pub fn get_api_version(&self) -> [u8; 3] { self.device.api_version }
280
281    /// This receiver is triggered periodically with the period that is set by
282    /// [`set_distance_callback_period`]. The parameter is the distance
283    /// value of the sensor.
284    ///
285    /// The [`get_distance_callback_receiver`] receiver is only triggered if the distance value has changed
286    /// since the last triggering.
287    ///
288    /// [`set_distance_callback_period`]: #method.set_distance_callback_period
289    /// [`get_distance_callback_receiver`]: #method.get_distance_callback_receiver
290    pub fn get_distance_callback_receiver(&self) -> ConvertingCallbackReceiver<u16> {
291        self.device.get_callback_receiver(u8::from(LaserRangeFinderBrickletFunction::CallbackDistance))
292    }
293
294    /// This receiver is triggered periodically with the period that is set by
295    /// [`set_velocity_callback_period`]. The parameter is the velocity
296    /// value of the sensor.
297    ///
298    /// The [`get_velocity_callback_receiver`] receiver is only triggered if the velocity has changed since
299    /// the last triggering.
300    pub fn get_velocity_callback_receiver(&self) -> ConvertingCallbackReceiver<i16> {
301        self.device.get_callback_receiver(u8::from(LaserRangeFinderBrickletFunction::CallbackVelocity))
302    }
303
304    /// This receiver is triggered when the threshold as set by
305    /// [`set_distance_callback_threshold`] is reached.
306    /// The parameter is the distance value of the sensor.
307    ///
308    /// If the threshold keeps being reached, the receiver is triggered periodically
309    /// with the period as set by [`set_debounce_period`].
310    pub fn get_distance_reached_callback_receiver(&self) -> ConvertingCallbackReceiver<u16> {
311        self.device.get_callback_receiver(u8::from(LaserRangeFinderBrickletFunction::CallbackDistanceReached))
312    }
313
314    /// This receiver is triggered when the threshold as set by
315    /// [`set_velocity_callback_threshold`] is reached.
316    /// The parameter is the velocity value of the sensor.
317    ///
318    /// If the threshold keeps being reached, the receiver is triggered periodically
319    /// with the period as set by [`set_debounce_period`].
320    pub fn get_velocity_reached_callback_receiver(&self) -> ConvertingCallbackReceiver<i16> {
321        self.device.get_callback_receiver(u8::from(LaserRangeFinderBrickletFunction::CallbackVelocityReached))
322    }
323
324    /// Returns the measured distance.
325    ///
326    /// Sensor hardware version 1 (see [`get_sensor_hardware_version`]) cannot
327    /// measure distance and velocity at the same time. Therefore, the distance mode
328    /// has to be enabled using [`set_mode`].
329    /// Sensor hardware version 3 can measure distance and velocity at the same
330    /// time. Also the laser has to be enabled, see [`enable_laser`].
331    ///
332    /// If you want to get the distance periodically, it is recommended to
333    /// use the [`get_distance_callback_receiver`] receiver and set the period with
334    /// [`set_distance_callback_period`].
335    pub fn get_distance(&self) -> ConvertingReceiver<u16> {
336        let payload = vec![0; 0];
337
338        self.device.get(u8::from(LaserRangeFinderBrickletFunction::GetDistance), payload)
339    }
340
341    /// Returns the measured velocity.
342    ///
343    /// Sensor hardware version 1 (see [`get_sensor_hardware_version`]) cannot
344    /// measure distance and velocity at the same time. Therefore, the velocity mode
345    /// has to be enabled using [`set_mode`].
346    /// Sensor hardware version 3 can measure distance and velocity at the same
347    /// time, but the velocity measurement only produces stables results if a fixed
348    /// measurement rate (see [`set_configuration`]) is configured. Also the laser
349    /// has to be enabled, see [`enable_laser`].
350    ///
351    /// If you want to get the velocity periodically, it is recommended to
352    /// use the [`get_velocity_callback_receiver`] receiver and set the period with
353    /// [`set_velocity_callback_period`].
354    pub fn get_velocity(&self) -> ConvertingReceiver<i16> {
355        let payload = vec![0; 0];
356
357        self.device.get(u8::from(LaserRangeFinderBrickletFunction::GetVelocity), payload)
358    }
359
360    /// Sets the period with which the [`get_distance_callback_receiver`] receiver is triggered
361    /// periodically. A value of 0 turns the receiver off.
362    ///
363    /// The [`get_distance_callback_receiver`] receiver is only triggered if the distance value has
364    /// changed since the last triggering.
365    pub fn set_distance_callback_period(&self, period: u32) -> ConvertingReceiver<()> {
366        let mut payload = vec![0; 4];
367        payload[0..4].copy_from_slice(&<u32>::to_le_byte_vec(period));
368
369        self.device.set(u8::from(LaserRangeFinderBrickletFunction::SetDistanceCallbackPeriod), payload)
370    }
371
372    /// Returns the period as set by [`set_distance_callback_period`].
373    pub fn get_distance_callback_period(&self) -> ConvertingReceiver<u32> {
374        let payload = vec![0; 0];
375
376        self.device.get(u8::from(LaserRangeFinderBrickletFunction::GetDistanceCallbackPeriod), payload)
377    }
378
379    /// Sets the period with which the [`get_velocity_callback_receiver`] receiver is triggered
380    /// periodically. A value of 0 turns the receiver off.
381    ///
382    /// The [`get_velocity_callback_receiver`] receiver is only triggered if the velocity value has
383    /// changed since the last triggering.
384    pub fn set_velocity_callback_period(&self, period: u32) -> ConvertingReceiver<()> {
385        let mut payload = vec![0; 4];
386        payload[0..4].copy_from_slice(&<u32>::to_le_byte_vec(period));
387
388        self.device.set(u8::from(LaserRangeFinderBrickletFunction::SetVelocityCallbackPeriod), payload)
389    }
390
391    /// Returns the period as set by [`set_velocity_callback_period`].
392    pub fn get_velocity_callback_period(&self) -> ConvertingReceiver<u32> {
393        let payload = vec![0; 0];
394
395        self.device.get(u8::from(LaserRangeFinderBrickletFunction::GetVelocityCallbackPeriod), payload)
396    }
397
398    /// Sets the thresholds for the [`get_distance_reached_callback_receiver`] receiver.
399    ///
400    /// The following options are possible:
401    ///
402    ///  Option| Description
403    ///  --- | ---
404    ///  'x'|    Receiver is turned off
405    ///  'o'|    Receiver is triggered when the distance value is *outside* the min and max values
406    ///  'i'|    Receiver is triggered when the distance value is *inside* the min and max values
407    ///  '<'|    Receiver is triggered when the distance value is smaller than the min value (max is ignored)
408    ///  '>'|    Receiver is triggered when the distance value is greater than the min value (max is ignored)
409    ///
410    /// Associated constants:
411    /// * LASER_RANGE_FINDER_BRICKLET_THRESHOLD_OPTION_OFF
412    ///	* LASER_RANGE_FINDER_BRICKLET_THRESHOLD_OPTION_OUTSIDE
413    ///	* LASER_RANGE_FINDER_BRICKLET_THRESHOLD_OPTION_INSIDE
414    ///	* LASER_RANGE_FINDER_BRICKLET_THRESHOLD_OPTION_SMALLER
415    ///	* LASER_RANGE_FINDER_BRICKLET_THRESHOLD_OPTION_GREATER
416    pub fn set_distance_callback_threshold(&self, option: char, min: u16, max: u16) -> ConvertingReceiver<()> {
417        let mut payload = vec![0; 5];
418        payload[0..1].copy_from_slice(&<char>::to_le_byte_vec(option));
419        payload[1..3].copy_from_slice(&<u16>::to_le_byte_vec(min));
420        payload[3..5].copy_from_slice(&<u16>::to_le_byte_vec(max));
421
422        self.device.set(u8::from(LaserRangeFinderBrickletFunction::SetDistanceCallbackThreshold), payload)
423    }
424
425    /// Returns the threshold as set by [`set_distance_callback_threshold`].
426    ///
427    /// Associated constants:
428    /// * LASER_RANGE_FINDER_BRICKLET_THRESHOLD_OPTION_OFF
429    ///	* LASER_RANGE_FINDER_BRICKLET_THRESHOLD_OPTION_OUTSIDE
430    ///	* LASER_RANGE_FINDER_BRICKLET_THRESHOLD_OPTION_INSIDE
431    ///	* LASER_RANGE_FINDER_BRICKLET_THRESHOLD_OPTION_SMALLER
432    ///	* LASER_RANGE_FINDER_BRICKLET_THRESHOLD_OPTION_GREATER
433    pub fn get_distance_callback_threshold(&self) -> ConvertingReceiver<DistanceCallbackThreshold> {
434        let payload = vec![0; 0];
435
436        self.device.get(u8::from(LaserRangeFinderBrickletFunction::GetDistanceCallbackThreshold), payload)
437    }
438
439    /// Sets the thresholds for the [`get_velocity_reached_callback_receiver`] receiver.
440    ///
441    /// The following options are possible:
442    ///
443    ///  Option| Description
444    ///  --- | ---
445    ///  'x'|    Receiver is turned off
446    ///  'o'|    Receiver is triggered when the velocity is *outside* the min and max values
447    ///  'i'|    Receiver is triggered when the velocity is *inside* the min and max values
448    ///  '<'|    Receiver is triggered when the velocity is smaller than the min value (max is ignored)
449    ///  '>'|    Receiver is triggered when the velocity is greater than the min value (max is ignored)
450    ///
451    /// Associated constants:
452    /// * LASER_RANGE_FINDER_BRICKLET_THRESHOLD_OPTION_OFF
453    ///	* LASER_RANGE_FINDER_BRICKLET_THRESHOLD_OPTION_OUTSIDE
454    ///	* LASER_RANGE_FINDER_BRICKLET_THRESHOLD_OPTION_INSIDE
455    ///	* LASER_RANGE_FINDER_BRICKLET_THRESHOLD_OPTION_SMALLER
456    ///	* LASER_RANGE_FINDER_BRICKLET_THRESHOLD_OPTION_GREATER
457    pub fn set_velocity_callback_threshold(&self, option: char, min: i16, max: i16) -> ConvertingReceiver<()> {
458        let mut payload = vec![0; 5];
459        payload[0..1].copy_from_slice(&<char>::to_le_byte_vec(option));
460        payload[1..3].copy_from_slice(&<i16>::to_le_byte_vec(min));
461        payload[3..5].copy_from_slice(&<i16>::to_le_byte_vec(max));
462
463        self.device.set(u8::from(LaserRangeFinderBrickletFunction::SetVelocityCallbackThreshold), payload)
464    }
465
466    /// Returns the threshold as set by [`set_velocity_callback_threshold`].
467    ///
468    /// Associated constants:
469    /// * LASER_RANGE_FINDER_BRICKLET_THRESHOLD_OPTION_OFF
470    ///	* LASER_RANGE_FINDER_BRICKLET_THRESHOLD_OPTION_OUTSIDE
471    ///	* LASER_RANGE_FINDER_BRICKLET_THRESHOLD_OPTION_INSIDE
472    ///	* LASER_RANGE_FINDER_BRICKLET_THRESHOLD_OPTION_SMALLER
473    ///	* LASER_RANGE_FINDER_BRICKLET_THRESHOLD_OPTION_GREATER
474    pub fn get_velocity_callback_threshold(&self) -> ConvertingReceiver<VelocityCallbackThreshold> {
475        let payload = vec![0; 0];
476
477        self.device.get(u8::from(LaserRangeFinderBrickletFunction::GetVelocityCallbackThreshold), payload)
478    }
479
480    /// Sets the period with which the threshold receivers
481    ///
482    /// * [`get_distance_reached_callback_receiver`],
483    /// * [`get_velocity_reached_callback_receiver`],
484    ///
485    /// are triggered, if the thresholds
486    ///
487    /// * [`set_distance_callback_threshold`],
488    /// * [`set_velocity_callback_threshold`],
489    ///
490    /// keep being reached.
491    pub fn set_debounce_period(&self, debounce: u32) -> ConvertingReceiver<()> {
492        let mut payload = vec![0; 4];
493        payload[0..4].copy_from_slice(&<u32>::to_le_byte_vec(debounce));
494
495        self.device.set(u8::from(LaserRangeFinderBrickletFunction::SetDebouncePeriod), payload)
496    }
497
498    /// Returns the debounce period as set by [`set_debounce_period`].
499    pub fn get_debounce_period(&self) -> ConvertingReceiver<u32> {
500        let payload = vec![0; 0];
501
502        self.device.get(u8::from(LaserRangeFinderBrickletFunction::GetDebouncePeriod), payload)
503    }
504
505    /// Sets the length of a [moving averaging](https://en.wikipedia.org/wiki/Moving_average)__
506    /// for the distance and velocity.
507    ///
508    /// Setting the length to 0 will turn the averaging completely off. With less
509    /// averaging, there is more noise on the data.
510    pub fn set_moving_average(&self, distance_average_length: u8, velocity_average_length: u8) -> ConvertingReceiver<()> {
511        let mut payload = vec![0; 2];
512        payload[0..1].copy_from_slice(&<u8>::to_le_byte_vec(distance_average_length));
513        payload[1..2].copy_from_slice(&<u8>::to_le_byte_vec(velocity_average_length));
514
515        self.device.set(u8::from(LaserRangeFinderBrickletFunction::SetMovingAverage), payload)
516    }
517
518    /// Returns the length moving average as set by [`set_moving_average`].
519    pub fn get_moving_average(&self) -> ConvertingReceiver<MovingAverage> {
520        let payload = vec![0; 0];
521
522        self.device.get(u8::from(LaserRangeFinderBrickletFunction::GetMovingAverage), payload)
523    }
524
525    /// # Note
526    ///  This function is only available if you have a LIDAR-Lite sensor with hardware
527    ///  version 1. Use [`set_configuration`] for hardware version 3. You can check
528    ///  the sensor hardware version using [`get_sensor_hardware_version`].
529    ///
530    /// The LIDAR-Lite sensor (hardware version 1) has five different modes. One mode is
531    /// for distance measurements and four modes are for velocity measurements with
532    /// different ranges.
533    ///
534    /// The following modes are available:
535    ///
536    /// * 0: Distance is measured with resolution 1.0 cm and range 0-4000 cm
537    /// * 1: Velocity is measured with resolution 0.1 m/s and range is 0-12.7 m/s
538    /// * 2: Velocity is measured with resolution 0.25 m/s and range is 0-31.75 m/s
539    /// * 3: Velocity is measured with resolution 0.5 m/s and range is 0-63.5 m/s
540    /// * 4: Velocity is measured with resolution 1.0 m/s and range is 0-127 m/s
541    ///
542    /// Associated constants:
543    /// * LASER_RANGE_FINDER_BRICKLET_MODE_DISTANCE
544    ///	* LASER_RANGE_FINDER_BRICKLET_MODE_VELOCITY_MAX_13MS
545    ///	* LASER_RANGE_FINDER_BRICKLET_MODE_VELOCITY_MAX_32MS
546    ///	* LASER_RANGE_FINDER_BRICKLET_MODE_VELOCITY_MAX_64MS
547    ///	* LASER_RANGE_FINDER_BRICKLET_MODE_VELOCITY_MAX_127MS
548    pub fn set_mode(&self, mode: u8) -> ConvertingReceiver<()> {
549        let mut payload = vec![0; 1];
550        payload[0..1].copy_from_slice(&<u8>::to_le_byte_vec(mode));
551
552        self.device.set(u8::from(LaserRangeFinderBrickletFunction::SetMode), payload)
553    }
554
555    /// Returns the mode as set by [`set_mode`].
556    ///
557    /// Associated constants:
558    /// * LASER_RANGE_FINDER_BRICKLET_MODE_DISTANCE
559    ///	* LASER_RANGE_FINDER_BRICKLET_MODE_VELOCITY_MAX_13MS
560    ///	* LASER_RANGE_FINDER_BRICKLET_MODE_VELOCITY_MAX_32MS
561    ///	* LASER_RANGE_FINDER_BRICKLET_MODE_VELOCITY_MAX_64MS
562    ///	* LASER_RANGE_FINDER_BRICKLET_MODE_VELOCITY_MAX_127MS
563    pub fn get_mode(&self) -> ConvertingReceiver<u8> {
564        let payload = vec![0; 0];
565
566        self.device.get(u8::from(LaserRangeFinderBrickletFunction::GetMode), payload)
567    }
568
569    /// Activates the laser of the LIDAR.
570    ///
571    /// We recommend that you wait 250ms after enabling the laser before
572    /// the first call of [`get_distance`] to ensure stable measurements.
573    pub fn enable_laser(&self) -> ConvertingReceiver<()> {
574        let payload = vec![0; 0];
575
576        self.device.set(u8::from(LaserRangeFinderBrickletFunction::EnableLaser), payload)
577    }
578
579    /// Deactivates the laser of the LIDAR.
580    pub fn disable_laser(&self) -> ConvertingReceiver<()> {
581        let payload = vec![0; 0];
582
583        self.device.set(u8::from(LaserRangeFinderBrickletFunction::DisableLaser), payload)
584    }
585
586    /// Returns *true* if the laser is enabled, *false* otherwise.
587    pub fn is_laser_enabled(&self) -> ConvertingReceiver<bool> {
588        let payload = vec![0; 0];
589
590        self.device.get(u8::from(LaserRangeFinderBrickletFunction::IsLaserEnabled), payload)
591    }
592
593    /// Returns the LIDAR-Lite hardware version.
594    ///
595    ///
596    /// .. versionadded:: 2.0.3$nbsp;(Plugin)
597    ///
598    /// Associated constants:
599    /// * LASER_RANGE_FINDER_BRICKLET_VERSION_1
600    ///	* LASER_RANGE_FINDER_BRICKLET_VERSION_3
601    pub fn get_sensor_hardware_version(&self) -> ConvertingReceiver<u8> {
602        let payload = vec![0; 0];
603
604        self.device.get(u8::from(LaserRangeFinderBrickletFunction::GetSensorHardwareVersion), payload)
605    }
606
607    /// # Note
608    ///  This function is only available if you have a LIDAR-Lite sensor with hardware
609    ///  version 3. Use [`set_mode`] for hardware version 1. You can check
610    ///  the sensor hardware version using [`get_sensor_hardware_version`].
611    ///
612    /// The **Acquisition Count** defines the number of times the Laser Range Finder Bricklet
613    /// will integrate acquisitions to find a correlation record peak. With a higher count,
614    /// the Bricklet can measure longer distances. With a lower count, the rate increases. The
615    /// allowed values are 1-255.
616    ///
617    /// If you set **Enable Quick Termination** to true, the distance measurement will be terminated
618    /// early if a high peak was already detected. This means that a higher measurement rate can be achieved
619    /// and long distances can be measured at the same time. However, the chance of false-positive
620    /// distance measurements increases.
621    ///
622    /// Normally the distance is calculated with a detection algorithm that uses peak value,
623    /// signal strength and noise. You can however also define a fixed **Threshold Value**.
624    /// Set this to a low value if you want to measure the distance to something that has
625    /// very little reflection (e.g. glass) and set it to a high value if you want to measure
626    /// the distance to something with a very high reflection (e.g. mirror). Set this to 0 to
627    /// use the default algorithm. The other allowed values are 1-255.
628    ///
629    /// Set the **Measurement Frequency** to force a fixed measurement rate. If set to 0,
630    /// the Laser Range Finder Bricklet will use the optimal frequency according to the other
631    /// configurations and the actual measured distance. Since the rate is not fixed in this case,
632    /// the velocity measurement is not stable. For a stable velocity measurement you should
633    /// set a fixed measurement frequency. The lower the frequency, the higher is the resolution
634    /// of the calculated velocity. The allowed values are 10Hz-500Hz (and 0 to turn the fixed
635    /// frequency off).
636    ///
637    ///
638    /// .. versionadded:: 2.0.3$nbsp;(Plugin)
639    pub fn set_configuration(
640        &self,
641        acquisition_count: u8,
642        enable_quick_termination: bool,
643        threshold_value: u8,
644        measurement_frequency: u16,
645    ) -> ConvertingReceiver<()> {
646        let mut payload = vec![0; 5];
647        payload[0..1].copy_from_slice(&<u8>::to_le_byte_vec(acquisition_count));
648        payload[1..2].copy_from_slice(&<bool>::to_le_byte_vec(enable_quick_termination));
649        payload[2..3].copy_from_slice(&<u8>::to_le_byte_vec(threshold_value));
650        payload[3..5].copy_from_slice(&<u16>::to_le_byte_vec(measurement_frequency));
651
652        self.device.set(u8::from(LaserRangeFinderBrickletFunction::SetConfiguration), payload)
653    }
654
655    /// Returns the configuration as set by [`set_configuration`].
656    ///
657    ///
658    /// .. versionadded:: 2.0.3$nbsp;(Plugin)
659    pub fn get_configuration(&self) -> ConvertingReceiver<Configuration> {
660        let payload = vec![0; 0];
661
662        self.device.get(u8::from(LaserRangeFinderBrickletFunction::GetConfiguration), payload)
663    }
664
665    /// Returns the UID, the UID where the Bricklet is connected to,
666    /// the position, the hardware and firmware version as well as the
667    /// device identifier.
668    ///
669    /// The position can be 'a', 'b', 'c', 'd', 'e', 'f', 'g' or 'h' (Bricklet Port).
670    /// A Bricklet connected to an [Isolator Bricklet](isolator_bricklet) is always at
671    /// position 'z'.
672    ///
673    /// The device identifier numbers can be found [here](device_identifier).
674    /// |device_identifier_constant|
675    pub fn get_identity(&self) -> ConvertingReceiver<Identity> {
676        let payload = vec![0; 0];
677
678        self.device.get(u8::from(LaserRangeFinderBrickletFunction::GetIdentity), payload)
679    }
680}