tinkerforge_async/bindings/
stepper_brick.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 bipolar stepper motor with up to 38V and 2.5A per phase.
12//!
13//! See also the documentation [here](https://www.tinkerforge.com/en/doc/Software/Bricks/Stepper_Brick_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 StepperBrickFunction {
24    SetMaxVelocity,
25    GetMaxVelocity,
26    GetCurrentVelocity,
27    SetSpeedRamping,
28    GetSpeedRamping,
29    FullBrake,
30    SetCurrentPosition,
31    GetCurrentPosition,
32    SetTargetPosition,
33    GetTargetPosition,
34    SetSteps,
35    GetSteps,
36    GetRemainingSteps,
37    SetStepMode,
38    GetStepMode,
39    DriveForward,
40    DriveBackward,
41    Stop,
42    GetStackInputVoltage,
43    GetExternalInputVoltage,
44    GetCurrentConsumption,
45    SetMotorCurrent,
46    GetMotorCurrent,
47    Enable,
48    Disable,
49    IsEnabled,
50    SetDecay,
51    GetDecay,
52    SetMinimumVoltage,
53    GetMinimumVoltage,
54    SetSyncRect,
55    IsSyncRect,
56    SetTimeBase,
57    GetTimeBase,
58    GetAllData,
59    SetAllDataPeriod,
60    GetAllDataPeriod,
61    SetSpitfpBaudrateConfig,
62    GetSpitfpBaudrateConfig,
63    GetSendTimeoutCount,
64    SetSpitfpBaudrate,
65    GetSpitfpBaudrate,
66    GetSpitfpErrorCount,
67    EnableStatusLed,
68    DisableStatusLed,
69    IsStatusLedEnabled,
70    GetProtocol1BrickletName,
71    GetChipTemperature,
72    Reset,
73    WriteBrickletPlugin,
74    ReadBrickletPlugin,
75    GetIdentity,
76    CallbackUnderVoltage,
77    CallbackPositionReached,
78    CallbackAllData,
79    CallbackNewState,
80}
81impl From<StepperBrickFunction> for u8 {
82    fn from(fun: StepperBrickFunction) -> Self {
83        match fun {
84            StepperBrickFunction::SetMaxVelocity => 1,
85            StepperBrickFunction::GetMaxVelocity => 2,
86            StepperBrickFunction::GetCurrentVelocity => 3,
87            StepperBrickFunction::SetSpeedRamping => 4,
88            StepperBrickFunction::GetSpeedRamping => 5,
89            StepperBrickFunction::FullBrake => 6,
90            StepperBrickFunction::SetCurrentPosition => 7,
91            StepperBrickFunction::GetCurrentPosition => 8,
92            StepperBrickFunction::SetTargetPosition => 9,
93            StepperBrickFunction::GetTargetPosition => 10,
94            StepperBrickFunction::SetSteps => 11,
95            StepperBrickFunction::GetSteps => 12,
96            StepperBrickFunction::GetRemainingSteps => 13,
97            StepperBrickFunction::SetStepMode => 14,
98            StepperBrickFunction::GetStepMode => 15,
99            StepperBrickFunction::DriveForward => 16,
100            StepperBrickFunction::DriveBackward => 17,
101            StepperBrickFunction::Stop => 18,
102            StepperBrickFunction::GetStackInputVoltage => 19,
103            StepperBrickFunction::GetExternalInputVoltage => 20,
104            StepperBrickFunction::GetCurrentConsumption => 21,
105            StepperBrickFunction::SetMotorCurrent => 22,
106            StepperBrickFunction::GetMotorCurrent => 23,
107            StepperBrickFunction::Enable => 24,
108            StepperBrickFunction::Disable => 25,
109            StepperBrickFunction::IsEnabled => 26,
110            StepperBrickFunction::SetDecay => 27,
111            StepperBrickFunction::GetDecay => 28,
112            StepperBrickFunction::SetMinimumVoltage => 29,
113            StepperBrickFunction::GetMinimumVoltage => 30,
114            StepperBrickFunction::SetSyncRect => 33,
115            StepperBrickFunction::IsSyncRect => 34,
116            StepperBrickFunction::SetTimeBase => 35,
117            StepperBrickFunction::GetTimeBase => 36,
118            StepperBrickFunction::GetAllData => 37,
119            StepperBrickFunction::SetAllDataPeriod => 38,
120            StepperBrickFunction::GetAllDataPeriod => 39,
121            StepperBrickFunction::SetSpitfpBaudrateConfig => 231,
122            StepperBrickFunction::GetSpitfpBaudrateConfig => 232,
123            StepperBrickFunction::GetSendTimeoutCount => 233,
124            StepperBrickFunction::SetSpitfpBaudrate => 234,
125            StepperBrickFunction::GetSpitfpBaudrate => 235,
126            StepperBrickFunction::GetSpitfpErrorCount => 237,
127            StepperBrickFunction::EnableStatusLed => 238,
128            StepperBrickFunction::DisableStatusLed => 239,
129            StepperBrickFunction::IsStatusLedEnabled => 240,
130            StepperBrickFunction::GetProtocol1BrickletName => 241,
131            StepperBrickFunction::GetChipTemperature => 242,
132            StepperBrickFunction::Reset => 243,
133            StepperBrickFunction::WriteBrickletPlugin => 246,
134            StepperBrickFunction::ReadBrickletPlugin => 247,
135            StepperBrickFunction::GetIdentity => 255,
136            StepperBrickFunction::CallbackUnderVoltage => 31,
137            StepperBrickFunction::CallbackPositionReached => 32,
138            StepperBrickFunction::CallbackAllData => 40,
139            StepperBrickFunction::CallbackNewState => 41,
140        }
141    }
142}
143pub const STEPPER_BRICK_STEP_MODE_FULL_STEP: u8 = 1;
144pub const STEPPER_BRICK_STEP_MODE_HALF_STEP: u8 = 2;
145pub const STEPPER_BRICK_STEP_MODE_QUARTER_STEP: u8 = 4;
146pub const STEPPER_BRICK_STEP_MODE_EIGHTH_STEP: u8 = 8;
147pub const STEPPER_BRICK_STATE_STOP: u8 = 1;
148pub const STEPPER_BRICK_STATE_ACCELERATION: u8 = 2;
149pub const STEPPER_BRICK_STATE_RUN: u8 = 3;
150pub const STEPPER_BRICK_STATE_DEACCELERATION: u8 = 4;
151pub const STEPPER_BRICK_STATE_DIRECTION_CHANGE_TO_FORWARD: u8 = 5;
152pub const STEPPER_BRICK_STATE_DIRECTION_CHANGE_TO_BACKWARD: u8 = 6;
153pub const STEPPER_BRICK_COMMUNICATION_METHOD_NONE: u8 = 0;
154pub const STEPPER_BRICK_COMMUNICATION_METHOD_USB: u8 = 1;
155pub const STEPPER_BRICK_COMMUNICATION_METHOD_SPI_STACK: u8 = 2;
156pub const STEPPER_BRICK_COMMUNICATION_METHOD_CHIBI: u8 = 3;
157pub const STEPPER_BRICK_COMMUNICATION_METHOD_RS485: u8 = 4;
158pub const STEPPER_BRICK_COMMUNICATION_METHOD_WIFI: u8 = 5;
159pub const STEPPER_BRICK_COMMUNICATION_METHOD_ETHERNET: u8 = 6;
160pub const STEPPER_BRICK_COMMUNICATION_METHOD_WIFI_V2: u8 = 7;
161
162#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
163pub struct SpeedRamping {
164    pub acceleration: u16,
165    pub deacceleration: u16,
166}
167impl FromByteSlice for SpeedRamping {
168    fn bytes_expected() -> usize {
169        4
170    }
171    fn from_le_byte_slice(bytes: &[u8]) -> SpeedRamping {
172        SpeedRamping { acceleration: <u16>::from_le_byte_slice(&bytes[0..2]), deacceleration: <u16>::from_le_byte_slice(&bytes[2..4]) }
173    }
174}
175
176#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
177pub struct AllData {
178    pub current_velocity: u16,
179    pub current_position: i32,
180    pub remaining_steps: i32,
181    pub stack_voltage: u16,
182    pub external_voltage: u16,
183    pub current_consumption: u16,
184}
185impl FromByteSlice for AllData {
186    fn bytes_expected() -> usize {
187        16
188    }
189    fn from_le_byte_slice(bytes: &[u8]) -> AllData {
190        AllData {
191            current_velocity: <u16>::from_le_byte_slice(&bytes[0..2]),
192            current_position: <i32>::from_le_byte_slice(&bytes[2..6]),
193            remaining_steps: <i32>::from_le_byte_slice(&bytes[6..10]),
194            stack_voltage: <u16>::from_le_byte_slice(&bytes[10..12]),
195            external_voltage: <u16>::from_le_byte_slice(&bytes[12..14]),
196            current_consumption: <u16>::from_le_byte_slice(&bytes[14..16]),
197        }
198    }
199}
200
201#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
202pub struct AllDataEvent {
203    pub current_velocity: u16,
204    pub current_position: i32,
205    pub remaining_steps: i32,
206    pub stack_voltage: u16,
207    pub external_voltage: u16,
208    pub current_consumption: u16,
209}
210impl FromByteSlice for AllDataEvent {
211    fn bytes_expected() -> usize {
212        16
213    }
214    fn from_le_byte_slice(bytes: &[u8]) -> AllDataEvent {
215        AllDataEvent {
216            current_velocity: <u16>::from_le_byte_slice(&bytes[0..2]),
217            current_position: <i32>::from_le_byte_slice(&bytes[2..6]),
218            remaining_steps: <i32>::from_le_byte_slice(&bytes[6..10]),
219            stack_voltage: <u16>::from_le_byte_slice(&bytes[10..12]),
220            external_voltage: <u16>::from_le_byte_slice(&bytes[12..14]),
221            current_consumption: <u16>::from_le_byte_slice(&bytes[14..16]),
222        }
223    }
224}
225
226#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
227pub struct NewStateEvent {
228    pub state_new: u8,
229    pub state_previous: u8,
230}
231impl FromByteSlice for NewStateEvent {
232    fn bytes_expected() -> usize {
233        2
234    }
235    fn from_le_byte_slice(bytes: &[u8]) -> NewStateEvent {
236        NewStateEvent { state_new: <u8>::from_le_byte_slice(&bytes[0..1]), state_previous: <u8>::from_le_byte_slice(&bytes[1..2]) }
237    }
238}
239
240#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
241pub struct SpitfpBaudrateConfig {
242    pub enable_dynamic_baudrate: bool,
243    pub minimum_dynamic_baudrate: u32,
244}
245impl FromByteSlice for SpitfpBaudrateConfig {
246    fn bytes_expected() -> usize {
247        5
248    }
249    fn from_le_byte_slice(bytes: &[u8]) -> SpitfpBaudrateConfig {
250        SpitfpBaudrateConfig {
251            enable_dynamic_baudrate: <bool>::from_le_byte_slice(&bytes[0..1]),
252            minimum_dynamic_baudrate: <u32>::from_le_byte_slice(&bytes[1..5]),
253        }
254    }
255}
256
257#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
258pub struct SpitfpErrorCount {
259    pub error_count_ack_checksum: u32,
260    pub error_count_message_checksum: u32,
261    pub error_count_frame: u32,
262    pub error_count_overflow: u32,
263}
264impl FromByteSlice for SpitfpErrorCount {
265    fn bytes_expected() -> usize {
266        16
267    }
268    fn from_le_byte_slice(bytes: &[u8]) -> SpitfpErrorCount {
269        SpitfpErrorCount {
270            error_count_ack_checksum: <u32>::from_le_byte_slice(&bytes[0..4]),
271            error_count_message_checksum: <u32>::from_le_byte_slice(&bytes[4..8]),
272            error_count_frame: <u32>::from_le_byte_slice(&bytes[8..12]),
273            error_count_overflow: <u32>::from_le_byte_slice(&bytes[12..16]),
274        }
275    }
276}
277
278#[derive(Clone)]
279pub struct Protocol1BrickletName {
280    pub protocol_version: u8,
281    pub firmware_version: [u8; 3],
282    pub name: String,
283}
284impl FromByteSlice for Protocol1BrickletName {
285    fn bytes_expected() -> usize {
286        44
287    }
288    fn from_le_byte_slice(bytes: &[u8]) -> Protocol1BrickletName {
289        Protocol1BrickletName {
290            protocol_version: <u8>::from_le_byte_slice(&bytes[0..1]),
291            firmware_version: <[u8; 3]>::from_le_byte_slice(&bytes[1..4]),
292            name: <String>::from_le_byte_slice(&bytes[4..44]),
293        }
294    }
295}
296
297#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
298pub struct Identity {
299    pub uid: String,
300    pub connected_uid: String,
301    pub position: char,
302    pub hardware_version: [u8; 3],
303    pub firmware_version: [u8; 3],
304    pub device_identifier: u16,
305}
306impl FromByteSlice for Identity {
307    fn bytes_expected() -> usize {
308        25
309    }
310    fn from_le_byte_slice(bytes: &[u8]) -> Identity {
311        Identity {
312            uid: <String>::from_le_byte_slice(&bytes[0..8]),
313            connected_uid: <String>::from_le_byte_slice(&bytes[8..16]),
314            position: <char>::from_le_byte_slice(&bytes[16..17]),
315            hardware_version: <[u8; 3]>::from_le_byte_slice(&bytes[17..20]),
316            firmware_version: <[u8; 3]>::from_le_byte_slice(&bytes[20..23]),
317            device_identifier: <u16>::from_le_byte_slice(&bytes[23..25]),
318        }
319    }
320}
321
322/// Drives one bipolar stepper motor with up to 38V and 2.5A per phase
323#[derive(Clone)]
324pub struct StepperBrick {
325    device: Device,
326}
327impl StepperBrick {
328    pub const DEVICE_IDENTIFIER: u16 = 15;
329    pub const DEVICE_DISPLAY_NAME: &'static str = "Stepper Brick";
330    /// Creates an object with the unique device ID `uid`. This object can then be used after the IP Connection `ip_connection` is connected.
331    pub fn new(uid: Uid, connection: AsyncIpConnection) -> StepperBrick {
332        let mut result = StepperBrick { device: Device::new([2, 0, 10], uid, connection, Self::DEVICE_DISPLAY_NAME) };
333        result.device.response_expected[u8::from(StepperBrickFunction::SetMaxVelocity) as usize] = ResponseExpectedFlag::False;
334        result.device.response_expected[u8::from(StepperBrickFunction::GetMaxVelocity) as usize] = ResponseExpectedFlag::AlwaysTrue;
335        result.device.response_expected[u8::from(StepperBrickFunction::GetCurrentVelocity) as usize] = ResponseExpectedFlag::AlwaysTrue;
336        result.device.response_expected[u8::from(StepperBrickFunction::SetSpeedRamping) as usize] = ResponseExpectedFlag::False;
337        result.device.response_expected[u8::from(StepperBrickFunction::GetSpeedRamping) as usize] = ResponseExpectedFlag::AlwaysTrue;
338        result.device.response_expected[u8::from(StepperBrickFunction::FullBrake) as usize] = ResponseExpectedFlag::False;
339        result.device.response_expected[u8::from(StepperBrickFunction::SetCurrentPosition) as usize] = ResponseExpectedFlag::False;
340        result.device.response_expected[u8::from(StepperBrickFunction::GetCurrentPosition) as usize] = ResponseExpectedFlag::AlwaysTrue;
341        result.device.response_expected[u8::from(StepperBrickFunction::SetTargetPosition) as usize] = ResponseExpectedFlag::False;
342        result.device.response_expected[u8::from(StepperBrickFunction::GetTargetPosition) as usize] = ResponseExpectedFlag::AlwaysTrue;
343        result.device.response_expected[u8::from(StepperBrickFunction::SetSteps) as usize] = ResponseExpectedFlag::False;
344        result.device.response_expected[u8::from(StepperBrickFunction::GetSteps) as usize] = ResponseExpectedFlag::AlwaysTrue;
345        result.device.response_expected[u8::from(StepperBrickFunction::GetRemainingSteps) as usize] = ResponseExpectedFlag::AlwaysTrue;
346        result.device.response_expected[u8::from(StepperBrickFunction::SetStepMode) as usize] = ResponseExpectedFlag::False;
347        result.device.response_expected[u8::from(StepperBrickFunction::GetStepMode) as usize] = ResponseExpectedFlag::AlwaysTrue;
348        result.device.response_expected[u8::from(StepperBrickFunction::DriveForward) as usize] = ResponseExpectedFlag::False;
349        result.device.response_expected[u8::from(StepperBrickFunction::DriveBackward) as usize] = ResponseExpectedFlag::False;
350        result.device.response_expected[u8::from(StepperBrickFunction::Stop) as usize] = ResponseExpectedFlag::False;
351        result.device.response_expected[u8::from(StepperBrickFunction::GetStackInputVoltage) as usize] = ResponseExpectedFlag::AlwaysTrue;
352        result.device.response_expected[u8::from(StepperBrickFunction::GetExternalInputVoltage) as usize] =
353            ResponseExpectedFlag::AlwaysTrue;
354        result.device.response_expected[u8::from(StepperBrickFunction::GetCurrentConsumption) as usize] = ResponseExpectedFlag::AlwaysTrue;
355        result.device.response_expected[u8::from(StepperBrickFunction::SetMotorCurrent) as usize] = ResponseExpectedFlag::False;
356        result.device.response_expected[u8::from(StepperBrickFunction::GetMotorCurrent) as usize] = ResponseExpectedFlag::AlwaysTrue;
357        result.device.response_expected[u8::from(StepperBrickFunction::Enable) as usize] = ResponseExpectedFlag::False;
358        result.device.response_expected[u8::from(StepperBrickFunction::Disable) as usize] = ResponseExpectedFlag::False;
359        result.device.response_expected[u8::from(StepperBrickFunction::IsEnabled) as usize] = ResponseExpectedFlag::AlwaysTrue;
360        result.device.response_expected[u8::from(StepperBrickFunction::SetDecay) as usize] = ResponseExpectedFlag::False;
361        result.device.response_expected[u8::from(StepperBrickFunction::GetDecay) as usize] = ResponseExpectedFlag::AlwaysTrue;
362        result.device.response_expected[u8::from(StepperBrickFunction::SetMinimumVoltage) as usize] = ResponseExpectedFlag::True;
363        result.device.response_expected[u8::from(StepperBrickFunction::GetMinimumVoltage) as usize] = ResponseExpectedFlag::AlwaysTrue;
364        result.device.response_expected[u8::from(StepperBrickFunction::SetSyncRect) as usize] = ResponseExpectedFlag::False;
365        result.device.response_expected[u8::from(StepperBrickFunction::IsSyncRect) as usize] = ResponseExpectedFlag::AlwaysTrue;
366        result.device.response_expected[u8::from(StepperBrickFunction::SetTimeBase) as usize] = ResponseExpectedFlag::False;
367        result.device.response_expected[u8::from(StepperBrickFunction::GetTimeBase) as usize] = ResponseExpectedFlag::AlwaysTrue;
368        result.device.response_expected[u8::from(StepperBrickFunction::GetAllData) as usize] = ResponseExpectedFlag::AlwaysTrue;
369        result.device.response_expected[u8::from(StepperBrickFunction::SetAllDataPeriod) as usize] = ResponseExpectedFlag::True;
370        result.device.response_expected[u8::from(StepperBrickFunction::GetAllDataPeriod) as usize] = ResponseExpectedFlag::AlwaysTrue;
371        result.device.response_expected[u8::from(StepperBrickFunction::SetSpitfpBaudrateConfig) as usize] = ResponseExpectedFlag::False;
372        result.device.response_expected[u8::from(StepperBrickFunction::GetSpitfpBaudrateConfig) as usize] =
373            ResponseExpectedFlag::AlwaysTrue;
374        result.device.response_expected[u8::from(StepperBrickFunction::GetSendTimeoutCount) as usize] = ResponseExpectedFlag::AlwaysTrue;
375        result.device.response_expected[u8::from(StepperBrickFunction::SetSpitfpBaudrate) as usize] = ResponseExpectedFlag::False;
376        result.device.response_expected[u8::from(StepperBrickFunction::GetSpitfpBaudrate) as usize] = ResponseExpectedFlag::AlwaysTrue;
377        result.device.response_expected[u8::from(StepperBrickFunction::GetSpitfpErrorCount) as usize] = ResponseExpectedFlag::AlwaysTrue;
378        result.device.response_expected[u8::from(StepperBrickFunction::EnableStatusLed) as usize] = ResponseExpectedFlag::False;
379        result.device.response_expected[u8::from(StepperBrickFunction::DisableStatusLed) as usize] = ResponseExpectedFlag::False;
380        result.device.response_expected[u8::from(StepperBrickFunction::IsStatusLedEnabled) as usize] = ResponseExpectedFlag::AlwaysTrue;
381        result.device.response_expected[u8::from(StepperBrickFunction::GetProtocol1BrickletName) as usize] =
382            ResponseExpectedFlag::AlwaysTrue;
383        result.device.response_expected[u8::from(StepperBrickFunction::GetChipTemperature) as usize] = ResponseExpectedFlag::AlwaysTrue;
384        result.device.response_expected[u8::from(StepperBrickFunction::Reset) as usize] = ResponseExpectedFlag::False;
385        result.device.response_expected[u8::from(StepperBrickFunction::WriteBrickletPlugin) as usize] = ResponseExpectedFlag::False;
386        result.device.response_expected[u8::from(StepperBrickFunction::ReadBrickletPlugin) as usize] = ResponseExpectedFlag::AlwaysTrue;
387        result.device.response_expected[u8::from(StepperBrickFunction::GetIdentity) as usize] = ResponseExpectedFlag::AlwaysTrue;
388        result
389    }
390
391    /// Returns the response expected flag for the function specified by the function ID parameter.
392    /// It is true if the function is expected to send a response, false otherwise.
393    ///
394    /// For getter functions this is enabled by default and cannot be disabled, because those
395    /// functions will always send a response. For callback configuration functions it is enabled
396    /// by default too, but can be disabled by [`set_response_expected`](crate::stepper_brick::StepperBrick::set_response_expected).
397    /// For setter functions it is disabled by default and can be enabled.
398    ///
399    /// Enabling the response expected flag for a setter function allows to detect timeouts
400    /// and other error conditions calls of this setter as well. The device will then send a response
401    /// for this purpose. If this flag is disabled for a setter function then no response is sent
402    /// and errors are silently ignored, because they cannot be detected.
403    ///
404    /// See [`set_response_expected`](crate::stepper_brick::StepperBrick::set_response_expected) for the list of function ID constants available for this function.
405    pub fn get_response_expected(&mut self, fun: StepperBrickFunction) -> Result<bool, GetResponseExpectedError> {
406        self.device.get_response_expected(u8::from(fun))
407    }
408
409    /// Changes the response expected flag of the function specified by the function ID parameter.
410    /// This flag can only be changed for setter (default value: false) and callback configuration
411    /// functions (default value: true). For getter functions it is always enabled.
412    ///
413    /// Enabling the response expected flag for a setter function allows to detect timeouts and
414    /// other error conditions calls of this setter as well. The device will then send a response
415    /// for this purpose. If this flag is disabled for a setter function then no response is sent
416    /// and errors are silently ignored, because they cannot be detected.
417    pub fn set_response_expected(&mut self, fun: StepperBrickFunction, response_expected: bool) -> Result<(), SetResponseExpectedError> {
418        self.device.set_response_expected(u8::from(fun), response_expected)
419    }
420
421    /// Changes the response expected flag for all setter and callback configuration functions of this device at once.
422    pub fn set_response_expected_all(&mut self, response_expected: bool) {
423        self.device.set_response_expected_all(response_expected)
424    }
425
426    /// Returns the version of the API definition (major, minor, revision) implemented by this API bindings.
427    /// This is neither the release version of this API bindings nor does it tell you anything about the represented Brick or Bricklet.
428    pub fn get_api_version(&self) -> [u8; 3] {
429        self.device.api_version
430    }
431
432    /// This receiver is triggered when the input voltage drops below the value set by
433    /// [`set_minimum_voltage`]. The parameter is the current voltage.
434    ///
435    /// [`set_minimum_voltage`]: #method.set_minimum_voltage
436    pub async fn get_under_voltage_callback_receiver(&mut self) -> impl Stream<Item = u16> {
437        self.device
438            .get_callback_receiver(u8::from(StepperBrickFunction::CallbackUnderVoltage))
439            .await
440            .map(|p| u16::from_le_byte_slice(p.body()))
441    }
442
443    /// This receiver is triggered when a position set by [`set_steps`] or
444    /// [`set_target_position`] is reached.
445    ///
446    /// # Note
447    ///  Since we can't get any feedback from the stepper motor, this only works if the
448    ///  acceleration (see [`set_speed_ramping`]) is set smaller or equal to the
449    ///  maximum acceleration of the motor. Otherwise the motor will lag behind the
450    ///  control value and the receiver will be triggered too early.
451    pub async fn get_position_reached_callback_receiver(&mut self) -> impl Stream<Item = i32> {
452        self.device
453            .get_callback_receiver(u8::from(StepperBrickFunction::CallbackPositionReached))
454            .await
455            .map(|p| i32::from_le_byte_slice(p.body()))
456    }
457
458    /// This receiver is triggered periodically with the period that is set by
459    /// [`set_all_data_period`]. The parameters are: the current velocity,
460    /// the current position, the remaining steps, the stack voltage, the external
461    /// voltage and the current consumption of the stepper motor.
462    pub async fn get_all_data_callback_receiver(&mut self) -> impl Stream<Item = AllDataEvent> {
463        self.device
464            .get_callback_receiver(u8::from(StepperBrickFunction::CallbackAllData))
465            .await
466            .map(|p| AllDataEvent::from_le_byte_slice(p.body()))
467    }
468
469    /// This receiver is triggered whenever the Stepper Brick enters a new state.
470    /// It returns the new state as well as the previous state.
471    pub async fn get_new_state_callback_receiver(&mut self) -> impl Stream<Item = NewStateEvent> {
472        self.device
473            .get_callback_receiver(u8::from(StepperBrickFunction::CallbackNewState))
474            .await
475            .map(|p| NewStateEvent::from_le_byte_slice(p.body()))
476    }
477
478    /// Sets the maximum velocity of the stepper motor.
479    /// This function does *not* start the motor, it merely sets the maximum
480    /// velocity the stepper motor is accelerated to. To get the motor running use
481    /// either [`set_target_position`], [`set_steps`], [`drive_forward`] or
482    /// [`drive_backward`].
483    pub async fn set_max_velocity(&mut self, velocity: u16) -> Result<(), TinkerforgeError> {
484        let mut payload = [0; 2];
485        velocity.write_to_slice(&mut payload[0..2]);
486
487        #[allow(unused_variables)]
488        let result = self.device.set(u8::from(StepperBrickFunction::SetMaxVelocity), &payload).await?;
489        Ok(())
490    }
491
492    /// Returns the velocity as set by [`set_max_velocity`].
493    pub async fn get_max_velocity(&mut self) -> Result<u16, TinkerforgeError> {
494        let payload = [0; 0];
495
496        #[allow(unused_variables)]
497        let result = self.device.get(u8::from(StepperBrickFunction::GetMaxVelocity), &payload).await?;
498        Ok(u16::from_le_byte_slice(result.body()))
499    }
500
501    /// Returns the *current* velocity of the stepper motor.
502    pub async fn get_current_velocity(&mut self) -> Result<u16, TinkerforgeError> {
503        let payload = [0; 0];
504
505        #[allow(unused_variables)]
506        let result = self.device.get(u8::from(StepperBrickFunction::GetCurrentVelocity), &payload).await?;
507        Ok(u16::from_le_byte_slice(result.body()))
508    }
509
510    /// Sets the acceleration and deacceleration of the stepper motor.
511    /// An acceleration of 1000 means, that
512    /// every second the velocity is increased by 1000 *steps/s*.
513    ///
514    /// For example: If the current velocity is 0 and you want to accelerate to a
515    /// velocity of 8000 *steps/s* in 10 seconds, you should set an acceleration
516    /// of 800 *steps/s²*.
517    ///
518    /// An acceleration/deacceleration of 0 means instantaneous
519    /// acceleration/deacceleration (not recommended)
520    pub async fn set_speed_ramping(&mut self, acceleration: u16, deacceleration: u16) -> Result<(), TinkerforgeError> {
521        let mut payload = [0; 4];
522        acceleration.write_to_slice(&mut payload[0..2]);
523        deacceleration.write_to_slice(&mut payload[2..4]);
524
525        #[allow(unused_variables)]
526        let result = self.device.set(u8::from(StepperBrickFunction::SetSpeedRamping), &payload).await?;
527        Ok(())
528    }
529
530    /// Returns the acceleration and deacceleration as set by
531    /// [`set_speed_ramping`].
532    pub async fn get_speed_ramping(&mut self) -> Result<SpeedRamping, TinkerforgeError> {
533        let payload = [0; 0];
534
535        #[allow(unused_variables)]
536        let result = self.device.get(u8::from(StepperBrickFunction::GetSpeedRamping), &payload).await?;
537        Ok(SpeedRamping::from_le_byte_slice(result.body()))
538    }
539
540    /// Executes an active full brake.
541    ///
542    /// # Warning
543    ///  This function is for emergency purposes,
544    ///  where an immediate brake is necessary. Depending on the current velocity and
545    ///  the strength of the motor, a full brake can be quite violent.
546    ///
547    /// Call [`stop`] if you just want to stop the motor.
548    pub async fn full_brake(&mut self) -> Result<(), TinkerforgeError> {
549        let payload = [0; 0];
550
551        #[allow(unused_variables)]
552        let result = self.device.set(u8::from(StepperBrickFunction::FullBrake), &payload).await?;
553        Ok(())
554    }
555
556    /// Sets the current steps of the internal step counter. This can be used to
557    /// set the current position to 0 when some kind of starting position
558    /// is reached (e.g. when a CNC machine reaches a corner).
559    pub async fn set_current_position(&mut self, position: i32) -> Result<(), TinkerforgeError> {
560        let mut payload = [0; 4];
561        position.write_to_slice(&mut payload[0..4]);
562
563        #[allow(unused_variables)]
564        let result = self.device.set(u8::from(StepperBrickFunction::SetCurrentPosition), &payload).await?;
565        Ok(())
566    }
567
568    /// Returns the current position of the stepper motor in steps. On startup
569    /// the position is 0. The steps are counted with all possible driving
570    /// functions ([`set_target_position`], [`set_steps`], [`drive_forward`] or
571    /// [`drive_backward`]). It also is possible to reset the steps to 0 or
572    /// set them to any other desired value with [`set_current_position`].
573    pub async fn get_current_position(&mut self) -> Result<i32, TinkerforgeError> {
574        let payload = [0; 0];
575
576        #[allow(unused_variables)]
577        let result = self.device.get(u8::from(StepperBrickFunction::GetCurrentPosition), &payload).await?;
578        Ok(i32::from_le_byte_slice(result.body()))
579    }
580
581    /// Sets the target position of the stepper motor in steps. For example,
582    /// if the current position of the motor is 500 and [`set_target_position`] is
583    /// called with 1000, the stepper motor will drive 500 steps forward. It will
584    /// use the velocity, acceleration and deacceleration as set by
585    /// [`set_max_velocity`] and [`set_speed_ramping`].
586    ///
587    /// A call of [`set_target_position`] with the parameter *x* is equivalent to
588    /// a call of [`set_steps`] with the parameter
589    /// (*x* - [`get_current_position`]).
590    pub async fn set_target_position(&mut self, position: i32) -> Result<(), TinkerforgeError> {
591        let mut payload = [0; 4];
592        position.write_to_slice(&mut payload[0..4]);
593
594        #[allow(unused_variables)]
595        let result = self.device.set(u8::from(StepperBrickFunction::SetTargetPosition), &payload).await?;
596        Ok(())
597    }
598
599    /// Returns the last target position as set by [`set_target_position`].
600    pub async fn get_target_position(&mut self) -> Result<i32, TinkerforgeError> {
601        let payload = [0; 0];
602
603        #[allow(unused_variables)]
604        let result = self.device.get(u8::from(StepperBrickFunction::GetTargetPosition), &payload).await?;
605        Ok(i32::from_le_byte_slice(result.body()))
606    }
607
608    /// Sets the number of steps the stepper motor should run. Positive values
609    /// will drive the motor forward and negative values backward.
610    /// The velocity, acceleration and deacceleration as set by
611    /// [`set_max_velocity`] and [`set_speed_ramping`] will be used.
612    pub async fn set_steps(&mut self, steps: i32) -> Result<(), TinkerforgeError> {
613        let mut payload = [0; 4];
614        steps.write_to_slice(&mut payload[0..4]);
615
616        #[allow(unused_variables)]
617        let result = self.device.set(u8::from(StepperBrickFunction::SetSteps), &payload).await?;
618        Ok(())
619    }
620
621    /// Returns the last steps as set by [`set_steps`].
622    pub async fn get_steps(&mut self) -> Result<i32, TinkerforgeError> {
623        let payload = [0; 0];
624
625        #[allow(unused_variables)]
626        let result = self.device.get(u8::from(StepperBrickFunction::GetSteps), &payload).await?;
627        Ok(i32::from_le_byte_slice(result.body()))
628    }
629
630    /// Returns the remaining steps of the last call of [`set_steps`].
631    /// For example, if [`set_steps`] is called with 2000 and
632    /// [`get_remaining_steps`] is called after the motor has run for 500 steps,
633    /// it will return 1500.
634    pub async fn get_remaining_steps(&mut self) -> Result<i32, TinkerforgeError> {
635        let payload = [0; 0];
636
637        #[allow(unused_variables)]
638        let result = self.device.get(u8::from(StepperBrickFunction::GetRemainingSteps), &payload).await?;
639        Ok(i32::from_le_byte_slice(result.body()))
640    }
641
642    /// Sets the step mode of the stepper motor. Possible values are:
643    ///
644    /// * Full Step = 1
645    /// * Half Step = 2
646    /// * Quarter Step = 4
647    /// * Eighth Step = 8
648    ///
649    /// A higher value will increase the resolution and
650    /// decrease the torque of the stepper motor.
651    ///
652    /// Associated constants:
653    /// * STEPPER_BRICK_STEP_MODE_FULL_STEP
654    ///	* STEPPER_BRICK_STEP_MODE_HALF_STEP
655    ///	* STEPPER_BRICK_STEP_MODE_QUARTER_STEP
656    ///	* STEPPER_BRICK_STEP_MODE_EIGHTH_STEP
657    pub async fn set_step_mode(&mut self, mode: u8) -> Result<(), TinkerforgeError> {
658        let mut payload = [0; 1];
659        mode.write_to_slice(&mut payload[0..1]);
660
661        #[allow(unused_variables)]
662        let result = self.device.set(u8::from(StepperBrickFunction::SetStepMode), &payload).await?;
663        Ok(())
664    }
665
666    /// Returns the step mode as set by [`set_step_mode`].
667    ///
668    /// Associated constants:
669    /// * STEPPER_BRICK_STEP_MODE_FULL_STEP
670    ///	* STEPPER_BRICK_STEP_MODE_HALF_STEP
671    ///	* STEPPER_BRICK_STEP_MODE_QUARTER_STEP
672    ///	* STEPPER_BRICK_STEP_MODE_EIGHTH_STEP
673    pub async fn get_step_mode(&mut self) -> Result<u8, TinkerforgeError> {
674        let payload = [0; 0];
675
676        #[allow(unused_variables)]
677        let result = self.device.get(u8::from(StepperBrickFunction::GetStepMode), &payload).await?;
678        Ok(u8::from_le_byte_slice(result.body()))
679    }
680
681    /// Drives the stepper motor forward until [`drive_backward`] or
682    /// [`stop`] is called. The velocity, acceleration and deacceleration as
683    /// set by [`set_max_velocity`] and [`set_speed_ramping`] will be used.
684    pub async fn drive_forward(&mut self) -> Result<(), TinkerforgeError> {
685        let payload = [0; 0];
686
687        #[allow(unused_variables)]
688        let result = self.device.set(u8::from(StepperBrickFunction::DriveForward), &payload).await?;
689        Ok(())
690    }
691
692    /// Drives the stepper motor backward until [`drive_forward`] or
693    /// [`stop`] is triggered. The velocity, acceleration and deacceleration as
694    /// set by [`set_max_velocity`] and [`set_speed_ramping`] will be used.
695    pub async fn drive_backward(&mut self) -> Result<(), TinkerforgeError> {
696        let payload = [0; 0];
697
698        #[allow(unused_variables)]
699        let result = self.device.set(u8::from(StepperBrickFunction::DriveBackward), &payload).await?;
700        Ok(())
701    }
702
703    /// Stops the stepper motor with the deacceleration as set by
704    /// [`set_speed_ramping`].
705    pub async fn stop(&mut self) -> Result<(), TinkerforgeError> {
706        let payload = [0; 0];
707
708        #[allow(unused_variables)]
709        let result = self.device.set(u8::from(StepperBrickFunction::Stop), &payload).await?;
710        Ok(())
711    }
712
713    /// Returns the stack input voltage. The stack input voltage is the
714    /// voltage that is supplied via the stack, i.e. it is given by a
715    /// Step-Down or Step-Up Power Supply.
716    pub async fn get_stack_input_voltage(&mut self) -> Result<u16, TinkerforgeError> {
717        let payload = [0; 0];
718
719        #[allow(unused_variables)]
720        let result = self.device.get(u8::from(StepperBrickFunction::GetStackInputVoltage), &payload).await?;
721        Ok(u16::from_le_byte_slice(result.body()))
722    }
723
724    /// Returns the external input voltage. The external input voltage is
725    /// given via the black power input connector on the Stepper Brick.
726    ///
727    /// If there is an external input voltage and a stack input voltage, the motor
728    /// will be driven by the external input voltage. If there is only a stack
729    /// voltage present, the motor will be driven by this voltage.
730    ///
731    /// # Warning
732    ///  This means, if you have a high stack voltage and a low external voltage,
733    ///  the motor will be driven with the low external voltage. If you then remove
734    ///  the external connection, it will immediately be driven by the high
735    ///  stack voltage
736    pub async fn get_external_input_voltage(&mut self) -> Result<u16, TinkerforgeError> {
737        let payload = [0; 0];
738
739        #[allow(unused_variables)]
740        let result = self.device.get(u8::from(StepperBrickFunction::GetExternalInputVoltage), &payload).await?;
741        Ok(u16::from_le_byte_slice(result.body()))
742    }
743
744    /// Returns the current consumption of the motor.
745    pub async fn get_current_consumption(&mut self) -> Result<u16, TinkerforgeError> {
746        let payload = [0; 0];
747
748        #[allow(unused_variables)]
749        let result = self.device.get(u8::from(StepperBrickFunction::GetCurrentConsumption), &payload).await?;
750        Ok(u16::from_le_byte_slice(result.body()))
751    }
752
753    /// Sets the current with which the motor will be driven.
754    ///
755    /// # Warning
756    ///  Do not set this value above the specifications of your stepper motor.
757    ///  Otherwise it may damage your motor.
758    pub async fn set_motor_current(&mut self, current: u16) -> Result<(), TinkerforgeError> {
759        let mut payload = [0; 2];
760        current.write_to_slice(&mut payload[0..2]);
761
762        #[allow(unused_variables)]
763        let result = self.device.set(u8::from(StepperBrickFunction::SetMotorCurrent), &payload).await?;
764        Ok(())
765    }
766
767    /// Returns the current as set by [`set_motor_current`].
768    pub async fn get_motor_current(&mut self) -> Result<u16, TinkerforgeError> {
769        let payload = [0; 0];
770
771        #[allow(unused_variables)]
772        let result = self.device.get(u8::from(StepperBrickFunction::GetMotorCurrent), &payload).await?;
773        Ok(u16::from_le_byte_slice(result.body()))
774    }
775
776    /// Enables the driver chip. The driver parameters can be configured (maximum velocity,
777    /// acceleration, etc) before it is enabled.
778    pub async fn enable(&mut self) -> Result<(), TinkerforgeError> {
779        let payload = [0; 0];
780
781        #[allow(unused_variables)]
782        let result = self.device.set(u8::from(StepperBrickFunction::Enable), &payload).await?;
783        Ok(())
784    }
785
786    /// Disables the driver chip. The configurations are kept (maximum velocity,
787    /// acceleration, etc) but the motor is not driven until it is enabled again.
788    ///
789    /// # Warning
790    ///  Disabling the driver chip while the motor is still turning can damage the
791    ///  driver chip. The motor should be stopped calling [`stop`] function
792    ///  before disabling the motor power. The [`stop`] function will **not**
793    ///  wait until the motor is actually stopped. You have to explicitly wait for the
794    ///  appropriate time after calling the [`stop`] function before calling
795    ///  the [`disable`] function.
796    pub async fn disable(&mut self) -> Result<(), TinkerforgeError> {
797        let payload = [0; 0];
798
799        #[allow(unused_variables)]
800        let result = self.device.set(u8::from(StepperBrickFunction::Disable), &payload).await?;
801        Ok(())
802    }
803
804    /// Returns *true* if the driver chip is enabled, *false* otherwise.
805    pub async fn is_enabled(&mut self) -> Result<bool, TinkerforgeError> {
806        let payload = [0; 0];
807
808        #[allow(unused_variables)]
809        let result = self.device.get(u8::from(StepperBrickFunction::IsEnabled), &payload).await?;
810        Ok(bool::from_le_byte_slice(result.body()))
811    }
812
813    /// Sets the decay mode of the stepper motor.
814    /// A value of 0 sets the fast decay mode, a value of
815    /// 65535 sets the slow decay mode and a value in between sets the mixed
816    /// decay mode.
817    ///
818    /// Changing the decay mode is only possible if synchronous rectification
819    /// is enabled (see :func:[Set Sync Rect`).
820    ///
821    /// For a good explanation of the different decay modes see
822    /// `this](https://ebldc.com/?p=86/)__ blog post by Avayan.
823    ///
824    /// A good decay mode is unfortunately different for every motor. The best
825    /// way to work out a good decay mode for your stepper motor, if you can't
826    /// measure the current with an oscilloscope, is to listen to the sound of
827    /// the motor. If the value is too low, you often hear a high pitched
828    /// sound and if it is too high you can often hear a humming sound.
829    ///
830    /// Generally, fast decay mode (small value) will be noisier but also
831    /// allow higher motor speeds.
832    ///
833    /// # Note
834    ///  There is unfortunately no formula to calculate a perfect decay
835    ///  mode for a given stepper motor. If you have problems with loud noises
836    ///  or the maximum motor speed is too slow, you should try to tinker with
837    ///  the decay value
838    pub async fn set_decay(&mut self, decay: u16) -> Result<(), TinkerforgeError> {
839        let mut payload = [0; 2];
840        decay.write_to_slice(&mut payload[0..2]);
841
842        #[allow(unused_variables)]
843        let result = self.device.set(u8::from(StepperBrickFunction::SetDecay), &payload).await?;
844        Ok(())
845    }
846
847    /// Returns the decay mode as set by [`set_decay`].
848    pub async fn get_decay(&mut self) -> Result<u16, TinkerforgeError> {
849        let payload = [0; 0];
850
851        #[allow(unused_variables)]
852        let result = self.device.get(u8::from(StepperBrickFunction::GetDecay), &payload).await?;
853        Ok(u16::from_le_byte_slice(result.body()))
854    }
855
856    /// Sets the minimum voltage, below which the [`get_under_voltage_callback_receiver`] receiver
857    /// is triggered. The minimum possible value that works with the Stepper Brick is 8V.
858    /// You can use this function to detect the discharge of a battery that is used
859    /// to drive the stepper motor. If you have a fixed power supply, you likely do
860    /// not need this functionality.
861    pub async fn set_minimum_voltage(&mut self, voltage: u16) -> Result<(), TinkerforgeError> {
862        let mut payload = [0; 2];
863        voltage.write_to_slice(&mut payload[0..2]);
864
865        #[allow(unused_variables)]
866        let result = self.device.set(u8::from(StepperBrickFunction::SetMinimumVoltage), &payload).await?;
867        Ok(())
868    }
869
870    /// Returns the minimum voltage as set by [`set_minimum_voltage`].
871    pub async fn get_minimum_voltage(&mut self) -> Result<u16, TinkerforgeError> {
872        let payload = [0; 0];
873
874        #[allow(unused_variables)]
875        let result = self.device.get(u8::from(StepperBrickFunction::GetMinimumVoltage), &payload).await?;
876        Ok(u16::from_le_byte_slice(result.body()))
877    }
878
879    /// Turns synchronous rectification on or off (*true* or *false*).
880    ///
881    /// With synchronous rectification on, the decay can be changed
882    /// (see :func:[Set Decay`). Without synchronous rectification fast
883    /// decay is used.
884    ///
885    /// For an explanation of synchronous rectification see
886    /// `here](https://en.wikipedia.org/wiki/Active_rectification)__.
887    ///
888    /// # Warning
889    ///  If you want to use high speeds (> 10000 steps/s) for a large
890    ///  stepper motor with a large inductivity we strongly
891    ///  suggest that you disable synchronous rectification. Otherwise the
892    ///  Brick may not be able to cope with the load and overheat.
893    pub async fn set_sync_rect(&mut self, sync_rect: bool) -> Result<(), TinkerforgeError> {
894        let mut payload = [0; 1];
895        sync_rect.write_to_slice(&mut payload[0..1]);
896
897        #[allow(unused_variables)]
898        let result = self.device.set(u8::from(StepperBrickFunction::SetSyncRect), &payload).await?;
899        Ok(())
900    }
901
902    /// Returns *true* if synchronous rectification is enabled, *false* otherwise.
903    pub async fn is_sync_rect(&mut self) -> Result<bool, TinkerforgeError> {
904        let payload = [0; 0];
905
906        #[allow(unused_variables)]
907        let result = self.device.get(u8::from(StepperBrickFunction::IsSyncRect), &payload).await?;
908        Ok(bool::from_le_byte_slice(result.body()))
909    }
910
911    /// Sets the time base of the velocity and the acceleration of the stepper brick.
912    ///
913    /// For example, if you want to make one step every 1.5 seconds, you can set
914    /// the time base to 15 and the velocity to 10. Now the velocity is
915    /// 10steps/15s = 1steps/1.5s.
916    pub async fn set_time_base(&mut self, time_base: u32) -> Result<(), TinkerforgeError> {
917        let mut payload = [0; 4];
918        time_base.write_to_slice(&mut payload[0..4]);
919
920        #[allow(unused_variables)]
921        let result = self.device.set(u8::from(StepperBrickFunction::SetTimeBase), &payload).await?;
922        Ok(())
923    }
924
925    /// Returns the time base as set by [`set_time_base`].
926    pub async fn get_time_base(&mut self) -> Result<u32, TinkerforgeError> {
927        let payload = [0; 0];
928
929        #[allow(unused_variables)]
930        let result = self.device.get(u8::from(StepperBrickFunction::GetTimeBase), &payload).await?;
931        Ok(u32::from_le_byte_slice(result.body()))
932    }
933
934    /// Returns the following parameters: The current velocity,
935    /// the current position, the remaining steps, the stack voltage, the external
936    /// voltage and the current consumption of the stepper motor.
937    ///
938    /// There is also a receiver for this function, see [`get_all_data_callback_receiver`] receiver.
939    pub async fn get_all_data(&mut self) -> Result<AllData, TinkerforgeError> {
940        let payload = [0; 0];
941
942        #[allow(unused_variables)]
943        let result = self.device.get(u8::from(StepperBrickFunction::GetAllData), &payload).await?;
944        Ok(AllData::from_le_byte_slice(result.body()))
945    }
946
947    /// Sets the period with which the [`get_all_data_callback_receiver`] receiver is triggered
948    /// periodically. A value of 0 turns the receiver off.
949    pub async fn set_all_data_period(&mut self, period: u32) -> Result<(), TinkerforgeError> {
950        let mut payload = [0; 4];
951        period.write_to_slice(&mut payload[0..4]);
952
953        #[allow(unused_variables)]
954        let result = self.device.set(u8::from(StepperBrickFunction::SetAllDataPeriod), &payload).await?;
955        Ok(())
956    }
957
958    /// Returns the period as set by [`set_all_data_period`].
959    pub async fn get_all_data_period(&mut self) -> Result<u32, TinkerforgeError> {
960        let payload = [0; 0];
961
962        #[allow(unused_variables)]
963        let result = self.device.get(u8::from(StepperBrickFunction::GetAllDataPeriod), &payload).await?;
964        Ok(u32::from_le_byte_slice(result.body()))
965    }
966
967    /// The SPITF protocol can be used with a dynamic baudrate. If the dynamic baudrate is
968    /// enabled, the Brick will try to adapt the baudrate for the communication
969    /// between Bricks and Bricklets according to the amount of data that is transferred.
970    ///
971    /// The baudrate will be increased exponentially if lots of data is sent/received and
972    /// decreased linearly if little data is sent/received.
973    ///
974    /// This lowers the baudrate in applications where little data is transferred (e.g.
975    /// a weather station) and increases the robustness. If there is lots of data to transfer
976    /// (e.g. Thermal Imaging Bricklet) it automatically increases the baudrate as needed.
977    ///
978    /// In cases where some data has to transferred as fast as possible every few seconds
979    /// (e.g. RS485 Bricklet with a high baudrate but small payload) you may want to turn
980    /// the dynamic baudrate off to get the highest possible performance.
981    ///
982    /// The maximum value of the baudrate can be set per port with the function
983    /// [`set_spitfp_baudrate`]. If the dynamic baudrate is disabled, the baudrate
984    /// as set by [`set_spitfp_baudrate`] will be used statically.
985    ///
986    ///
987    /// .. versionadded:: 2.3.6$nbsp;(Firmware)
988    pub async fn set_spitfp_baudrate_config(
989        &mut self,
990        enable_dynamic_baudrate: bool,
991        minimum_dynamic_baudrate: u32,
992    ) -> Result<(), TinkerforgeError> {
993        let mut payload = [0; 5];
994        enable_dynamic_baudrate.write_to_slice(&mut payload[0..1]);
995        minimum_dynamic_baudrate.write_to_slice(&mut payload[1..5]);
996
997        #[allow(unused_variables)]
998        let result = self.device.set(u8::from(StepperBrickFunction::SetSpitfpBaudrateConfig), &payload).await?;
999        Ok(())
1000    }
1001
1002    /// Returns the baudrate config, see [`set_spitfp_baudrate_config`].
1003    ///
1004    ///
1005    /// .. versionadded:: 2.3.6$nbsp;(Firmware)
1006    pub async fn get_spitfp_baudrate_config(&mut self) -> Result<SpitfpBaudrateConfig, TinkerforgeError> {
1007        let payload = [0; 0];
1008
1009        #[allow(unused_variables)]
1010        let result = self.device.get(u8::from(StepperBrickFunction::GetSpitfpBaudrateConfig), &payload).await?;
1011        Ok(SpitfpBaudrateConfig::from_le_byte_slice(result.body()))
1012    }
1013
1014    /// Returns the timeout count for the different communication methods.
1015    ///
1016    /// The methods 0-2 are available for all Bricks, 3-7 only for Master Bricks.
1017    ///
1018    /// This function is mostly used for debugging during development, in normal operation
1019    /// the counters should nearly always stay at 0.
1020    ///
1021    ///
1022    /// .. versionadded:: 2.3.4$nbsp;(Firmware)
1023    ///
1024    /// Associated constants:
1025    /// * STEPPER_BRICK_COMMUNICATION_METHOD_NONE
1026    ///	* STEPPER_BRICK_COMMUNICATION_METHOD_USB
1027    ///	* STEPPER_BRICK_COMMUNICATION_METHOD_SPI_STACK
1028    ///	* STEPPER_BRICK_COMMUNICATION_METHOD_CHIBI
1029    ///	* STEPPER_BRICK_COMMUNICATION_METHOD_RS485
1030    ///	* STEPPER_BRICK_COMMUNICATION_METHOD_WIFI
1031    ///	* STEPPER_BRICK_COMMUNICATION_METHOD_ETHERNET
1032    ///	* STEPPER_BRICK_COMMUNICATION_METHOD_WIFI_V2
1033    pub async fn get_send_timeout_count(&mut self, communication_method: u8) -> Result<u32, TinkerforgeError> {
1034        let mut payload = [0; 1];
1035        communication_method.write_to_slice(&mut payload[0..1]);
1036
1037        #[allow(unused_variables)]
1038        let result = self.device.get(u8::from(StepperBrickFunction::GetSendTimeoutCount), &payload).await?;
1039        Ok(u32::from_le_byte_slice(result.body()))
1040    }
1041
1042    /// Sets the baudrate for a specific Bricklet port.
1043    ///
1044    /// If you want to increase the throughput of Bricklets you can increase
1045    /// the baudrate. If you get a high error count because of high
1046    /// interference (see [`get_spitfp_error_count`]) you can decrease the
1047    /// baudrate.
1048    ///
1049    /// If the dynamic baudrate feature is enabled, the baudrate set by this
1050    /// function corresponds to the maximum baudrate (see [`set_spitfp_baudrate_config`]).
1051    ///
1052    /// Regulatory testing is done with the default baudrate. If CE compatibility
1053    /// or similar is necessary in your applications we recommend to not change
1054    /// the baudrate.
1055    ///
1056    ///
1057    /// .. versionadded:: 2.3.3$nbsp;(Firmware)
1058    pub async fn set_spitfp_baudrate(&mut self, bricklet_port: char, baudrate: u32) -> Result<(), TinkerforgeError> {
1059        let mut payload = [0; 5];
1060        bricklet_port.write_to_slice(&mut payload[0..1]);
1061        baudrate.write_to_slice(&mut payload[1..5]);
1062
1063        #[allow(unused_variables)]
1064        let result = self.device.set(u8::from(StepperBrickFunction::SetSpitfpBaudrate), &payload).await?;
1065        Ok(())
1066    }
1067
1068    /// Returns the baudrate for a given Bricklet port, see [`set_spitfp_baudrate`].
1069    ///
1070    ///
1071    /// .. versionadded:: 2.3.3$nbsp;(Firmware)
1072    pub async fn get_spitfp_baudrate(&mut self, bricklet_port: char) -> Result<u32, TinkerforgeError> {
1073        let mut payload = [0; 1];
1074        bricklet_port.write_to_slice(&mut payload[0..1]);
1075
1076        #[allow(unused_variables)]
1077        let result = self.device.get(u8::from(StepperBrickFunction::GetSpitfpBaudrate), &payload).await?;
1078        Ok(u32::from_le_byte_slice(result.body()))
1079    }
1080
1081    /// Returns the error count for the communication between Brick and Bricklet.
1082    ///
1083    /// The errors are divided into
1084    ///
1085    /// * ACK checksum errors,
1086    /// * message checksum errors,
1087    /// * framing errors and
1088    /// * overflow errors.
1089    ///
1090    /// The errors counts are for errors that occur on the Brick side. All
1091    /// Bricklets have a similar function that returns the errors on the Bricklet side.
1092    ///
1093    ///
1094    /// .. versionadded:: 2.3.3$nbsp;(Firmware)
1095    pub async fn get_spitfp_error_count(&mut self, bricklet_port: char) -> Result<SpitfpErrorCount, TinkerforgeError> {
1096        let mut payload = [0; 1];
1097        bricklet_port.write_to_slice(&mut payload[0..1]);
1098
1099        #[allow(unused_variables)]
1100        let result = self.device.get(u8::from(StepperBrickFunction::GetSpitfpErrorCount), &payload).await?;
1101        Ok(SpitfpErrorCount::from_le_byte_slice(result.body()))
1102    }
1103
1104    /// Enables the status LED.
1105    ///
1106    /// The status LED is the blue LED next to the USB connector. If enabled is is
1107    /// on and it flickers if data is transfered. If disabled it is always off.
1108    ///
1109    /// The default state is enabled.
1110    ///
1111    ///
1112    /// .. versionadded:: 2.3.1$nbsp;(Firmware)
1113    pub async fn enable_status_led(&mut self) -> Result<(), TinkerforgeError> {
1114        let payload = [0; 0];
1115
1116        #[allow(unused_variables)]
1117        let result = self.device.set(u8::from(StepperBrickFunction::EnableStatusLed), &payload).await?;
1118        Ok(())
1119    }
1120
1121    /// Disables the status LED.
1122    ///
1123    /// The status LED is the blue LED next to the USB connector. If enabled is is
1124    /// on and it flickers if data is transfered. If disabled it is always off.
1125    ///
1126    /// The default state is enabled.
1127    ///
1128    ///
1129    /// .. versionadded:: 2.3.1$nbsp;(Firmware)
1130    pub async fn disable_status_led(&mut self) -> Result<(), TinkerforgeError> {
1131        let payload = [0; 0];
1132
1133        #[allow(unused_variables)]
1134        let result = self.device.set(u8::from(StepperBrickFunction::DisableStatusLed), &payload).await?;
1135        Ok(())
1136    }
1137
1138    /// Returns *true* if the status LED is enabled, *false* otherwise.
1139    ///
1140    ///
1141    /// .. versionadded:: 2.3.1$nbsp;(Firmware)
1142    pub async fn is_status_led_enabled(&mut self) -> Result<bool, TinkerforgeError> {
1143        let payload = [0; 0];
1144
1145        #[allow(unused_variables)]
1146        let result = self.device.get(u8::from(StepperBrickFunction::IsStatusLedEnabled), &payload).await?;
1147        Ok(bool::from_le_byte_slice(result.body()))
1148    }
1149
1150    /// Returns the firmware and protocol version and the name of the Bricklet for a
1151    /// given port.
1152    ///
1153    /// This functions sole purpose is to allow automatic flashing of v1.x.y Bricklet
1154    /// plugins.
1155    pub async fn get_protocol1_bricklet_name(&mut self, port: char) -> Result<Protocol1BrickletName, TinkerforgeError> {
1156        let mut payload = [0; 1];
1157        port.write_to_slice(&mut payload[0..1]);
1158
1159        #[allow(unused_variables)]
1160        let result = self.device.get(u8::from(StepperBrickFunction::GetProtocol1BrickletName), &payload).await?;
1161        Ok(Protocol1BrickletName::from_le_byte_slice(result.body()))
1162    }
1163
1164    /// Returns the temperature as measured inside the microcontroller. The
1165    /// value returned is not the ambient temperature!
1166    ///
1167    /// The temperature is only proportional to the real temperature and it has an
1168    /// accuracy of ±15%. Practically it is only useful as an indicator for
1169    /// temperature changes.
1170    pub async fn get_chip_temperature(&mut self) -> Result<i16, TinkerforgeError> {
1171        let payload = [0; 0];
1172
1173        #[allow(unused_variables)]
1174        let result = self.device.get(u8::from(StepperBrickFunction::GetChipTemperature), &payload).await?;
1175        Ok(i16::from_le_byte_slice(result.body()))
1176    }
1177
1178    /// Calling this function will reset the Brick. Calling this function
1179    /// on a Brick inside of a stack will reset the whole stack.
1180    ///
1181    /// After a reset you have to create new device objects,
1182    /// calling functions on the existing ones will result in
1183    /// undefined behavior!
1184    pub async fn reset(&mut self) -> Result<(), TinkerforgeError> {
1185        let payload = [0; 0];
1186
1187        #[allow(unused_variables)]
1188        let result = self.device.set(u8::from(StepperBrickFunction::Reset), &payload).await?;
1189        Ok(())
1190    }
1191
1192    /// Writes 32 bytes of firmware to the bricklet attached at the given port.
1193    /// The bytes are written to the position offset * 32.
1194    ///
1195    /// This function is used by Brick Viewer during flashing. It should not be
1196    /// necessary to call it in a normal user program.
1197    pub async fn write_bricklet_plugin(&mut self, port: char, offset: u8, chunk: &[u8; 32]) -> Result<(), TinkerforgeError> {
1198        let mut payload = [0; 34];
1199        port.write_to_slice(&mut payload[0..1]);
1200        offset.write_to_slice(&mut payload[1..2]);
1201        chunk.write_to_slice(&mut payload[2..34]);
1202
1203        #[allow(unused_variables)]
1204        let result = self.device.set(u8::from(StepperBrickFunction::WriteBrickletPlugin), &payload).await?;
1205        Ok(())
1206    }
1207
1208    /// Reads 32 bytes of firmware from the bricklet attached at the given port.
1209    /// The bytes are read starting at the position offset * 32.
1210    ///
1211    /// This function is used by Brick Viewer during flashing. It should not be
1212    /// necessary to call it in a normal user program.
1213    pub async fn read_bricklet_plugin(&mut self, port: char, offset: u8) -> Result<Box<[u8; 32]>, TinkerforgeError> {
1214        let mut payload = [0; 2];
1215        port.write_to_slice(&mut payload[0..1]);
1216        offset.write_to_slice(&mut payload[1..2]);
1217
1218        #[allow(unused_variables)]
1219        let result = self.device.get(u8::from(StepperBrickFunction::ReadBrickletPlugin), &payload).await?;
1220        Ok(Box::<[u8; 32]>::from_le_byte_slice(result.body()))
1221    }
1222
1223    /// Returns the UID, the UID where the Brick is connected to,
1224    /// the position, the hardware and firmware version as well as the
1225    /// device identifier.
1226    ///
1227    /// The position is the position in the stack from '0' (bottom) to '8' (top).
1228    ///
1229    /// The device identifier numbers can be found [here](device_identifier).
1230    /// |device_identifier_constant|
1231    pub async fn get_identity(&mut self) -> Result<Identity, TinkerforgeError> {
1232        let payload = [0; 0];
1233
1234        #[allow(unused_variables)]
1235        let result = self.device.get(u8::from(StepperBrickFunction::GetIdentity), &payload).await?;
1236        Ok(Identity::from_le_byte_slice(result.body()))
1237    }
1238}