tinkerforge_async/bindings/
performance_dc_bricklet.rs

1/* ***********************************************************
2 * This file was automatically generated on 2024-02-16.      *
3 *                                                           *
4 * Rust Bindings Version 2.0.20                              *
5 *                                                           *
6 * If you have a bugfix for this file and want to commit it, *
7 * please fix the bug in the generator. You can find a link  *
8 * to the generators git repository on tinkerforge.com       *
9 *************************************************************/
10
11//! Drives one brushed DC motor with up to 36V and 10A.
12//!
13//! See also the documentation [here](https://www.tinkerforge.com/en/doc/Software/Bricklets/PerformanceDC_Bricklet_Rust.html).
14#[allow(unused_imports)]
15use crate::{
16    base58::Uid, byte_converter::*, device::*, error::TinkerforgeError, ip_connection::async_io::AsyncIpConnection,
17    low_level_traits::LowLevelRead,
18};
19#[allow(unused_imports)]
20use futures_core::Stream;
21#[allow(unused_imports)]
22use tokio_stream::StreamExt;
23pub enum 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/// Drives one brushed DC motor with up to 36V and 10A
286#[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    /// Creates an object with the unique device ID `uid`. This object can then be used after the IP Connection `ip_connection` is connected.
294    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    /// Returns the response expected flag for the function specified by the function ID parameter.
368    /// It is true if the function is expected to send a response, false otherwise.
369    ///
370    /// For getter functions this is enabled by default and cannot be disabled, because those
371    /// functions will always send a response. For callback configuration functions it is enabled
372    /// by default too, but can be disabled by [`set_response_expected`](crate::performance_dc_bricklet::PerformanceDcBricklet::set_response_expected).
373    /// For setter functions it is disabled by default and can be enabled.
374    ///
375    /// Enabling the response expected flag for a setter function allows to detect timeouts
376    /// and other error conditions calls of this setter as well. The device will then send a response
377    /// for this purpose. If this flag is disabled for a setter function then no response is sent
378    /// and errors are silently ignored, because they cannot be detected.
379    ///
380    /// See [`set_response_expected`](crate::performance_dc_bricklet::PerformanceDcBricklet::set_response_expected) for the list of function ID constants available for this function.
381    pub fn get_response_expected(&mut self, fun: PerformanceDcBrickletFunction) -> Result<bool, GetResponseExpectedError> {
382        self.device.get_response_expected(u8::from(fun))
383    }
384
385    /// Changes the response expected flag of the function specified by the function ID parameter.
386    /// This flag can only be changed for setter (default value: false) and callback configuration
387    /// functions (default value: true). For getter functions it is always enabled.
388    ///
389    /// Enabling the response expected flag for a setter function allows to detect timeouts and
390    /// other error conditions calls of this setter as well. The device will then send a response
391    /// for this purpose. If this flag is disabled for a setter function then no response is sent
392    /// and errors are silently ignored, because they cannot be detected.
393    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    /// Changes the response expected flag for all setter and callback configuration functions of this device at once.
402    pub fn set_response_expected_all(&mut self, response_expected: bool) {
403        self.device.set_response_expected_all(response_expected)
404    }
405
406    /// Returns the version of the API definition (major, minor, revision) implemented by this API bindings.
407    /// This is neither the release version of this API bindings nor does it tell you anything about the represented Brick or Bricklet.
408    pub fn get_api_version(&self) -> [u8; 3] {
409        self.device.api_version
410    }
411
412    /// This receiver is triggered if either the current consumption
413    /// is too high or the temperature of the driver chip is too high
414    /// (above 150°C) or the user defined thermal shutdown is triggered (see [`set_thermal_shutdown`]).
415    /// n case of a voltage below 6V (input voltage) this
416    /// receiver is triggered as well.
417    ///
418    /// If this receiver is triggered, the driver chip gets disabled at the same time.
419    /// That means, [`set_enabled`] has to be called to drive the motor again.
420    ///
421    /// [`set_enabled`]: #method.set_enabled
422    /// [`set_thermal_shutdown`]: #method.set_thermal_shutdown
423    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    /// This receiver is triggered whenever a set velocity is reached. For example:
428    /// If a velocity of 0 is present, acceleration is set to 5000 and velocity
429    /// to 10000, the [`get_velocity_reached_callback_receiver`] receiver will be triggered after about
430    /// 2 seconds, when the set velocity is actually reached.
431    ///
432    /// # Note
433    ///  Since we can't get any feedback from the DC motor, this only works if the
434    ///  acceleration (see [`set_motion`]) is set smaller or equal to the
435    ///  maximum acceleration of the motor. Otherwise the motor will lag behind the
436    ///  control value and the receiver will be triggered too early.
437    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    /// This receiver is triggered with the period that is set by
445    /// [`set_current_velocity_callback_configuration`]. The parameter is the *current*
446    /// velocity used by the motor.
447    ///
448    /// The [`get_current_velocity_callback_receiver`] receiver is only triggered after the set period
449    /// if there is a change in the velocity.
450    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    /// This receiver is triggered by GPIO changes if it is activated through [`set_gpio_action`].
458    ///
459    ///
460    /// .. versionadded:: 2.0.1$nbsp;(Plugin)
461    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    /// Enables/Disables the driver chip. The driver parameters can be configured
469    /// (velocity, acceleration, etc) before it is enabled.
470    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    /// Returns *true* if the driver chip is enabled, *false* otherwise.
480    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    /// Sets the velocity of the motor. Whereas -32767 is full speed backward,
489    /// 0 is stop and 32767 is full speed forward. Depending on the
490    /// acceleration (see [`set_motion`]), the motor is not immediately
491    /// brought to the velocity but smoothly accelerated.
492    ///
493    /// The velocity describes the duty cycle of the PWM with which the motor is
494    /// controlled, e.g. a velocity of 3277 sets a PWM with a 10% duty cycle.
495    /// You can not only control the duty cycle of the PWM but also the frequency,
496    /// see [`set_pwm_frequency`].
497    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    /// Returns the velocity as set by [`set_velocity`].
507    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    /// Returns the *current* velocity of the motor. This value is different
516    /// from [`get_velocity`] whenever the motor is currently accelerating
517    /// to a goal set by [`set_velocity`].
518    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    /// Sets the acceleration and deceleration of the motor. It is given in *velocity/s*.
527    /// An acceleration of 10000 means, that every second the velocity is increased
528    /// by 10000 (or about 30% duty cycle).
529    ///
530    /// For example: If the current velocity is 0 and you want to accelerate to a
531    /// velocity of 16000 (about 50% duty cycle) in 10 seconds, you should set
532    /// an acceleration of 1600.
533    ///
534    /// If acceleration and deceleration is set to 0, there is no speed ramping, i.e. a
535    /// new velocity is immediately given to the motor.
536    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    /// Returns the acceleration/deceleration as set by [`set_motion`].
547    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    /// Executes an active full brake.
556    ///
557    /// # Warning
558    ///  This function is for emergency purposes,
559    ///  where an immediate brake is necessary. Depending on the current velocity and
560    ///  the strength of the motor, a full brake can be quite violent.
561    ///
562    /// Call [`set_velocity`] with 0 if you just want to stop the motor.
563    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    /// Sets the drive mode. Possible modes are:
572    ///
573    /// * 0 = Drive/Brake
574    /// * 1 = Drive/Coast
575    ///
576    /// These modes are different kinds of motor controls.
577    ///
578    /// In Drive/Brake mode, the motor is always either driving or braking. There
579    /// is no freewheeling. Advantages are: A more linear correlation between
580    /// PWM and velocity, more exact accelerations and the possibility to drive
581    /// with slower velocities.
582    ///
583    /// In Drive/Coast mode, the motor is always either driving or freewheeling.
584    /// Advantages are: Less current consumption and less demands on the motor and
585    /// driver chip.
586    ///
587    /// Associated constants:
588    /// * PERFORMANCE_DC_BRICKLET_DRIVE_MODE_DRIVE_BRAKE
589    ///	* PERFORMANCE_DC_BRICKLET_DRIVE_MODE_DRIVE_COAST
590    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    /// Returns the drive mode, as set by [`set_drive_mode`].
600    ///
601    /// Associated constants:
602    /// * PERFORMANCE_DC_BRICKLET_DRIVE_MODE_DRIVE_BRAKE
603    ///	* PERFORMANCE_DC_BRICKLET_DRIVE_MODE_DRIVE_COAST
604    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    /// Sets the frequency of the PWM with which the motor is driven.
613    /// Often a high frequency
614    /// is less noisy and the motor runs smoother. However, with a low frequency
615    /// there are less switches and therefore fewer switching losses. Also with
616    /// most motors lower frequencies enable higher torque.
617    ///
618    /// If you have no idea what all this means, just ignore this function and use
619    /// the default frequency, it will very likely work fine.
620    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    /// Returns the PWM frequency as set by [`set_pwm_frequency`].
630    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    /// Returns input voltage, current usage and temperature of the driver.
639    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    /// Sets a temperature threshold that is used for thermal shutdown.
648    ///
649    /// Additionally to this user defined threshold the driver chip will shut down at a
650    /// temperature of 150°C.
651    ///
652    /// If a thermal shutdown is triggered the driver is disabled and has to be
653    /// explicitly re-enabled with [`set_enabled`].
654    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    /// Returns the thermal shutdown temperature as set by [`set_thermal_shutdown`].
664    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    /// Sets the GPIO configuration for the given channel.
673    /// You can configure a debounce and the deceleration that is used if the action is
674    /// configured as ``normal stop``. See [`set_gpio_action`].
675    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    /// Returns the GPIO configuration for a channel as set by [`set_gpio_configuration`].
687    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    /// Sets the GPIO action for the given channel.
697    ///
698    /// The action can be a normal stop, a full brake or a receiver. Each for a rising
699    /// edge or falling edge. The actions are a bitmask they can be used at the same time.
700    /// You can for example trigger a full brake and a receiver at the same time or for
701    /// rising and falling edge.
702    ///
703    /// The deceleration speed for the normal stop can be configured with
704    /// [`set_gpio_configuration`].
705    ///
706    /// Associated constants:
707    /// * PERFORMANCE_DC_BRICKLET_GPIO_ACTION_NONE
708    ///	* PERFORMANCE_DC_BRICKLET_GPIO_ACTION_NORMAL_STOP_RISING_EDGE
709    ///	* PERFORMANCE_DC_BRICKLET_GPIO_ACTION_NORMAL_STOP_FALLING_EDGE
710    ///	* PERFORMANCE_DC_BRICKLET_GPIO_ACTION_FULL_BRAKE_RISING_EDGE
711    ///	* PERFORMANCE_DC_BRICKLET_GPIO_ACTION_FULL_BRAKE_FALLING_EDGE
712    ///	* PERFORMANCE_DC_BRICKLET_GPIO_ACTION_CALLBACK_RISING_EDGE
713    ///	* PERFORMANCE_DC_BRICKLET_GPIO_ACTION_CALLBACK_FALLING_EDGE
714    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    /// Returns the GPIO action for a channel as set by [`set_gpio_action`].
725    ///
726    /// Associated constants:
727    /// * PERFORMANCE_DC_BRICKLET_GPIO_ACTION_NONE
728    ///	* PERFORMANCE_DC_BRICKLET_GPIO_ACTION_NORMAL_STOP_RISING_EDGE
729    ///	* PERFORMANCE_DC_BRICKLET_GPIO_ACTION_NORMAL_STOP_FALLING_EDGE
730    ///	* PERFORMANCE_DC_BRICKLET_GPIO_ACTION_FULL_BRAKE_RISING_EDGE
731    ///	* PERFORMANCE_DC_BRICKLET_GPIO_ACTION_FULL_BRAKE_FALLING_EDGE
732    ///	* PERFORMANCE_DC_BRICKLET_GPIO_ACTION_CALLBACK_RISING_EDGE
733    ///	* PERFORMANCE_DC_BRICKLET_GPIO_ACTION_CALLBACK_FALLING_EDGE
734    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    /// Returns the GPIO state for both channels. True if the state is ``high`` and
744    /// false if the state is ``low``.
745    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    /// Configures the error LED to be either turned off, turned on, blink in
754    /// heartbeat mode or show an error.
755    ///
756    /// If the LED is configured to show errors it has three different states:
757    ///
758    /// * Off: No error present.
759    /// * 1s interval blinking: Input voltage too low (below 6V).
760    /// * 250ms interval blinking: Overtemperature or overcurrent.
761    ///
762    /// Associated constants:
763    /// * PERFORMANCE_DC_BRICKLET_ERROR_LED_CONFIG_OFF
764    ///	* PERFORMANCE_DC_BRICKLET_ERROR_LED_CONFIG_ON
765    ///	* PERFORMANCE_DC_BRICKLET_ERROR_LED_CONFIG_SHOW_HEARTBEAT
766    ///	* PERFORMANCE_DC_BRICKLET_ERROR_LED_CONFIG_SHOW_ERROR
767    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    /// Returns the LED configuration as set by [`set_error_led_config`]
777    ///
778    /// Associated constants:
779    /// * PERFORMANCE_DC_BRICKLET_ERROR_LED_CONFIG_OFF
780    ///	* PERFORMANCE_DC_BRICKLET_ERROR_LED_CONFIG_ON
781    ///	* PERFORMANCE_DC_BRICKLET_ERROR_LED_CONFIG_SHOW_HEARTBEAT
782    ///	* PERFORMANCE_DC_BRICKLET_ERROR_LED_CONFIG_SHOW_ERROR
783    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    /// Configures the CW LED to be either turned off, turned on, blink in
792    /// heartbeat mode or if the motor turn clockwise.
793    ///
794    /// Associated constants:
795    /// * PERFORMANCE_DC_BRICKLET_CW_LED_CONFIG_OFF
796    ///	* PERFORMANCE_DC_BRICKLET_CW_LED_CONFIG_ON
797    ///	* PERFORMANCE_DC_BRICKLET_CW_LED_CONFIG_SHOW_HEARTBEAT
798    ///	* PERFORMANCE_DC_BRICKLET_CW_LED_CONFIG_SHOW_CW_AS_FORWARD
799    ///	* PERFORMANCE_DC_BRICKLET_CW_LED_CONFIG_SHOW_CW_AS_BACKWARD
800    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    /// Returns the LED configuration as set by [`set_cw_led_config`]
810    ///
811    /// Associated constants:
812    /// * PERFORMANCE_DC_BRICKLET_CW_LED_CONFIG_OFF
813    ///	* PERFORMANCE_DC_BRICKLET_CW_LED_CONFIG_ON
814    ///	* PERFORMANCE_DC_BRICKLET_CW_LED_CONFIG_SHOW_HEARTBEAT
815    ///	* PERFORMANCE_DC_BRICKLET_CW_LED_CONFIG_SHOW_CW_AS_FORWARD
816    ///	* PERFORMANCE_DC_BRICKLET_CW_LED_CONFIG_SHOW_CW_AS_BACKWARD
817    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    /// Configures the CCW LED to be either turned off, turned on, blink in
826    /// heartbeat mode or if the motor turn counter-clockwise.
827    ///
828    /// Associated constants:
829    /// * PERFORMANCE_DC_BRICKLET_CCW_LED_CONFIG_OFF
830    ///	* PERFORMANCE_DC_BRICKLET_CCW_LED_CONFIG_ON
831    ///	* PERFORMANCE_DC_BRICKLET_CCW_LED_CONFIG_SHOW_HEARTBEAT
832    ///	* PERFORMANCE_DC_BRICKLET_CCW_LED_CONFIG_SHOW_CCW_AS_FORWARD
833    ///	* PERFORMANCE_DC_BRICKLET_CCW_LED_CONFIG_SHOW_CCW_AS_BACKWARD
834    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    /// Returns the LED configuration as set by [`set_ccw_led_config`]
844    ///
845    /// Associated constants:
846    /// * PERFORMANCE_DC_BRICKLET_CCW_LED_CONFIG_OFF
847    ///	* PERFORMANCE_DC_BRICKLET_CCW_LED_CONFIG_ON
848    ///	* PERFORMANCE_DC_BRICKLET_CCW_LED_CONFIG_SHOW_HEARTBEAT
849    ///	* PERFORMANCE_DC_BRICKLET_CCW_LED_CONFIG_SHOW_CCW_AS_FORWARD
850    ///	* PERFORMANCE_DC_BRICKLET_CCW_LED_CONFIG_SHOW_CCW_AS_BACKWARD
851    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    /// Configures the GPIO LED to be either turned off, turned on, blink in
860    /// heartbeat mode or the GPIO state.
861    ///
862    /// The GPIO LED can be configured for both channels.
863    ///
864    /// Associated constants:
865    /// * PERFORMANCE_DC_BRICKLET_GPIO_LED_CONFIG_OFF
866    ///	* PERFORMANCE_DC_BRICKLET_GPIO_LED_CONFIG_ON
867    ///	* PERFORMANCE_DC_BRICKLET_GPIO_LED_CONFIG_SHOW_HEARTBEAT
868    ///	* PERFORMANCE_DC_BRICKLET_GPIO_LED_CONFIG_SHOW_GPIO_ACTIVE_HIGH
869    ///	* PERFORMANCE_DC_BRICKLET_GPIO_LED_CONFIG_SHOW_GPIO_ACTIVE_LOW
870    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    /// Returns the LED configuration as set by [`set_gpio_led_config`]
881    ///
882    /// Associated constants:
883    /// * PERFORMANCE_DC_BRICKLET_GPIO_LED_CONFIG_OFF
884    ///	* PERFORMANCE_DC_BRICKLET_GPIO_LED_CONFIG_ON
885    ///	* PERFORMANCE_DC_BRICKLET_GPIO_LED_CONFIG_SHOW_HEARTBEAT
886    ///	* PERFORMANCE_DC_BRICKLET_GPIO_LED_CONFIG_SHOW_GPIO_ACTIVE_HIGH
887    ///	* PERFORMANCE_DC_BRICKLET_GPIO_LED_CONFIG_SHOW_GPIO_ACTIVE_LOW
888    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    /// Enable/Disable [`get_emergency_shutdown_callback_receiver`] receiver.
898    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    /// Returns the receiver configuration as set by
908    /// [`set_emergency_shutdown_callback_configuration`].
909    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    /// Enable/Disable [`get_velocity_reached_callback_receiver`] receiver.
918    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    /// Returns the receiver configuration as set by
928    /// [`set_velocity_reached_callback_configuration`].
929    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    /// The period is the period with which the [`get_current_velocity_callback_receiver`]
938    /// receiver is triggered periodically. A value of 0 turns the receiver off.
939    ///
940    /// If the `value has to change`-parameter is set to true, the receiver is only
941    /// triggered after the value has changed. If the value didn't change within the
942    /// period, the receiver is triggered immediately on change.
943    ///
944    /// If it is set to false, the receiver is continuously triggered with the period,
945    /// independent of the value.
946    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    /// Returns the receiver configuration as set by
961    /// [`set_current_velocity_callback_configuration`].
962    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    /// Returns the error count for the communication between Brick and Bricklet.
971    ///
972    /// The errors are divided into
973    ///
974    /// * ACK checksum errors,
975    /// * message checksum errors,
976    /// * framing errors and
977    /// * overflow errors.
978    ///
979    /// The errors counts are for errors that occur on the Bricklet side. All
980    /// Bricks have a similar function that returns the errors on the Brick side.
981    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    /// Sets the bootloader mode and returns the status after the requested
990    /// mode change was instigated.
991    ///
992    /// You can change from bootloader mode to firmware mode and vice versa. A change
993    /// from bootloader mode to firmware mode will only take place if the entry function,
994    /// device identifier and CRC are present and correct.
995    ///
996    /// This function is used by Brick Viewer during flashing. It should not be
997    /// necessary to call it in a normal user program.
998    ///
999    /// Associated constants:
1000    /// * PERFORMANCE_DC_BRICKLET_BOOTLOADER_MODE_BOOTLOADER
1001    ///	* PERFORMANCE_DC_BRICKLET_BOOTLOADER_MODE_FIRMWARE
1002    ///	* PERFORMANCE_DC_BRICKLET_BOOTLOADER_MODE_BOOTLOADER_WAIT_FOR_REBOOT
1003    ///	* PERFORMANCE_DC_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_REBOOT
1004    ///	* PERFORMANCE_DC_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_ERASE_AND_REBOOT
1005    ///	* PERFORMANCE_DC_BRICKLET_BOOTLOADER_STATUS_OK
1006    ///	* PERFORMANCE_DC_BRICKLET_BOOTLOADER_STATUS_INVALID_MODE
1007    ///	* PERFORMANCE_DC_BRICKLET_BOOTLOADER_STATUS_NO_CHANGE
1008    ///	* PERFORMANCE_DC_BRICKLET_BOOTLOADER_STATUS_ENTRY_FUNCTION_NOT_PRESENT
1009    ///	* PERFORMANCE_DC_BRICKLET_BOOTLOADER_STATUS_DEVICE_IDENTIFIER_INCORRECT
1010    ///	* PERFORMANCE_DC_BRICKLET_BOOTLOADER_STATUS_CRC_MISMATCH
1011    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    /// Returns the current bootloader mode, see [`set_bootloader_mode`].
1021    ///
1022    /// Associated constants:
1023    /// * PERFORMANCE_DC_BRICKLET_BOOTLOADER_MODE_BOOTLOADER
1024    ///	* PERFORMANCE_DC_BRICKLET_BOOTLOADER_MODE_FIRMWARE
1025    ///	* PERFORMANCE_DC_BRICKLET_BOOTLOADER_MODE_BOOTLOADER_WAIT_FOR_REBOOT
1026    ///	* PERFORMANCE_DC_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_REBOOT
1027    ///	* PERFORMANCE_DC_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_ERASE_AND_REBOOT
1028    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    /// Sets the firmware pointer for [`write_firmware`]. The pointer has
1037    /// to be increased by chunks of size 64. The data is written to flash
1038    /// every 4 chunks (which equals to one page of size 256).
1039    ///
1040    /// This function is used by Brick Viewer during flashing. It should not be
1041    /// necessary to call it in a normal user program.
1042    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    /// Writes 64 Bytes of firmware at the position as written by
1052    /// [`set_write_firmware_pointer`] before. The firmware is written
1053    /// to flash every 4 chunks.
1054    ///
1055    /// You can only write firmware in bootloader mode.
1056    ///
1057    /// This function is used by Brick Viewer during flashing. It should not be
1058    /// necessary to call it in a normal user program.
1059    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    /// Sets the status LED configuration. By default the LED shows
1069    /// communication traffic between Brick and Bricklet, it flickers once
1070    /// for every 10 received data packets.
1071    ///
1072    /// You can also turn the LED permanently on/off or show a heartbeat.
1073    ///
1074    /// If the Bricklet is in bootloader mode, the LED is will show heartbeat by default.
1075    ///
1076    /// Associated constants:
1077    /// * PERFORMANCE_DC_BRICKLET_STATUS_LED_CONFIG_OFF
1078    ///	* PERFORMANCE_DC_BRICKLET_STATUS_LED_CONFIG_ON
1079    ///	* PERFORMANCE_DC_BRICKLET_STATUS_LED_CONFIG_SHOW_HEARTBEAT
1080    ///	* PERFORMANCE_DC_BRICKLET_STATUS_LED_CONFIG_SHOW_STATUS
1081    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    /// Returns the configuration as set by [`set_status_led_config`]
1091    ///
1092    /// Associated constants:
1093    /// * PERFORMANCE_DC_BRICKLET_STATUS_LED_CONFIG_OFF
1094    ///	* PERFORMANCE_DC_BRICKLET_STATUS_LED_CONFIG_ON
1095    ///	* PERFORMANCE_DC_BRICKLET_STATUS_LED_CONFIG_SHOW_HEARTBEAT
1096    ///	* PERFORMANCE_DC_BRICKLET_STATUS_LED_CONFIG_SHOW_STATUS
1097    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    /// Returns the temperature as measured inside the microcontroller. The
1106    /// value returned is not the ambient temperature!
1107    ///
1108    /// The temperature is only proportional to the real temperature and it has bad
1109    /// accuracy. Practically it is only useful as an indicator for
1110    /// temperature changes.
1111    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    /// Calling this function will reset the Bricklet. All configurations
1120    /// will be lost.
1121    ///
1122    /// After a reset you have to create new device objects,
1123    /// calling functions on the existing ones will result in
1124    /// undefined behavior!
1125    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    /// Writes a new UID into flash. If you want to set a new UID
1134    /// you have to decode the Base58 encoded UID string into an
1135    /// integer first.
1136    ///
1137    /// We recommend that you use Brick Viewer to change the UID.
1138    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    /// Returns the current UID as an integer. Encode as
1148    /// Base58 to get the usual string version.
1149    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    /// Returns the UID, the UID where the Bricklet is connected to,
1158    /// the position, the hardware and firmware version as well as the
1159    /// device identifier.
1160    ///
1161    /// The position can be 'a', 'b', 'c', 'd', 'e', 'f', 'g' or 'h' (Bricklet Port).
1162    /// A Bricklet connected to an [Isolator Bricklet](isolator_bricklet) is always at
1163    /// position 'z'.
1164    ///
1165    /// The device identifier numbers can be found [here](device_identifier).
1166    /// |device_identifier_constant|
1167    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}