1#[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#[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 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 pub fn get_response_expected(&mut self, fun: LaserRangeFinderV2BrickletFunction) -> Result<bool, GetResponseExpectedError> {
327 self.device.get_response_expected(u8::from(fun))
328 }
329
330 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 pub fn set_response_expected_all(&mut self, response_expected: bool) {
348 self.device.set_response_expected_all(response_expected)
349 }
350
351 pub fn get_api_version(&self) -> [u8; 3] {
354 self.device.api_version
355 }
356
357 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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}