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 DcV2BrickletFunction {
24 SetEnabled,
25 GetEnabled,
26 SetVelocity,
27 GetVelocity,
28 GetCurrentVelocity,
29 SetMotion,
30 GetMotion,
31 FullBrake,
32 SetDriveMode,
33 GetDriveMode,
34 SetPwmFrequency,
35 GetPwmFrequency,
36 GetPowerStatistics,
37 SetErrorLedConfig,
38 GetErrorLedConfig,
39 SetEmergencyShutdownCallbackConfiguration,
40 GetEmergencyShutdownCallbackConfiguration,
41 SetVelocityReachedCallbackConfiguration,
42 GetVelocityReachedCallbackConfiguration,
43 SetCurrentVelocityCallbackConfiguration,
44 GetCurrentVelocityCallbackConfiguration,
45 GetSpitfpErrorCount,
46 SetBootloaderMode,
47 GetBootloaderMode,
48 SetWriteFirmwarePointer,
49 WriteFirmware,
50 SetStatusLedConfig,
51 GetStatusLedConfig,
52 GetChipTemperature,
53 Reset,
54 WriteUid,
55 ReadUid,
56 GetIdentity,
57 CallbackEmergencyShutdown,
58 CallbackVelocityReached,
59 CallbackCurrentVelocity,
60}
61impl From<DcV2BrickletFunction> for u8 {
62 fn from(fun: DcV2BrickletFunction) -> Self {
63 match fun {
64 DcV2BrickletFunction::SetEnabled => 1,
65 DcV2BrickletFunction::GetEnabled => 2,
66 DcV2BrickletFunction::SetVelocity => 3,
67 DcV2BrickletFunction::GetVelocity => 4,
68 DcV2BrickletFunction::GetCurrentVelocity => 5,
69 DcV2BrickletFunction::SetMotion => 6,
70 DcV2BrickletFunction::GetMotion => 7,
71 DcV2BrickletFunction::FullBrake => 8,
72 DcV2BrickletFunction::SetDriveMode => 9,
73 DcV2BrickletFunction::GetDriveMode => 10,
74 DcV2BrickletFunction::SetPwmFrequency => 11,
75 DcV2BrickletFunction::GetPwmFrequency => 12,
76 DcV2BrickletFunction::GetPowerStatistics => 13,
77 DcV2BrickletFunction::SetErrorLedConfig => 14,
78 DcV2BrickletFunction::GetErrorLedConfig => 15,
79 DcV2BrickletFunction::SetEmergencyShutdownCallbackConfiguration => 16,
80 DcV2BrickletFunction::GetEmergencyShutdownCallbackConfiguration => 17,
81 DcV2BrickletFunction::SetVelocityReachedCallbackConfiguration => 18,
82 DcV2BrickletFunction::GetVelocityReachedCallbackConfiguration => 19,
83 DcV2BrickletFunction::SetCurrentVelocityCallbackConfiguration => 20,
84 DcV2BrickletFunction::GetCurrentVelocityCallbackConfiguration => 21,
85 DcV2BrickletFunction::GetSpitfpErrorCount => 234,
86 DcV2BrickletFunction::SetBootloaderMode => 235,
87 DcV2BrickletFunction::GetBootloaderMode => 236,
88 DcV2BrickletFunction::SetWriteFirmwarePointer => 237,
89 DcV2BrickletFunction::WriteFirmware => 238,
90 DcV2BrickletFunction::SetStatusLedConfig => 239,
91 DcV2BrickletFunction::GetStatusLedConfig => 240,
92 DcV2BrickletFunction::GetChipTemperature => 242,
93 DcV2BrickletFunction::Reset => 243,
94 DcV2BrickletFunction::WriteUid => 248,
95 DcV2BrickletFunction::ReadUid => 249,
96 DcV2BrickletFunction::GetIdentity => 255,
97 DcV2BrickletFunction::CallbackEmergencyShutdown => 22,
98 DcV2BrickletFunction::CallbackVelocityReached => 23,
99 DcV2BrickletFunction::CallbackCurrentVelocity => 24,
100 }
101 }
102}
103pub const DC_V2_BRICKLET_DRIVE_MODE_DRIVE_BRAKE: u8 = 0;
104pub const DC_V2_BRICKLET_DRIVE_MODE_DRIVE_COAST: u8 = 1;
105pub const DC_V2_BRICKLET_ERROR_LED_CONFIG_OFF: u8 = 0;
106pub const DC_V2_BRICKLET_ERROR_LED_CONFIG_ON: u8 = 1;
107pub const DC_V2_BRICKLET_ERROR_LED_CONFIG_SHOW_HEARTBEAT: u8 = 2;
108pub const DC_V2_BRICKLET_ERROR_LED_CONFIG_SHOW_ERROR: u8 = 3;
109pub const DC_V2_BRICKLET_BOOTLOADER_MODE_BOOTLOADER: u8 = 0;
110pub const DC_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE: u8 = 1;
111pub const DC_V2_BRICKLET_BOOTLOADER_MODE_BOOTLOADER_WAIT_FOR_REBOOT: u8 = 2;
112pub const DC_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_REBOOT: u8 = 3;
113pub const DC_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_ERASE_AND_REBOOT: u8 = 4;
114pub const DC_V2_BRICKLET_BOOTLOADER_STATUS_OK: u8 = 0;
115pub const DC_V2_BRICKLET_BOOTLOADER_STATUS_INVALID_MODE: u8 = 1;
116pub const DC_V2_BRICKLET_BOOTLOADER_STATUS_NO_CHANGE: u8 = 2;
117pub const DC_V2_BRICKLET_BOOTLOADER_STATUS_ENTRY_FUNCTION_NOT_PRESENT: u8 = 3;
118pub const DC_V2_BRICKLET_BOOTLOADER_STATUS_DEVICE_IDENTIFIER_INCORRECT: u8 = 4;
119pub const DC_V2_BRICKLET_BOOTLOADER_STATUS_CRC_MISMATCH: u8 = 5;
120pub const DC_V2_BRICKLET_STATUS_LED_CONFIG_OFF: u8 = 0;
121pub const DC_V2_BRICKLET_STATUS_LED_CONFIG_ON: u8 = 1;
122pub const DC_V2_BRICKLET_STATUS_LED_CONFIG_SHOW_HEARTBEAT: u8 = 2;
123pub const DC_V2_BRICKLET_STATUS_LED_CONFIG_SHOW_STATUS: u8 = 3;
124
125#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
126pub struct Motion {
127 pub acceleration: u16,
128 pub deceleration: u16,
129}
130impl FromByteSlice for Motion {
131 fn bytes_expected() -> usize {
132 4
133 }
134 fn from_le_byte_slice(bytes: &[u8]) -> Motion {
135 Motion { acceleration: <u16>::from_le_byte_slice(&bytes[0..2]), deceleration: <u16>::from_le_byte_slice(&bytes[2..4]) }
136 }
137}
138
139#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
140pub struct PowerStatistics {
141 pub voltage: u16,
142 pub current: u16,
143}
144impl FromByteSlice for PowerStatistics {
145 fn bytes_expected() -> usize {
146 4
147 }
148 fn from_le_byte_slice(bytes: &[u8]) -> PowerStatistics {
149 PowerStatistics { voltage: <u16>::from_le_byte_slice(&bytes[0..2]), current: <u16>::from_le_byte_slice(&bytes[2..4]) }
150 }
151}
152
153#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
154pub struct CurrentVelocityCallbackConfiguration {
155 pub period: u32,
156 pub value_has_to_change: bool,
157}
158impl FromByteSlice for CurrentVelocityCallbackConfiguration {
159 fn bytes_expected() -> usize {
160 5
161 }
162 fn from_le_byte_slice(bytes: &[u8]) -> CurrentVelocityCallbackConfiguration {
163 CurrentVelocityCallbackConfiguration {
164 period: <u32>::from_le_byte_slice(&bytes[0..4]),
165 value_has_to_change: <bool>::from_le_byte_slice(&bytes[4..5]),
166 }
167 }
168}
169
170#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
171pub struct SpitfpErrorCount {
172 pub error_count_ack_checksum: u32,
173 pub error_count_message_checksum: u32,
174 pub error_count_frame: u32,
175 pub error_count_overflow: u32,
176}
177impl FromByteSlice for SpitfpErrorCount {
178 fn bytes_expected() -> usize {
179 16
180 }
181 fn from_le_byte_slice(bytes: &[u8]) -> SpitfpErrorCount {
182 SpitfpErrorCount {
183 error_count_ack_checksum: <u32>::from_le_byte_slice(&bytes[0..4]),
184 error_count_message_checksum: <u32>::from_le_byte_slice(&bytes[4..8]),
185 error_count_frame: <u32>::from_le_byte_slice(&bytes[8..12]),
186 error_count_overflow: <u32>::from_le_byte_slice(&bytes[12..16]),
187 }
188 }
189}
190
191#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
192pub struct Identity {
193 pub uid: String,
194 pub connected_uid: String,
195 pub position: char,
196 pub hardware_version: [u8; 3],
197 pub firmware_version: [u8; 3],
198 pub device_identifier: u16,
199}
200impl FromByteSlice for Identity {
201 fn bytes_expected() -> usize {
202 25
203 }
204 fn from_le_byte_slice(bytes: &[u8]) -> Identity {
205 Identity {
206 uid: <String>::from_le_byte_slice(&bytes[0..8]),
207 connected_uid: <String>::from_le_byte_slice(&bytes[8..16]),
208 position: <char>::from_le_byte_slice(&bytes[16..17]),
209 hardware_version: <[u8; 3]>::from_le_byte_slice(&bytes[17..20]),
210 firmware_version: <[u8; 3]>::from_le_byte_slice(&bytes[20..23]),
211 device_identifier: <u16>::from_le_byte_slice(&bytes[23..25]),
212 }
213 }
214}
215
216#[derive(Clone)]
218pub struct DcV2Bricklet {
219 device: Device,
220}
221impl DcV2Bricklet {
222 pub const DEVICE_IDENTIFIER: u16 = 2165;
223 pub const DEVICE_DISPLAY_NAME: &'static str = "DC Bricklet 2.0";
224 pub fn new(uid: Uid, connection: AsyncIpConnection) -> DcV2Bricklet {
226 let mut result = DcV2Bricklet { device: Device::new([2, 0, 10], uid, connection, Self::DEVICE_DISPLAY_NAME) };
227 result.device.response_expected[u8::from(DcV2BrickletFunction::SetEnabled) as usize] = ResponseExpectedFlag::False;
228 result.device.response_expected[u8::from(DcV2BrickletFunction::GetEnabled) as usize] = ResponseExpectedFlag::AlwaysTrue;
229 result.device.response_expected[u8::from(DcV2BrickletFunction::SetVelocity) as usize] = ResponseExpectedFlag::False;
230 result.device.response_expected[u8::from(DcV2BrickletFunction::GetVelocity) as usize] = ResponseExpectedFlag::AlwaysTrue;
231 result.device.response_expected[u8::from(DcV2BrickletFunction::GetCurrentVelocity) as usize] = ResponseExpectedFlag::AlwaysTrue;
232 result.device.response_expected[u8::from(DcV2BrickletFunction::SetMotion) as usize] = ResponseExpectedFlag::False;
233 result.device.response_expected[u8::from(DcV2BrickletFunction::GetMotion) as usize] = ResponseExpectedFlag::AlwaysTrue;
234 result.device.response_expected[u8::from(DcV2BrickletFunction::FullBrake) as usize] = ResponseExpectedFlag::False;
235 result.device.response_expected[u8::from(DcV2BrickletFunction::SetDriveMode) as usize] = ResponseExpectedFlag::False;
236 result.device.response_expected[u8::from(DcV2BrickletFunction::GetDriveMode) as usize] = ResponseExpectedFlag::AlwaysTrue;
237 result.device.response_expected[u8::from(DcV2BrickletFunction::SetPwmFrequency) as usize] = ResponseExpectedFlag::False;
238 result.device.response_expected[u8::from(DcV2BrickletFunction::GetPwmFrequency) as usize] = ResponseExpectedFlag::AlwaysTrue;
239 result.device.response_expected[u8::from(DcV2BrickletFunction::GetPowerStatistics) as usize] = ResponseExpectedFlag::AlwaysTrue;
240 result.device.response_expected[u8::from(DcV2BrickletFunction::SetErrorLedConfig) as usize] = ResponseExpectedFlag::False;
241 result.device.response_expected[u8::from(DcV2BrickletFunction::GetErrorLedConfig) as usize] = ResponseExpectedFlag::AlwaysTrue;
242 result.device.response_expected[u8::from(DcV2BrickletFunction::SetEmergencyShutdownCallbackConfiguration) as usize] =
243 ResponseExpectedFlag::True;
244 result.device.response_expected[u8::from(DcV2BrickletFunction::GetEmergencyShutdownCallbackConfiguration) as usize] =
245 ResponseExpectedFlag::AlwaysTrue;
246 result.device.response_expected[u8::from(DcV2BrickletFunction::SetVelocityReachedCallbackConfiguration) as usize] =
247 ResponseExpectedFlag::True;
248 result.device.response_expected[u8::from(DcV2BrickletFunction::GetVelocityReachedCallbackConfiguration) as usize] =
249 ResponseExpectedFlag::AlwaysTrue;
250 result.device.response_expected[u8::from(DcV2BrickletFunction::SetCurrentVelocityCallbackConfiguration) as usize] =
251 ResponseExpectedFlag::True;
252 result.device.response_expected[u8::from(DcV2BrickletFunction::GetCurrentVelocityCallbackConfiguration) as usize] =
253 ResponseExpectedFlag::AlwaysTrue;
254 result.device.response_expected[u8::from(DcV2BrickletFunction::GetSpitfpErrorCount) as usize] = ResponseExpectedFlag::AlwaysTrue;
255 result.device.response_expected[u8::from(DcV2BrickletFunction::SetBootloaderMode) as usize] = ResponseExpectedFlag::AlwaysTrue;
256 result.device.response_expected[u8::from(DcV2BrickletFunction::GetBootloaderMode) as usize] = ResponseExpectedFlag::AlwaysTrue;
257 result.device.response_expected[u8::from(DcV2BrickletFunction::SetWriteFirmwarePointer) as usize] = ResponseExpectedFlag::False;
258 result.device.response_expected[u8::from(DcV2BrickletFunction::WriteFirmware) as usize] = ResponseExpectedFlag::AlwaysTrue;
259 result.device.response_expected[u8::from(DcV2BrickletFunction::SetStatusLedConfig) as usize] = ResponseExpectedFlag::False;
260 result.device.response_expected[u8::from(DcV2BrickletFunction::GetStatusLedConfig) as usize] = ResponseExpectedFlag::AlwaysTrue;
261 result.device.response_expected[u8::from(DcV2BrickletFunction::GetChipTemperature) as usize] = ResponseExpectedFlag::AlwaysTrue;
262 result.device.response_expected[u8::from(DcV2BrickletFunction::Reset) as usize] = ResponseExpectedFlag::False;
263 result.device.response_expected[u8::from(DcV2BrickletFunction::WriteUid) as usize] = ResponseExpectedFlag::False;
264 result.device.response_expected[u8::from(DcV2BrickletFunction::ReadUid) as usize] = ResponseExpectedFlag::AlwaysTrue;
265 result.device.response_expected[u8::from(DcV2BrickletFunction::GetIdentity) as usize] = ResponseExpectedFlag::AlwaysTrue;
266 result
267 }
268
269 pub fn get_response_expected(&mut self, fun: DcV2BrickletFunction) -> Result<bool, GetResponseExpectedError> {
284 self.device.get_response_expected(u8::from(fun))
285 }
286
287 pub fn set_response_expected(&mut self, fun: DcV2BrickletFunction, response_expected: bool) -> Result<(), SetResponseExpectedError> {
296 self.device.set_response_expected(u8::from(fun), response_expected)
297 }
298
299 pub fn set_response_expected_all(&mut self, response_expected: bool) {
301 self.device.set_response_expected_all(response_expected)
302 }
303
304 pub fn get_api_version(&self) -> [u8; 3] {
307 self.device.api_version
308 }
309
310 pub async fn get_emergency_shutdown_callback_receiver(&mut self) -> impl Stream<Item = ()> {
328 self.device.get_callback_receiver(u8::from(DcV2BrickletFunction::CallbackEmergencyShutdown)).await.map(|_p| ())
329 }
330
331 pub async fn get_velocity_reached_callback_receiver(&mut self) -> impl Stream<Item = i16> {
342 self.device
343 .get_callback_receiver(u8::from(DcV2BrickletFunction::CallbackVelocityReached))
344 .await
345 .map(|p| i16::from_le_byte_slice(p.body()))
346 }
347
348 pub async fn get_current_velocity_callback_receiver(&mut self) -> impl Stream<Item = i16> {
355 self.device
356 .get_callback_receiver(u8::from(DcV2BrickletFunction::CallbackCurrentVelocity))
357 .await
358 .map(|p| i16::from_le_byte_slice(p.body()))
359 }
360
361 pub async fn set_enabled(&mut self, enabled: bool) -> Result<(), TinkerforgeError> {
364 let mut payload = [0; 1];
365 enabled.write_to_slice(&mut payload[0..1]);
366
367 #[allow(unused_variables)]
368 let result = self.device.set(u8::from(DcV2BrickletFunction::SetEnabled), &payload).await?;
369 Ok(())
370 }
371
372 pub async fn get_enabled(&mut self) -> Result<bool, TinkerforgeError> {
374 let payload = [0; 0];
375
376 #[allow(unused_variables)]
377 let result = self.device.get(u8::from(DcV2BrickletFunction::GetEnabled), &payload).await?;
378 Ok(bool::from_le_byte_slice(result.body()))
379 }
380
381 pub async fn set_velocity(&mut self, velocity: i16) -> Result<(), TinkerforgeError> {
391 let mut payload = [0; 2];
392 velocity.write_to_slice(&mut payload[0..2]);
393
394 #[allow(unused_variables)]
395 let result = self.device.set(u8::from(DcV2BrickletFunction::SetVelocity), &payload).await?;
396 Ok(())
397 }
398
399 pub async fn get_velocity(&mut self) -> Result<i16, TinkerforgeError> {
401 let payload = [0; 0];
402
403 #[allow(unused_variables)]
404 let result = self.device.get(u8::from(DcV2BrickletFunction::GetVelocity), &payload).await?;
405 Ok(i16::from_le_byte_slice(result.body()))
406 }
407
408 pub async fn get_current_velocity(&mut self) -> Result<i16, TinkerforgeError> {
412 let payload = [0; 0];
413
414 #[allow(unused_variables)]
415 let result = self.device.get(u8::from(DcV2BrickletFunction::GetCurrentVelocity), &payload).await?;
416 Ok(i16::from_le_byte_slice(result.body()))
417 }
418
419 pub async fn set_motion(&mut self, acceleration: u16, deceleration: u16) -> Result<(), TinkerforgeError> {
430 let mut payload = [0; 4];
431 acceleration.write_to_slice(&mut payload[0..2]);
432 deceleration.write_to_slice(&mut payload[2..4]);
433
434 #[allow(unused_variables)]
435 let result = self.device.set(u8::from(DcV2BrickletFunction::SetMotion), &payload).await?;
436 Ok(())
437 }
438
439 pub async fn get_motion(&mut self) -> Result<Motion, TinkerforgeError> {
441 let payload = [0; 0];
442
443 #[allow(unused_variables)]
444 let result = self.device.get(u8::from(DcV2BrickletFunction::GetMotion), &payload).await?;
445 Ok(Motion::from_le_byte_slice(result.body()))
446 }
447
448 pub async fn full_brake(&mut self) -> Result<(), TinkerforgeError> {
457 let payload = [0; 0];
458
459 #[allow(unused_variables)]
460 let result = self.device.set(u8::from(DcV2BrickletFunction::FullBrake), &payload).await?;
461 Ok(())
462 }
463
464 pub async fn set_drive_mode(&mut self, mode: u8) -> Result<(), TinkerforgeError> {
484 let mut payload = [0; 1];
485 mode.write_to_slice(&mut payload[0..1]);
486
487 #[allow(unused_variables)]
488 let result = self.device.set(u8::from(DcV2BrickletFunction::SetDriveMode), &payload).await?;
489 Ok(())
490 }
491
492 pub async fn get_drive_mode(&mut self) -> Result<u8, TinkerforgeError> {
498 let payload = [0; 0];
499
500 #[allow(unused_variables)]
501 let result = self.device.get(u8::from(DcV2BrickletFunction::GetDriveMode), &payload).await?;
502 Ok(u8::from_le_byte_slice(result.body()))
503 }
504
505 pub async fn set_pwm_frequency(&mut self, frequency: u16) -> Result<(), TinkerforgeError> {
514 let mut payload = [0; 2];
515 frequency.write_to_slice(&mut payload[0..2]);
516
517 #[allow(unused_variables)]
518 let result = self.device.set(u8::from(DcV2BrickletFunction::SetPwmFrequency), &payload).await?;
519 Ok(())
520 }
521
522 pub async fn get_pwm_frequency(&mut self) -> Result<u16, TinkerforgeError> {
524 let payload = [0; 0];
525
526 #[allow(unused_variables)]
527 let result = self.device.get(u8::from(DcV2BrickletFunction::GetPwmFrequency), &payload).await?;
528 Ok(u16::from_le_byte_slice(result.body()))
529 }
530
531 pub async fn get_power_statistics(&mut self) -> Result<PowerStatistics, TinkerforgeError> {
533 let payload = [0; 0];
534
535 #[allow(unused_variables)]
536 let result = self.device.get(u8::from(DcV2BrickletFunction::GetPowerStatistics), &payload).await?;
537 Ok(PowerStatistics::from_le_byte_slice(result.body()))
538 }
539
540 pub async fn set_error_led_config(&mut self, config: u8) -> Result<(), TinkerforgeError> {
555 let mut payload = [0; 1];
556 config.write_to_slice(&mut payload[0..1]);
557
558 #[allow(unused_variables)]
559 let result = self.device.set(u8::from(DcV2BrickletFunction::SetErrorLedConfig), &payload).await?;
560 Ok(())
561 }
562
563 pub async fn get_error_led_config(&mut self) -> Result<u8, TinkerforgeError> {
571 let payload = [0; 0];
572
573 #[allow(unused_variables)]
574 let result = self.device.get(u8::from(DcV2BrickletFunction::GetErrorLedConfig), &payload).await?;
575 Ok(u8::from_le_byte_slice(result.body()))
576 }
577
578 pub async fn set_emergency_shutdown_callback_configuration(&mut self, enabled: bool) -> Result<(), TinkerforgeError> {
580 let mut payload = [0; 1];
581 enabled.write_to_slice(&mut payload[0..1]);
582
583 #[allow(unused_variables)]
584 let result = self.device.set(u8::from(DcV2BrickletFunction::SetEmergencyShutdownCallbackConfiguration), &payload).await?;
585 Ok(())
586 }
587
588 pub async fn get_emergency_shutdown_callback_configuration(&mut self) -> Result<bool, TinkerforgeError> {
591 let payload = [0; 0];
592
593 #[allow(unused_variables)]
594 let result = self.device.get(u8::from(DcV2BrickletFunction::GetEmergencyShutdownCallbackConfiguration), &payload).await?;
595 Ok(bool::from_le_byte_slice(result.body()))
596 }
597
598 pub async fn set_velocity_reached_callback_configuration(&mut self, enabled: bool) -> Result<(), TinkerforgeError> {
600 let mut payload = [0; 1];
601 enabled.write_to_slice(&mut payload[0..1]);
602
603 #[allow(unused_variables)]
604 let result = self.device.set(u8::from(DcV2BrickletFunction::SetVelocityReachedCallbackConfiguration), &payload).await?;
605 Ok(())
606 }
607
608 pub async fn get_velocity_reached_callback_configuration(&mut self) -> Result<bool, TinkerforgeError> {
611 let payload = [0; 0];
612
613 #[allow(unused_variables)]
614 let result = self.device.get(u8::from(DcV2BrickletFunction::GetVelocityReachedCallbackConfiguration), &payload).await?;
615 Ok(bool::from_le_byte_slice(result.body()))
616 }
617
618 pub async fn set_current_velocity_callback_configuration(
628 &mut self,
629 period: u32,
630 value_has_to_change: bool,
631 ) -> Result<(), TinkerforgeError> {
632 let mut payload = [0; 5];
633 period.write_to_slice(&mut payload[0..4]);
634 value_has_to_change.write_to_slice(&mut payload[4..5]);
635
636 #[allow(unused_variables)]
637 let result = self.device.set(u8::from(DcV2BrickletFunction::SetCurrentVelocityCallbackConfiguration), &payload).await?;
638 Ok(())
639 }
640
641 pub async fn get_current_velocity_callback_configuration(&mut self) -> Result<CurrentVelocityCallbackConfiguration, TinkerforgeError> {
644 let payload = [0; 0];
645
646 #[allow(unused_variables)]
647 let result = self.device.get(u8::from(DcV2BrickletFunction::GetCurrentVelocityCallbackConfiguration), &payload).await?;
648 Ok(CurrentVelocityCallbackConfiguration::from_le_byte_slice(result.body()))
649 }
650
651 pub async fn get_spitfp_error_count(&mut self) -> Result<SpitfpErrorCount, TinkerforgeError> {
663 let payload = [0; 0];
664
665 #[allow(unused_variables)]
666 let result = self.device.get(u8::from(DcV2BrickletFunction::GetSpitfpErrorCount), &payload).await?;
667 Ok(SpitfpErrorCount::from_le_byte_slice(result.body()))
668 }
669
670 pub async fn set_bootloader_mode(&mut self, mode: u8) -> Result<u8, TinkerforgeError> {
693 let mut payload = [0; 1];
694 mode.write_to_slice(&mut payload[0..1]);
695
696 #[allow(unused_variables)]
697 let result = self.device.get(u8::from(DcV2BrickletFunction::SetBootloaderMode), &payload).await?;
698 Ok(u8::from_le_byte_slice(result.body()))
699 }
700
701 pub async fn get_bootloader_mode(&mut self) -> Result<u8, TinkerforgeError> {
710 let payload = [0; 0];
711
712 #[allow(unused_variables)]
713 let result = self.device.get(u8::from(DcV2BrickletFunction::GetBootloaderMode), &payload).await?;
714 Ok(u8::from_le_byte_slice(result.body()))
715 }
716
717 pub async fn set_write_firmware_pointer(&mut self, pointer: u32) -> Result<(), TinkerforgeError> {
724 let mut payload = [0; 4];
725 pointer.write_to_slice(&mut payload[0..4]);
726
727 #[allow(unused_variables)]
728 let result = self.device.set(u8::from(DcV2BrickletFunction::SetWriteFirmwarePointer), &payload).await?;
729 Ok(())
730 }
731
732 pub async fn write_firmware(&mut self, data: &[u8; 64]) -> Result<u8, TinkerforgeError> {
741 let mut payload = [0; 64];
742 data.write_to_slice(&mut payload[0..64]);
743
744 #[allow(unused_variables)]
745 let result = self.device.get(u8::from(DcV2BrickletFunction::WriteFirmware), &payload).await?;
746 Ok(u8::from_le_byte_slice(result.body()))
747 }
748
749 pub async fn set_status_led_config(&mut self, config: u8) -> Result<(), TinkerforgeError> {
763 let mut payload = [0; 1];
764 config.write_to_slice(&mut payload[0..1]);
765
766 #[allow(unused_variables)]
767 let result = self.device.set(u8::from(DcV2BrickletFunction::SetStatusLedConfig), &payload).await?;
768 Ok(())
769 }
770
771 pub async fn get_status_led_config(&mut self) -> Result<u8, TinkerforgeError> {
779 let payload = [0; 0];
780
781 #[allow(unused_variables)]
782 let result = self.device.get(u8::from(DcV2BrickletFunction::GetStatusLedConfig), &payload).await?;
783 Ok(u8::from_le_byte_slice(result.body()))
784 }
785
786 pub async fn get_chip_temperature(&mut self) -> Result<i16, TinkerforgeError> {
793 let payload = [0; 0];
794
795 #[allow(unused_variables)]
796 let result = self.device.get(u8::from(DcV2BrickletFunction::GetChipTemperature), &payload).await?;
797 Ok(i16::from_le_byte_slice(result.body()))
798 }
799
800 pub async fn reset(&mut self) -> Result<(), TinkerforgeError> {
807 let payload = [0; 0];
808
809 #[allow(unused_variables)]
810 let result = self.device.set(u8::from(DcV2BrickletFunction::Reset), &payload).await?;
811 Ok(())
812 }
813
814 pub async fn write_uid(&mut self, uid: u32) -> Result<(), TinkerforgeError> {
820 let mut payload = [0; 4];
821 uid.write_to_slice(&mut payload[0..4]);
822
823 #[allow(unused_variables)]
824 let result = self.device.set(u8::from(DcV2BrickletFunction::WriteUid), &payload).await?;
825 Ok(())
826 }
827
828 pub async fn read_uid(&mut self) -> Result<u32, TinkerforgeError> {
831 let payload = [0; 0];
832
833 #[allow(unused_variables)]
834 let result = self.device.get(u8::from(DcV2BrickletFunction::ReadUid), &payload).await?;
835 Ok(u32::from_le_byte_slice(result.body()))
836 }
837
838 pub async fn get_identity(&mut self) -> Result<Identity, TinkerforgeError> {
849 let payload = [0; 0];
850
851 #[allow(unused_variables)]
852 let result = self.device.get(u8::from(DcV2BrickletFunction::GetIdentity), &payload).await?;
853 Ok(Identity::from_le_byte_slice(result.body()))
854 }
855}