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 PerformanceDcBrickletFunction {
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 SetThermalShutdown,
38 GetThermalShutdown,
39 SetGpioConfiguration,
40 GetGpioConfiguration,
41 SetGpioAction,
42 GetGpioAction,
43 GetGpioState,
44 SetErrorLedConfig,
45 GetErrorLedConfig,
46 SetCwLedConfig,
47 GetCwLedConfig,
48 SetCcwLedConfig,
49 GetCcwLedConfig,
50 SetGpioLedConfig,
51 GetGpioLedConfig,
52 SetEmergencyShutdownCallbackConfiguration,
53 GetEmergencyShutdownCallbackConfiguration,
54 SetVelocityReachedCallbackConfiguration,
55 GetVelocityReachedCallbackConfiguration,
56 SetCurrentVelocityCallbackConfiguration,
57 GetCurrentVelocityCallbackConfiguration,
58 GetSpitfpErrorCount,
59 SetBootloaderMode,
60 GetBootloaderMode,
61 SetWriteFirmwarePointer,
62 WriteFirmware,
63 SetStatusLedConfig,
64 GetStatusLedConfig,
65 GetChipTemperature,
66 Reset,
67 WriteUid,
68 ReadUid,
69 GetIdentity,
70 CallbackEmergencyShutdown,
71 CallbackVelocityReached,
72 CallbackCurrentVelocity,
73 CallbackGpioState,
74}
75impl From<PerformanceDcBrickletFunction> for u8 {
76 fn from(fun: PerformanceDcBrickletFunction) -> Self {
77 match fun {
78 PerformanceDcBrickletFunction::SetEnabled => 1,
79 PerformanceDcBrickletFunction::GetEnabled => 2,
80 PerformanceDcBrickletFunction::SetVelocity => 3,
81 PerformanceDcBrickletFunction::GetVelocity => 4,
82 PerformanceDcBrickletFunction::GetCurrentVelocity => 5,
83 PerformanceDcBrickletFunction::SetMotion => 6,
84 PerformanceDcBrickletFunction::GetMotion => 7,
85 PerformanceDcBrickletFunction::FullBrake => 8,
86 PerformanceDcBrickletFunction::SetDriveMode => 9,
87 PerformanceDcBrickletFunction::GetDriveMode => 10,
88 PerformanceDcBrickletFunction::SetPwmFrequency => 11,
89 PerformanceDcBrickletFunction::GetPwmFrequency => 12,
90 PerformanceDcBrickletFunction::GetPowerStatistics => 13,
91 PerformanceDcBrickletFunction::SetThermalShutdown => 14,
92 PerformanceDcBrickletFunction::GetThermalShutdown => 15,
93 PerformanceDcBrickletFunction::SetGpioConfiguration => 16,
94 PerformanceDcBrickletFunction::GetGpioConfiguration => 17,
95 PerformanceDcBrickletFunction::SetGpioAction => 18,
96 PerformanceDcBrickletFunction::GetGpioAction => 19,
97 PerformanceDcBrickletFunction::GetGpioState => 20,
98 PerformanceDcBrickletFunction::SetErrorLedConfig => 21,
99 PerformanceDcBrickletFunction::GetErrorLedConfig => 22,
100 PerformanceDcBrickletFunction::SetCwLedConfig => 23,
101 PerformanceDcBrickletFunction::GetCwLedConfig => 24,
102 PerformanceDcBrickletFunction::SetCcwLedConfig => 25,
103 PerformanceDcBrickletFunction::GetCcwLedConfig => 26,
104 PerformanceDcBrickletFunction::SetGpioLedConfig => 27,
105 PerformanceDcBrickletFunction::GetGpioLedConfig => 28,
106 PerformanceDcBrickletFunction::SetEmergencyShutdownCallbackConfiguration => 29,
107 PerformanceDcBrickletFunction::GetEmergencyShutdownCallbackConfiguration => 30,
108 PerformanceDcBrickletFunction::SetVelocityReachedCallbackConfiguration => 31,
109 PerformanceDcBrickletFunction::GetVelocityReachedCallbackConfiguration => 32,
110 PerformanceDcBrickletFunction::SetCurrentVelocityCallbackConfiguration => 33,
111 PerformanceDcBrickletFunction::GetCurrentVelocityCallbackConfiguration => 34,
112 PerformanceDcBrickletFunction::GetSpitfpErrorCount => 234,
113 PerformanceDcBrickletFunction::SetBootloaderMode => 235,
114 PerformanceDcBrickletFunction::GetBootloaderMode => 236,
115 PerformanceDcBrickletFunction::SetWriteFirmwarePointer => 237,
116 PerformanceDcBrickletFunction::WriteFirmware => 238,
117 PerformanceDcBrickletFunction::SetStatusLedConfig => 239,
118 PerformanceDcBrickletFunction::GetStatusLedConfig => 240,
119 PerformanceDcBrickletFunction::GetChipTemperature => 242,
120 PerformanceDcBrickletFunction::Reset => 243,
121 PerformanceDcBrickletFunction::WriteUid => 248,
122 PerformanceDcBrickletFunction::ReadUid => 249,
123 PerformanceDcBrickletFunction::GetIdentity => 255,
124 PerformanceDcBrickletFunction::CallbackEmergencyShutdown => 35,
125 PerformanceDcBrickletFunction::CallbackVelocityReached => 36,
126 PerformanceDcBrickletFunction::CallbackCurrentVelocity => 37,
127 PerformanceDcBrickletFunction::CallbackGpioState => 38,
128 }
129 }
130}
131pub const PERFORMANCE_DC_BRICKLET_DRIVE_MODE_DRIVE_BRAKE: u8 = 0;
132pub const PERFORMANCE_DC_BRICKLET_DRIVE_MODE_DRIVE_COAST: u8 = 1;
133pub const PERFORMANCE_DC_BRICKLET_GPIO_ACTION_NONE: u32 = 0;
134pub const PERFORMANCE_DC_BRICKLET_GPIO_ACTION_NORMAL_STOP_RISING_EDGE: u32 = 1;
135pub const PERFORMANCE_DC_BRICKLET_GPIO_ACTION_NORMAL_STOP_FALLING_EDGE: u32 = 2;
136pub const PERFORMANCE_DC_BRICKLET_GPIO_ACTION_FULL_BRAKE_RISING_EDGE: u32 = 4;
137pub const PERFORMANCE_DC_BRICKLET_GPIO_ACTION_FULL_BRAKE_FALLING_EDGE: u32 = 8;
138pub const PERFORMANCE_DC_BRICKLET_GPIO_ACTION_CALLBACK_RISING_EDGE: u32 = 16;
139pub const PERFORMANCE_DC_BRICKLET_GPIO_ACTION_CALLBACK_FALLING_EDGE: u32 = 32;
140pub const PERFORMANCE_DC_BRICKLET_ERROR_LED_CONFIG_OFF: u8 = 0;
141pub const PERFORMANCE_DC_BRICKLET_ERROR_LED_CONFIG_ON: u8 = 1;
142pub const PERFORMANCE_DC_BRICKLET_ERROR_LED_CONFIG_SHOW_HEARTBEAT: u8 = 2;
143pub const PERFORMANCE_DC_BRICKLET_ERROR_LED_CONFIG_SHOW_ERROR: u8 = 3;
144pub const PERFORMANCE_DC_BRICKLET_CW_LED_CONFIG_OFF: u8 = 0;
145pub const PERFORMANCE_DC_BRICKLET_CW_LED_CONFIG_ON: u8 = 1;
146pub const PERFORMANCE_DC_BRICKLET_CW_LED_CONFIG_SHOW_HEARTBEAT: u8 = 2;
147pub const PERFORMANCE_DC_BRICKLET_CW_LED_CONFIG_SHOW_CW_AS_FORWARD: u8 = 3;
148pub const PERFORMANCE_DC_BRICKLET_CW_LED_CONFIG_SHOW_CW_AS_BACKWARD: u8 = 4;
149pub const PERFORMANCE_DC_BRICKLET_CCW_LED_CONFIG_OFF: u8 = 0;
150pub const PERFORMANCE_DC_BRICKLET_CCW_LED_CONFIG_ON: u8 = 1;
151pub const PERFORMANCE_DC_BRICKLET_CCW_LED_CONFIG_SHOW_HEARTBEAT: u8 = 2;
152pub const PERFORMANCE_DC_BRICKLET_CCW_LED_CONFIG_SHOW_CCW_AS_FORWARD: u8 = 3;
153pub const PERFORMANCE_DC_BRICKLET_CCW_LED_CONFIG_SHOW_CCW_AS_BACKWARD: u8 = 4;
154pub const PERFORMANCE_DC_BRICKLET_GPIO_LED_CONFIG_OFF: u8 = 0;
155pub const PERFORMANCE_DC_BRICKLET_GPIO_LED_CONFIG_ON: u8 = 1;
156pub const PERFORMANCE_DC_BRICKLET_GPIO_LED_CONFIG_SHOW_HEARTBEAT: u8 = 2;
157pub const PERFORMANCE_DC_BRICKLET_GPIO_LED_CONFIG_SHOW_GPIO_ACTIVE_HIGH: u8 = 3;
158pub const PERFORMANCE_DC_BRICKLET_GPIO_LED_CONFIG_SHOW_GPIO_ACTIVE_LOW: u8 = 4;
159pub const PERFORMANCE_DC_BRICKLET_BOOTLOADER_MODE_BOOTLOADER: u8 = 0;
160pub const PERFORMANCE_DC_BRICKLET_BOOTLOADER_MODE_FIRMWARE: u8 = 1;
161pub const PERFORMANCE_DC_BRICKLET_BOOTLOADER_MODE_BOOTLOADER_WAIT_FOR_REBOOT: u8 = 2;
162pub const PERFORMANCE_DC_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_REBOOT: u8 = 3;
163pub const PERFORMANCE_DC_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_ERASE_AND_REBOOT: u8 = 4;
164pub const PERFORMANCE_DC_BRICKLET_BOOTLOADER_STATUS_OK: u8 = 0;
165pub const PERFORMANCE_DC_BRICKLET_BOOTLOADER_STATUS_INVALID_MODE: u8 = 1;
166pub const PERFORMANCE_DC_BRICKLET_BOOTLOADER_STATUS_NO_CHANGE: u8 = 2;
167pub const PERFORMANCE_DC_BRICKLET_BOOTLOADER_STATUS_ENTRY_FUNCTION_NOT_PRESENT: u8 = 3;
168pub const PERFORMANCE_DC_BRICKLET_BOOTLOADER_STATUS_DEVICE_IDENTIFIER_INCORRECT: u8 = 4;
169pub const PERFORMANCE_DC_BRICKLET_BOOTLOADER_STATUS_CRC_MISMATCH: u8 = 5;
170pub const PERFORMANCE_DC_BRICKLET_STATUS_LED_CONFIG_OFF: u8 = 0;
171pub const PERFORMANCE_DC_BRICKLET_STATUS_LED_CONFIG_ON: u8 = 1;
172pub const PERFORMANCE_DC_BRICKLET_STATUS_LED_CONFIG_SHOW_HEARTBEAT: u8 = 2;
173pub const PERFORMANCE_DC_BRICKLET_STATUS_LED_CONFIG_SHOW_STATUS: u8 = 3;
174
175#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
176pub struct Motion {
177 pub acceleration: u16,
178 pub deceleration: u16,
179}
180impl FromByteSlice for Motion {
181 fn bytes_expected() -> usize {
182 4
183 }
184 fn from_le_byte_slice(bytes: &[u8]) -> Motion {
185 Motion { acceleration: <u16>::from_le_byte_slice(&bytes[0..2]), deceleration: <u16>::from_le_byte_slice(&bytes[2..4]) }
186 }
187}
188
189#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
190pub struct PowerStatistics {
191 pub voltage: u16,
192 pub current: u16,
193 pub temperature: i16,
194}
195impl FromByteSlice for PowerStatistics {
196 fn bytes_expected() -> usize {
197 6
198 }
199 fn from_le_byte_slice(bytes: &[u8]) -> PowerStatistics {
200 PowerStatistics {
201 voltage: <u16>::from_le_byte_slice(&bytes[0..2]),
202 current: <u16>::from_le_byte_slice(&bytes[2..4]),
203 temperature: <i16>::from_le_byte_slice(&bytes[4..6]),
204 }
205 }
206}
207
208#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
209pub struct GpioConfiguration {
210 pub debounce: u16,
211 pub stop_deceleration: u16,
212}
213impl FromByteSlice for GpioConfiguration {
214 fn bytes_expected() -> usize {
215 4
216 }
217 fn from_le_byte_slice(bytes: &[u8]) -> GpioConfiguration {
218 GpioConfiguration { debounce: <u16>::from_le_byte_slice(&bytes[0..2]), stop_deceleration: <u16>::from_le_byte_slice(&bytes[2..4]) }
219 }
220}
221
222#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
223pub struct CurrentVelocityCallbackConfiguration {
224 pub period: u32,
225 pub value_has_to_change: bool,
226}
227impl FromByteSlice for CurrentVelocityCallbackConfiguration {
228 fn bytes_expected() -> usize {
229 5
230 }
231 fn from_le_byte_slice(bytes: &[u8]) -> CurrentVelocityCallbackConfiguration {
232 CurrentVelocityCallbackConfiguration {
233 period: <u32>::from_le_byte_slice(&bytes[0..4]),
234 value_has_to_change: <bool>::from_le_byte_slice(&bytes[4..5]),
235 }
236 }
237}
238
239#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
240pub struct SpitfpErrorCount {
241 pub error_count_ack_checksum: u32,
242 pub error_count_message_checksum: u32,
243 pub error_count_frame: u32,
244 pub error_count_overflow: u32,
245}
246impl FromByteSlice for SpitfpErrorCount {
247 fn bytes_expected() -> usize {
248 16
249 }
250 fn from_le_byte_slice(bytes: &[u8]) -> SpitfpErrorCount {
251 SpitfpErrorCount {
252 error_count_ack_checksum: <u32>::from_le_byte_slice(&bytes[0..4]),
253 error_count_message_checksum: <u32>::from_le_byte_slice(&bytes[4..8]),
254 error_count_frame: <u32>::from_le_byte_slice(&bytes[8..12]),
255 error_count_overflow: <u32>::from_le_byte_slice(&bytes[12..16]),
256 }
257 }
258}
259
260#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
261pub struct Identity {
262 pub uid: String,
263 pub connected_uid: String,
264 pub position: char,
265 pub hardware_version: [u8; 3],
266 pub firmware_version: [u8; 3],
267 pub device_identifier: u16,
268}
269impl FromByteSlice for Identity {
270 fn bytes_expected() -> usize {
271 25
272 }
273 fn from_le_byte_slice(bytes: &[u8]) -> Identity {
274 Identity {
275 uid: <String>::from_le_byte_slice(&bytes[0..8]),
276 connected_uid: <String>::from_le_byte_slice(&bytes[8..16]),
277 position: <char>::from_le_byte_slice(&bytes[16..17]),
278 hardware_version: <[u8; 3]>::from_le_byte_slice(&bytes[17..20]),
279 firmware_version: <[u8; 3]>::from_le_byte_slice(&bytes[20..23]),
280 device_identifier: <u16>::from_le_byte_slice(&bytes[23..25]),
281 }
282 }
283}
284
285#[derive(Clone)]
287pub struct PerformanceDcBricklet {
288 device: Device,
289}
290impl PerformanceDcBricklet {
291 pub const DEVICE_IDENTIFIER: u16 = 2156;
292 pub const DEVICE_DISPLAY_NAME: &'static str = "Performance DC Bricklet";
293 pub fn new(uid: Uid, connection: AsyncIpConnection) -> PerformanceDcBricklet {
295 let mut result = PerformanceDcBricklet { device: Device::new([2, 0, 10], uid, connection, Self::DEVICE_DISPLAY_NAME) };
296 result.device.response_expected[u8::from(PerformanceDcBrickletFunction::SetEnabled) as usize] = ResponseExpectedFlag::False;
297 result.device.response_expected[u8::from(PerformanceDcBrickletFunction::GetEnabled) as usize] = ResponseExpectedFlag::AlwaysTrue;
298 result.device.response_expected[u8::from(PerformanceDcBrickletFunction::SetVelocity) as usize] = ResponseExpectedFlag::False;
299 result.device.response_expected[u8::from(PerformanceDcBrickletFunction::GetVelocity) as usize] = ResponseExpectedFlag::AlwaysTrue;
300 result.device.response_expected[u8::from(PerformanceDcBrickletFunction::GetCurrentVelocity) as usize] =
301 ResponseExpectedFlag::AlwaysTrue;
302 result.device.response_expected[u8::from(PerformanceDcBrickletFunction::SetMotion) as usize] = ResponseExpectedFlag::False;
303 result.device.response_expected[u8::from(PerformanceDcBrickletFunction::GetMotion) as usize] = ResponseExpectedFlag::AlwaysTrue;
304 result.device.response_expected[u8::from(PerformanceDcBrickletFunction::FullBrake) as usize] = ResponseExpectedFlag::False;
305 result.device.response_expected[u8::from(PerformanceDcBrickletFunction::SetDriveMode) as usize] = ResponseExpectedFlag::False;
306 result.device.response_expected[u8::from(PerformanceDcBrickletFunction::GetDriveMode) as usize] = ResponseExpectedFlag::AlwaysTrue;
307 result.device.response_expected[u8::from(PerformanceDcBrickletFunction::SetPwmFrequency) as usize] = ResponseExpectedFlag::False;
308 result.device.response_expected[u8::from(PerformanceDcBrickletFunction::GetPwmFrequency) as usize] =
309 ResponseExpectedFlag::AlwaysTrue;
310 result.device.response_expected[u8::from(PerformanceDcBrickletFunction::GetPowerStatistics) as usize] =
311 ResponseExpectedFlag::AlwaysTrue;
312 result.device.response_expected[u8::from(PerformanceDcBrickletFunction::SetThermalShutdown) as usize] = ResponseExpectedFlag::False;
313 result.device.response_expected[u8::from(PerformanceDcBrickletFunction::GetThermalShutdown) as usize] =
314 ResponseExpectedFlag::AlwaysTrue;
315 result.device.response_expected[u8::from(PerformanceDcBrickletFunction::SetGpioConfiguration) as usize] =
316 ResponseExpectedFlag::False;
317 result.device.response_expected[u8::from(PerformanceDcBrickletFunction::GetGpioConfiguration) as usize] =
318 ResponseExpectedFlag::AlwaysTrue;
319 result.device.response_expected[u8::from(PerformanceDcBrickletFunction::SetGpioAction) as usize] = ResponseExpectedFlag::False;
320 result.device.response_expected[u8::from(PerformanceDcBrickletFunction::GetGpioAction) as usize] = ResponseExpectedFlag::AlwaysTrue;
321 result.device.response_expected[u8::from(PerformanceDcBrickletFunction::GetGpioState) as usize] = ResponseExpectedFlag::AlwaysTrue;
322 result.device.response_expected[u8::from(PerformanceDcBrickletFunction::SetErrorLedConfig) as usize] = ResponseExpectedFlag::False;
323 result.device.response_expected[u8::from(PerformanceDcBrickletFunction::GetErrorLedConfig) as usize] =
324 ResponseExpectedFlag::AlwaysTrue;
325 result.device.response_expected[u8::from(PerformanceDcBrickletFunction::SetCwLedConfig) as usize] = ResponseExpectedFlag::False;
326 result.device.response_expected[u8::from(PerformanceDcBrickletFunction::GetCwLedConfig) as usize] =
327 ResponseExpectedFlag::AlwaysTrue;
328 result.device.response_expected[u8::from(PerformanceDcBrickletFunction::SetCcwLedConfig) as usize] = ResponseExpectedFlag::False;
329 result.device.response_expected[u8::from(PerformanceDcBrickletFunction::GetCcwLedConfig) as usize] =
330 ResponseExpectedFlag::AlwaysTrue;
331 result.device.response_expected[u8::from(PerformanceDcBrickletFunction::SetGpioLedConfig) as usize] = ResponseExpectedFlag::False;
332 result.device.response_expected[u8::from(PerformanceDcBrickletFunction::GetGpioLedConfig) as usize] =
333 ResponseExpectedFlag::AlwaysTrue;
334 result.device.response_expected[u8::from(PerformanceDcBrickletFunction::SetEmergencyShutdownCallbackConfiguration) as usize] =
335 ResponseExpectedFlag::True;
336 result.device.response_expected[u8::from(PerformanceDcBrickletFunction::GetEmergencyShutdownCallbackConfiguration) as usize] =
337 ResponseExpectedFlag::AlwaysTrue;
338 result.device.response_expected[u8::from(PerformanceDcBrickletFunction::SetVelocityReachedCallbackConfiguration) as usize] =
339 ResponseExpectedFlag::True;
340 result.device.response_expected[u8::from(PerformanceDcBrickletFunction::GetVelocityReachedCallbackConfiguration) as usize] =
341 ResponseExpectedFlag::AlwaysTrue;
342 result.device.response_expected[u8::from(PerformanceDcBrickletFunction::SetCurrentVelocityCallbackConfiguration) as usize] =
343 ResponseExpectedFlag::True;
344 result.device.response_expected[u8::from(PerformanceDcBrickletFunction::GetCurrentVelocityCallbackConfiguration) as usize] =
345 ResponseExpectedFlag::AlwaysTrue;
346 result.device.response_expected[u8::from(PerformanceDcBrickletFunction::GetSpitfpErrorCount) as usize] =
347 ResponseExpectedFlag::AlwaysTrue;
348 result.device.response_expected[u8::from(PerformanceDcBrickletFunction::SetBootloaderMode) as usize] =
349 ResponseExpectedFlag::AlwaysTrue;
350 result.device.response_expected[u8::from(PerformanceDcBrickletFunction::GetBootloaderMode) as usize] =
351 ResponseExpectedFlag::AlwaysTrue;
352 result.device.response_expected[u8::from(PerformanceDcBrickletFunction::SetWriteFirmwarePointer) as usize] =
353 ResponseExpectedFlag::False;
354 result.device.response_expected[u8::from(PerformanceDcBrickletFunction::WriteFirmware) as usize] = ResponseExpectedFlag::AlwaysTrue;
355 result.device.response_expected[u8::from(PerformanceDcBrickletFunction::SetStatusLedConfig) as usize] = ResponseExpectedFlag::False;
356 result.device.response_expected[u8::from(PerformanceDcBrickletFunction::GetStatusLedConfig) as usize] =
357 ResponseExpectedFlag::AlwaysTrue;
358 result.device.response_expected[u8::from(PerformanceDcBrickletFunction::GetChipTemperature) as usize] =
359 ResponseExpectedFlag::AlwaysTrue;
360 result.device.response_expected[u8::from(PerformanceDcBrickletFunction::Reset) as usize] = ResponseExpectedFlag::False;
361 result.device.response_expected[u8::from(PerformanceDcBrickletFunction::WriteUid) as usize] = ResponseExpectedFlag::False;
362 result.device.response_expected[u8::from(PerformanceDcBrickletFunction::ReadUid) as usize] = ResponseExpectedFlag::AlwaysTrue;
363 result.device.response_expected[u8::from(PerformanceDcBrickletFunction::GetIdentity) as usize] = ResponseExpectedFlag::AlwaysTrue;
364 result
365 }
366
367 pub fn get_response_expected(&mut self, fun: PerformanceDcBrickletFunction) -> Result<bool, GetResponseExpectedError> {
382 self.device.get_response_expected(u8::from(fun))
383 }
384
385 pub fn set_response_expected(
394 &mut self,
395 fun: PerformanceDcBrickletFunction,
396 response_expected: bool,
397 ) -> Result<(), SetResponseExpectedError> {
398 self.device.set_response_expected(u8::from(fun), response_expected)
399 }
400
401 pub fn set_response_expected_all(&mut self, response_expected: bool) {
403 self.device.set_response_expected_all(response_expected)
404 }
405
406 pub fn get_api_version(&self) -> [u8; 3] {
409 self.device.api_version
410 }
411
412 pub async fn get_emergency_shutdown_callback_receiver(&mut self) -> impl Stream<Item = ()> {
424 self.device.get_callback_receiver(u8::from(PerformanceDcBrickletFunction::CallbackEmergencyShutdown)).await.map(|_p| ())
425 }
426
427 pub async fn get_velocity_reached_callback_receiver(&mut self) -> impl Stream<Item = i16> {
438 self.device
439 .get_callback_receiver(u8::from(PerformanceDcBrickletFunction::CallbackVelocityReached))
440 .await
441 .map(|p| i16::from_le_byte_slice(p.body()))
442 }
443
444 pub async fn get_current_velocity_callback_receiver(&mut self) -> impl Stream<Item = i16> {
451 self.device
452 .get_callback_receiver(u8::from(PerformanceDcBrickletFunction::CallbackCurrentVelocity))
453 .await
454 .map(|p| i16::from_le_byte_slice(p.body()))
455 }
456
457 pub async fn get_gpio_state_callback_receiver(&mut self) -> impl Stream<Item = [bool; 2]> {
462 self.device
463 .get_callback_receiver(u8::from(PerformanceDcBrickletFunction::CallbackGpioState))
464 .await
465 .map(|p| <[bool; 2]>::from_le_byte_slice(p.body()))
466 }
467
468 pub async fn set_enabled(&mut self, enabled: bool) -> Result<(), TinkerforgeError> {
471 let mut payload = [0; 1];
472 enabled.write_to_slice(&mut payload[0..1]);
473
474 #[allow(unused_variables)]
475 let result = self.device.set(u8::from(PerformanceDcBrickletFunction::SetEnabled), &payload).await?;
476 Ok(())
477 }
478
479 pub async fn get_enabled(&mut self) -> Result<bool, TinkerforgeError> {
481 let payload = [0; 0];
482
483 #[allow(unused_variables)]
484 let result = self.device.get(u8::from(PerformanceDcBrickletFunction::GetEnabled), &payload).await?;
485 Ok(bool::from_le_byte_slice(result.body()))
486 }
487
488 pub async fn set_velocity(&mut self, velocity: i16) -> Result<(), TinkerforgeError> {
498 let mut payload = [0; 2];
499 velocity.write_to_slice(&mut payload[0..2]);
500
501 #[allow(unused_variables)]
502 let result = self.device.set(u8::from(PerformanceDcBrickletFunction::SetVelocity), &payload).await?;
503 Ok(())
504 }
505
506 pub async fn get_velocity(&mut self) -> Result<i16, TinkerforgeError> {
508 let payload = [0; 0];
509
510 #[allow(unused_variables)]
511 let result = self.device.get(u8::from(PerformanceDcBrickletFunction::GetVelocity), &payload).await?;
512 Ok(i16::from_le_byte_slice(result.body()))
513 }
514
515 pub async fn get_current_velocity(&mut self) -> Result<i16, TinkerforgeError> {
519 let payload = [0; 0];
520
521 #[allow(unused_variables)]
522 let result = self.device.get(u8::from(PerformanceDcBrickletFunction::GetCurrentVelocity), &payload).await?;
523 Ok(i16::from_le_byte_slice(result.body()))
524 }
525
526 pub async fn set_motion(&mut self, acceleration: u16, deceleration: u16) -> Result<(), TinkerforgeError> {
537 let mut payload = [0; 4];
538 acceleration.write_to_slice(&mut payload[0..2]);
539 deceleration.write_to_slice(&mut payload[2..4]);
540
541 #[allow(unused_variables)]
542 let result = self.device.set(u8::from(PerformanceDcBrickletFunction::SetMotion), &payload).await?;
543 Ok(())
544 }
545
546 pub async fn get_motion(&mut self) -> Result<Motion, TinkerforgeError> {
548 let payload = [0; 0];
549
550 #[allow(unused_variables)]
551 let result = self.device.get(u8::from(PerformanceDcBrickletFunction::GetMotion), &payload).await?;
552 Ok(Motion::from_le_byte_slice(result.body()))
553 }
554
555 pub async fn full_brake(&mut self) -> Result<(), TinkerforgeError> {
564 let payload = [0; 0];
565
566 #[allow(unused_variables)]
567 let result = self.device.set(u8::from(PerformanceDcBrickletFunction::FullBrake), &payload).await?;
568 Ok(())
569 }
570
571 pub async fn set_drive_mode(&mut self, mode: u8) -> Result<(), TinkerforgeError> {
591 let mut payload = [0; 1];
592 mode.write_to_slice(&mut payload[0..1]);
593
594 #[allow(unused_variables)]
595 let result = self.device.set(u8::from(PerformanceDcBrickletFunction::SetDriveMode), &payload).await?;
596 Ok(())
597 }
598
599 pub async fn get_drive_mode(&mut self) -> Result<u8, TinkerforgeError> {
605 let payload = [0; 0];
606
607 #[allow(unused_variables)]
608 let result = self.device.get(u8::from(PerformanceDcBrickletFunction::GetDriveMode), &payload).await?;
609 Ok(u8::from_le_byte_slice(result.body()))
610 }
611
612 pub async fn set_pwm_frequency(&mut self, frequency: u16) -> Result<(), TinkerforgeError> {
621 let mut payload = [0; 2];
622 frequency.write_to_slice(&mut payload[0..2]);
623
624 #[allow(unused_variables)]
625 let result = self.device.set(u8::from(PerformanceDcBrickletFunction::SetPwmFrequency), &payload).await?;
626 Ok(())
627 }
628
629 pub async fn get_pwm_frequency(&mut self) -> Result<u16, TinkerforgeError> {
631 let payload = [0; 0];
632
633 #[allow(unused_variables)]
634 let result = self.device.get(u8::from(PerformanceDcBrickletFunction::GetPwmFrequency), &payload).await?;
635 Ok(u16::from_le_byte_slice(result.body()))
636 }
637
638 pub async fn get_power_statistics(&mut self) -> Result<PowerStatistics, TinkerforgeError> {
640 let payload = [0; 0];
641
642 #[allow(unused_variables)]
643 let result = self.device.get(u8::from(PerformanceDcBrickletFunction::GetPowerStatistics), &payload).await?;
644 Ok(PowerStatistics::from_le_byte_slice(result.body()))
645 }
646
647 pub async fn set_thermal_shutdown(&mut self, temperature: u8) -> Result<(), TinkerforgeError> {
655 let mut payload = [0; 1];
656 temperature.write_to_slice(&mut payload[0..1]);
657
658 #[allow(unused_variables)]
659 let result = self.device.set(u8::from(PerformanceDcBrickletFunction::SetThermalShutdown), &payload).await?;
660 Ok(())
661 }
662
663 pub async fn get_thermal_shutdown(&mut self) -> Result<u8, TinkerforgeError> {
665 let payload = [0; 0];
666
667 #[allow(unused_variables)]
668 let result = self.device.get(u8::from(PerformanceDcBrickletFunction::GetThermalShutdown), &payload).await?;
669 Ok(u8::from_le_byte_slice(result.body()))
670 }
671
672 pub async fn set_gpio_configuration(&mut self, channel: u8, debounce: u16, stop_deceleration: u16) -> Result<(), TinkerforgeError> {
676 let mut payload = [0; 5];
677 channel.write_to_slice(&mut payload[0..1]);
678 debounce.write_to_slice(&mut payload[1..3]);
679 stop_deceleration.write_to_slice(&mut payload[3..5]);
680
681 #[allow(unused_variables)]
682 let result = self.device.set(u8::from(PerformanceDcBrickletFunction::SetGpioConfiguration), &payload).await?;
683 Ok(())
684 }
685
686 pub async fn get_gpio_configuration(&mut self, channel: u8) -> Result<GpioConfiguration, TinkerforgeError> {
688 let mut payload = [0; 1];
689 channel.write_to_slice(&mut payload[0..1]);
690
691 #[allow(unused_variables)]
692 let result = self.device.get(u8::from(PerformanceDcBrickletFunction::GetGpioConfiguration), &payload).await?;
693 Ok(GpioConfiguration::from_le_byte_slice(result.body()))
694 }
695
696 pub async fn set_gpio_action(&mut self, channel: u8, action: u32) -> Result<(), TinkerforgeError> {
715 let mut payload = [0; 5];
716 channel.write_to_slice(&mut payload[0..1]);
717 action.write_to_slice(&mut payload[1..5]);
718
719 #[allow(unused_variables)]
720 let result = self.device.set(u8::from(PerformanceDcBrickletFunction::SetGpioAction), &payload).await?;
721 Ok(())
722 }
723
724 pub async fn get_gpio_action(&mut self, channel: u8) -> Result<u32, TinkerforgeError> {
735 let mut payload = [0; 1];
736 channel.write_to_slice(&mut payload[0..1]);
737
738 #[allow(unused_variables)]
739 let result = self.device.get(u8::from(PerformanceDcBrickletFunction::GetGpioAction), &payload).await?;
740 Ok(u32::from_le_byte_slice(result.body()))
741 }
742
743 pub async fn get_gpio_state(&mut self) -> Result<Box<[bool; 2]>, TinkerforgeError> {
746 let payload = [0; 0];
747
748 #[allow(unused_variables)]
749 let result = self.device.get(u8::from(PerformanceDcBrickletFunction::GetGpioState), &payload).await?;
750 Ok(Box::<[bool; 2]>::from_le_byte_slice(result.body()))
751 }
752
753 pub async fn set_error_led_config(&mut self, config: u8) -> Result<(), TinkerforgeError> {
768 let mut payload = [0; 1];
769 config.write_to_slice(&mut payload[0..1]);
770
771 #[allow(unused_variables)]
772 let result = self.device.set(u8::from(PerformanceDcBrickletFunction::SetErrorLedConfig), &payload).await?;
773 Ok(())
774 }
775
776 pub async fn get_error_led_config(&mut self) -> Result<u8, TinkerforgeError> {
784 let payload = [0; 0];
785
786 #[allow(unused_variables)]
787 let result = self.device.get(u8::from(PerformanceDcBrickletFunction::GetErrorLedConfig), &payload).await?;
788 Ok(u8::from_le_byte_slice(result.body()))
789 }
790
791 pub async fn set_cw_led_config(&mut self, config: u8) -> Result<(), TinkerforgeError> {
801 let mut payload = [0; 1];
802 config.write_to_slice(&mut payload[0..1]);
803
804 #[allow(unused_variables)]
805 let result = self.device.set(u8::from(PerformanceDcBrickletFunction::SetCwLedConfig), &payload).await?;
806 Ok(())
807 }
808
809 pub async fn get_cw_led_config(&mut self) -> Result<u8, TinkerforgeError> {
818 let payload = [0; 0];
819
820 #[allow(unused_variables)]
821 let result = self.device.get(u8::from(PerformanceDcBrickletFunction::GetCwLedConfig), &payload).await?;
822 Ok(u8::from_le_byte_slice(result.body()))
823 }
824
825 pub async fn set_ccw_led_config(&mut self, config: u8) -> Result<(), TinkerforgeError> {
835 let mut payload = [0; 1];
836 config.write_to_slice(&mut payload[0..1]);
837
838 #[allow(unused_variables)]
839 let result = self.device.set(u8::from(PerformanceDcBrickletFunction::SetCcwLedConfig), &payload).await?;
840 Ok(())
841 }
842
843 pub async fn get_ccw_led_config(&mut self) -> Result<u8, TinkerforgeError> {
852 let payload = [0; 0];
853
854 #[allow(unused_variables)]
855 let result = self.device.get(u8::from(PerformanceDcBrickletFunction::GetCcwLedConfig), &payload).await?;
856 Ok(u8::from_le_byte_slice(result.body()))
857 }
858
859 pub async fn set_gpio_led_config(&mut self, channel: u8, config: u8) -> Result<(), TinkerforgeError> {
871 let mut payload = [0; 2];
872 channel.write_to_slice(&mut payload[0..1]);
873 config.write_to_slice(&mut payload[1..2]);
874
875 #[allow(unused_variables)]
876 let result = self.device.set(u8::from(PerformanceDcBrickletFunction::SetGpioLedConfig), &payload).await?;
877 Ok(())
878 }
879
880 pub async fn get_gpio_led_config(&mut self, channel: u8) -> Result<u8, TinkerforgeError> {
889 let mut payload = [0; 1];
890 channel.write_to_slice(&mut payload[0..1]);
891
892 #[allow(unused_variables)]
893 let result = self.device.get(u8::from(PerformanceDcBrickletFunction::GetGpioLedConfig), &payload).await?;
894 Ok(u8::from_le_byte_slice(result.body()))
895 }
896
897 pub async fn set_emergency_shutdown_callback_configuration(&mut self, enabled: bool) -> Result<(), TinkerforgeError> {
899 let mut payload = [0; 1];
900 enabled.write_to_slice(&mut payload[0..1]);
901
902 #[allow(unused_variables)]
903 let result = self.device.set(u8::from(PerformanceDcBrickletFunction::SetEmergencyShutdownCallbackConfiguration), &payload).await?;
904 Ok(())
905 }
906
907 pub async fn get_emergency_shutdown_callback_configuration(&mut self) -> Result<bool, TinkerforgeError> {
910 let payload = [0; 0];
911
912 #[allow(unused_variables)]
913 let result = self.device.get(u8::from(PerformanceDcBrickletFunction::GetEmergencyShutdownCallbackConfiguration), &payload).await?;
914 Ok(bool::from_le_byte_slice(result.body()))
915 }
916
917 pub async fn set_velocity_reached_callback_configuration(&mut self, enabled: bool) -> Result<(), TinkerforgeError> {
919 let mut payload = [0; 1];
920 enabled.write_to_slice(&mut payload[0..1]);
921
922 #[allow(unused_variables)]
923 let result = self.device.set(u8::from(PerformanceDcBrickletFunction::SetVelocityReachedCallbackConfiguration), &payload).await?;
924 Ok(())
925 }
926
927 pub async fn get_velocity_reached_callback_configuration(&mut self) -> Result<bool, TinkerforgeError> {
930 let payload = [0; 0];
931
932 #[allow(unused_variables)]
933 let result = self.device.get(u8::from(PerformanceDcBrickletFunction::GetVelocityReachedCallbackConfiguration), &payload).await?;
934 Ok(bool::from_le_byte_slice(result.body()))
935 }
936
937 pub async fn set_current_velocity_callback_configuration(
947 &mut self,
948 period: u32,
949 value_has_to_change: bool,
950 ) -> Result<(), TinkerforgeError> {
951 let mut payload = [0; 5];
952 period.write_to_slice(&mut payload[0..4]);
953 value_has_to_change.write_to_slice(&mut payload[4..5]);
954
955 #[allow(unused_variables)]
956 let result = self.device.set(u8::from(PerformanceDcBrickletFunction::SetCurrentVelocityCallbackConfiguration), &payload).await?;
957 Ok(())
958 }
959
960 pub async fn get_current_velocity_callback_configuration(&mut self) -> Result<CurrentVelocityCallbackConfiguration, TinkerforgeError> {
963 let payload = [0; 0];
964
965 #[allow(unused_variables)]
966 let result = self.device.get(u8::from(PerformanceDcBrickletFunction::GetCurrentVelocityCallbackConfiguration), &payload).await?;
967 Ok(CurrentVelocityCallbackConfiguration::from_le_byte_slice(result.body()))
968 }
969
970 pub async fn get_spitfp_error_count(&mut self) -> Result<SpitfpErrorCount, TinkerforgeError> {
982 let payload = [0; 0];
983
984 #[allow(unused_variables)]
985 let result = self.device.get(u8::from(PerformanceDcBrickletFunction::GetSpitfpErrorCount), &payload).await?;
986 Ok(SpitfpErrorCount::from_le_byte_slice(result.body()))
987 }
988
989 pub async fn set_bootloader_mode(&mut self, mode: u8) -> Result<u8, TinkerforgeError> {
1012 let mut payload = [0; 1];
1013 mode.write_to_slice(&mut payload[0..1]);
1014
1015 #[allow(unused_variables)]
1016 let result = self.device.get(u8::from(PerformanceDcBrickletFunction::SetBootloaderMode), &payload).await?;
1017 Ok(u8::from_le_byte_slice(result.body()))
1018 }
1019
1020 pub async fn get_bootloader_mode(&mut self) -> Result<u8, TinkerforgeError> {
1029 let payload = [0; 0];
1030
1031 #[allow(unused_variables)]
1032 let result = self.device.get(u8::from(PerformanceDcBrickletFunction::GetBootloaderMode), &payload).await?;
1033 Ok(u8::from_le_byte_slice(result.body()))
1034 }
1035
1036 pub async fn set_write_firmware_pointer(&mut self, pointer: u32) -> Result<(), TinkerforgeError> {
1043 let mut payload = [0; 4];
1044 pointer.write_to_slice(&mut payload[0..4]);
1045
1046 #[allow(unused_variables)]
1047 let result = self.device.set(u8::from(PerformanceDcBrickletFunction::SetWriteFirmwarePointer), &payload).await?;
1048 Ok(())
1049 }
1050
1051 pub async fn write_firmware(&mut self, data: &[u8; 64]) -> Result<u8, TinkerforgeError> {
1060 let mut payload = [0; 64];
1061 data.write_to_slice(&mut payload[0..64]);
1062
1063 #[allow(unused_variables)]
1064 let result = self.device.get(u8::from(PerformanceDcBrickletFunction::WriteFirmware), &payload).await?;
1065 Ok(u8::from_le_byte_slice(result.body()))
1066 }
1067
1068 pub async fn set_status_led_config(&mut self, config: u8) -> Result<(), TinkerforgeError> {
1082 let mut payload = [0; 1];
1083 config.write_to_slice(&mut payload[0..1]);
1084
1085 #[allow(unused_variables)]
1086 let result = self.device.set(u8::from(PerformanceDcBrickletFunction::SetStatusLedConfig), &payload).await?;
1087 Ok(())
1088 }
1089
1090 pub async fn get_status_led_config(&mut self) -> Result<u8, TinkerforgeError> {
1098 let payload = [0; 0];
1099
1100 #[allow(unused_variables)]
1101 let result = self.device.get(u8::from(PerformanceDcBrickletFunction::GetStatusLedConfig), &payload).await?;
1102 Ok(u8::from_le_byte_slice(result.body()))
1103 }
1104
1105 pub async fn get_chip_temperature(&mut self) -> Result<i16, TinkerforgeError> {
1112 let payload = [0; 0];
1113
1114 #[allow(unused_variables)]
1115 let result = self.device.get(u8::from(PerformanceDcBrickletFunction::GetChipTemperature), &payload).await?;
1116 Ok(i16::from_le_byte_slice(result.body()))
1117 }
1118
1119 pub async fn reset(&mut self) -> Result<(), TinkerforgeError> {
1126 let payload = [0; 0];
1127
1128 #[allow(unused_variables)]
1129 let result = self.device.set(u8::from(PerformanceDcBrickletFunction::Reset), &payload).await?;
1130 Ok(())
1131 }
1132
1133 pub async fn write_uid(&mut self, uid: u32) -> Result<(), TinkerforgeError> {
1139 let mut payload = [0; 4];
1140 uid.write_to_slice(&mut payload[0..4]);
1141
1142 #[allow(unused_variables)]
1143 let result = self.device.set(u8::from(PerformanceDcBrickletFunction::WriteUid), &payload).await?;
1144 Ok(())
1145 }
1146
1147 pub async fn read_uid(&mut self) -> Result<u32, TinkerforgeError> {
1150 let payload = [0; 0];
1151
1152 #[allow(unused_variables)]
1153 let result = self.device.get(u8::from(PerformanceDcBrickletFunction::ReadUid), &payload).await?;
1154 Ok(u32::from_le_byte_slice(result.body()))
1155 }
1156
1157 pub async fn get_identity(&mut self) -> Result<Identity, TinkerforgeError> {
1168 let payload = [0; 0];
1169
1170 #[allow(unused_variables)]
1171 let result = self.device.get(u8::from(PerformanceDcBrickletFunction::GetIdentity), &payload).await?;
1172 Ok(Identity::from_le_byte_slice(result.body()))
1173 }
1174}