tinkerforge_async/bindings/
motorized_linear_poti_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//! Motorized Linear Potentiometer.
12//!
13//! See also the documentation [here](https://www.tinkerforge.com/en/doc/Software/Bricklets/MotorizedLinearPoti_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 MotorizedLinearPotiBrickletFunction {
24    GetPosition,
25    SetPositionCallbackConfiguration,
26    GetPositionCallbackConfiguration,
27    SetMotorPosition,
28    GetMotorPosition,
29    Calibrate,
30    SetPositionReachedCallbackConfiguration,
31    GetPositionReachedCallbackConfiguration,
32    GetSpitfpErrorCount,
33    SetBootloaderMode,
34    GetBootloaderMode,
35    SetWriteFirmwarePointer,
36    WriteFirmware,
37    SetStatusLedConfig,
38    GetStatusLedConfig,
39    GetChipTemperature,
40    Reset,
41    WriteUid,
42    ReadUid,
43    GetIdentity,
44    CallbackPosition,
45    CallbackPositionReached,
46}
47impl From<MotorizedLinearPotiBrickletFunction> for u8 {
48    fn from(fun: MotorizedLinearPotiBrickletFunction) -> Self {
49        match fun {
50            MotorizedLinearPotiBrickletFunction::GetPosition => 1,
51            MotorizedLinearPotiBrickletFunction::SetPositionCallbackConfiguration => 2,
52            MotorizedLinearPotiBrickletFunction::GetPositionCallbackConfiguration => 3,
53            MotorizedLinearPotiBrickletFunction::SetMotorPosition => 5,
54            MotorizedLinearPotiBrickletFunction::GetMotorPosition => 6,
55            MotorizedLinearPotiBrickletFunction::Calibrate => 7,
56            MotorizedLinearPotiBrickletFunction::SetPositionReachedCallbackConfiguration => 8,
57            MotorizedLinearPotiBrickletFunction::GetPositionReachedCallbackConfiguration => 9,
58            MotorizedLinearPotiBrickletFunction::GetSpitfpErrorCount => 234,
59            MotorizedLinearPotiBrickletFunction::SetBootloaderMode => 235,
60            MotorizedLinearPotiBrickletFunction::GetBootloaderMode => 236,
61            MotorizedLinearPotiBrickletFunction::SetWriteFirmwarePointer => 237,
62            MotorizedLinearPotiBrickletFunction::WriteFirmware => 238,
63            MotorizedLinearPotiBrickletFunction::SetStatusLedConfig => 239,
64            MotorizedLinearPotiBrickletFunction::GetStatusLedConfig => 240,
65            MotorizedLinearPotiBrickletFunction::GetChipTemperature => 242,
66            MotorizedLinearPotiBrickletFunction::Reset => 243,
67            MotorizedLinearPotiBrickletFunction::WriteUid => 248,
68            MotorizedLinearPotiBrickletFunction::ReadUid => 249,
69            MotorizedLinearPotiBrickletFunction::GetIdentity => 255,
70            MotorizedLinearPotiBrickletFunction::CallbackPosition => 4,
71            MotorizedLinearPotiBrickletFunction::CallbackPositionReached => 10,
72        }
73    }
74}
75pub const MOTORIZED_LINEAR_POTI_BRICKLET_THRESHOLD_OPTION_OFF: char = 'x';
76pub const MOTORIZED_LINEAR_POTI_BRICKLET_THRESHOLD_OPTION_OUTSIDE: char = 'o';
77pub const MOTORIZED_LINEAR_POTI_BRICKLET_THRESHOLD_OPTION_INSIDE: char = 'i';
78pub const MOTORIZED_LINEAR_POTI_BRICKLET_THRESHOLD_OPTION_SMALLER: char = '<';
79pub const MOTORIZED_LINEAR_POTI_BRICKLET_THRESHOLD_OPTION_GREATER: char = '>';
80pub const MOTORIZED_LINEAR_POTI_BRICKLET_DRIVE_MODE_FAST: u8 = 0;
81pub const MOTORIZED_LINEAR_POTI_BRICKLET_DRIVE_MODE_SMOOTH: u8 = 1;
82pub const MOTORIZED_LINEAR_POTI_BRICKLET_BOOTLOADER_MODE_BOOTLOADER: u8 = 0;
83pub const MOTORIZED_LINEAR_POTI_BRICKLET_BOOTLOADER_MODE_FIRMWARE: u8 = 1;
84pub const MOTORIZED_LINEAR_POTI_BRICKLET_BOOTLOADER_MODE_BOOTLOADER_WAIT_FOR_REBOOT: u8 = 2;
85pub const MOTORIZED_LINEAR_POTI_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_REBOOT: u8 = 3;
86pub const MOTORIZED_LINEAR_POTI_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_ERASE_AND_REBOOT: u8 = 4;
87pub const MOTORIZED_LINEAR_POTI_BRICKLET_BOOTLOADER_STATUS_OK: u8 = 0;
88pub const MOTORIZED_LINEAR_POTI_BRICKLET_BOOTLOADER_STATUS_INVALID_MODE: u8 = 1;
89pub const MOTORIZED_LINEAR_POTI_BRICKLET_BOOTLOADER_STATUS_NO_CHANGE: u8 = 2;
90pub const MOTORIZED_LINEAR_POTI_BRICKLET_BOOTLOADER_STATUS_ENTRY_FUNCTION_NOT_PRESENT: u8 = 3;
91pub const MOTORIZED_LINEAR_POTI_BRICKLET_BOOTLOADER_STATUS_DEVICE_IDENTIFIER_INCORRECT: u8 = 4;
92pub const MOTORIZED_LINEAR_POTI_BRICKLET_BOOTLOADER_STATUS_CRC_MISMATCH: u8 = 5;
93pub const MOTORIZED_LINEAR_POTI_BRICKLET_STATUS_LED_CONFIG_OFF: u8 = 0;
94pub const MOTORIZED_LINEAR_POTI_BRICKLET_STATUS_LED_CONFIG_ON: u8 = 1;
95pub const MOTORIZED_LINEAR_POTI_BRICKLET_STATUS_LED_CONFIG_SHOW_HEARTBEAT: u8 = 2;
96pub const MOTORIZED_LINEAR_POTI_BRICKLET_STATUS_LED_CONFIG_SHOW_STATUS: u8 = 3;
97
98#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
99pub struct PositionCallbackConfiguration {
100    pub period: u32,
101    pub value_has_to_change: bool,
102    pub option: char,
103    pub min: u16,
104    pub max: u16,
105}
106impl FromByteSlice for PositionCallbackConfiguration {
107    fn bytes_expected() -> usize {
108        10
109    }
110    fn from_le_byte_slice(bytes: &[u8]) -> PositionCallbackConfiguration {
111        PositionCallbackConfiguration {
112            period: <u32>::from_le_byte_slice(&bytes[0..4]),
113            value_has_to_change: <bool>::from_le_byte_slice(&bytes[4..5]),
114            option: <char>::from_le_byte_slice(&bytes[5..6]),
115            min: <u16>::from_le_byte_slice(&bytes[6..8]),
116            max: <u16>::from_le_byte_slice(&bytes[8..10]),
117        }
118    }
119}
120
121#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
122pub struct MotorPosition {
123    pub position: u16,
124    pub drive_mode: u8,
125    pub hold_position: bool,
126    pub position_reached: bool,
127}
128impl FromByteSlice for MotorPosition {
129    fn bytes_expected() -> usize {
130        5
131    }
132    fn from_le_byte_slice(bytes: &[u8]) -> MotorPosition {
133        MotorPosition {
134            position: <u16>::from_le_byte_slice(&bytes[0..2]),
135            drive_mode: <u8>::from_le_byte_slice(&bytes[2..3]),
136            hold_position: <bool>::from_le_byte_slice(&bytes[3..4]),
137            position_reached: <bool>::from_le_byte_slice(&bytes[4..5]),
138        }
139    }
140}
141
142#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
143pub struct SpitfpErrorCount {
144    pub error_count_ack_checksum: u32,
145    pub error_count_message_checksum: u32,
146    pub error_count_frame: u32,
147    pub error_count_overflow: u32,
148}
149impl FromByteSlice for SpitfpErrorCount {
150    fn bytes_expected() -> usize {
151        16
152    }
153    fn from_le_byte_slice(bytes: &[u8]) -> SpitfpErrorCount {
154        SpitfpErrorCount {
155            error_count_ack_checksum: <u32>::from_le_byte_slice(&bytes[0..4]),
156            error_count_message_checksum: <u32>::from_le_byte_slice(&bytes[4..8]),
157            error_count_frame: <u32>::from_le_byte_slice(&bytes[8..12]),
158            error_count_overflow: <u32>::from_le_byte_slice(&bytes[12..16]),
159        }
160    }
161}
162
163#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
164pub struct Identity {
165    pub uid: String,
166    pub connected_uid: String,
167    pub position: char,
168    pub hardware_version: [u8; 3],
169    pub firmware_version: [u8; 3],
170    pub device_identifier: u16,
171}
172impl FromByteSlice for Identity {
173    fn bytes_expected() -> usize {
174        25
175    }
176    fn from_le_byte_slice(bytes: &[u8]) -> Identity {
177        Identity {
178            uid: <String>::from_le_byte_slice(&bytes[0..8]),
179            connected_uid: <String>::from_le_byte_slice(&bytes[8..16]),
180            position: <char>::from_le_byte_slice(&bytes[16..17]),
181            hardware_version: <[u8; 3]>::from_le_byte_slice(&bytes[17..20]),
182            firmware_version: <[u8; 3]>::from_le_byte_slice(&bytes[20..23]),
183            device_identifier: <u16>::from_le_byte_slice(&bytes[23..25]),
184        }
185    }
186}
187
188/// Motorized Linear Potentiometer
189#[derive(Clone)]
190pub struct MotorizedLinearPotiBricklet {
191    device: Device,
192}
193impl MotorizedLinearPotiBricklet {
194    pub const DEVICE_IDENTIFIER: u16 = 267;
195    pub const DEVICE_DISPLAY_NAME: &'static str = "Motorized Linear Poti Bricklet";
196    /// Creates an object with the unique device ID `uid`. This object can then be used after the IP Connection `ip_connection` is connected.
197    pub fn new(uid: Uid, connection: AsyncIpConnection) -> MotorizedLinearPotiBricklet {
198        let mut result = MotorizedLinearPotiBricklet { device: Device::new([2, 0, 10], uid, connection, Self::DEVICE_DISPLAY_NAME) };
199        result.device.response_expected[u8::from(MotorizedLinearPotiBrickletFunction::GetPosition) as usize] =
200            ResponseExpectedFlag::AlwaysTrue;
201        result.device.response_expected[u8::from(MotorizedLinearPotiBrickletFunction::SetPositionCallbackConfiguration) as usize] =
202            ResponseExpectedFlag::True;
203        result.device.response_expected[u8::from(MotorizedLinearPotiBrickletFunction::GetPositionCallbackConfiguration) as usize] =
204            ResponseExpectedFlag::AlwaysTrue;
205        result.device.response_expected[u8::from(MotorizedLinearPotiBrickletFunction::SetMotorPosition) as usize] =
206            ResponseExpectedFlag::False;
207        result.device.response_expected[u8::from(MotorizedLinearPotiBrickletFunction::GetMotorPosition) as usize] =
208            ResponseExpectedFlag::AlwaysTrue;
209        result.device.response_expected[u8::from(MotorizedLinearPotiBrickletFunction::Calibrate) as usize] = ResponseExpectedFlag::False;
210        result.device.response_expected[u8::from(MotorizedLinearPotiBrickletFunction::SetPositionReachedCallbackConfiguration) as usize] =
211            ResponseExpectedFlag::True;
212        result.device.response_expected[u8::from(MotorizedLinearPotiBrickletFunction::GetPositionReachedCallbackConfiguration) as usize] =
213            ResponseExpectedFlag::AlwaysTrue;
214        result.device.response_expected[u8::from(MotorizedLinearPotiBrickletFunction::GetSpitfpErrorCount) as usize] =
215            ResponseExpectedFlag::AlwaysTrue;
216        result.device.response_expected[u8::from(MotorizedLinearPotiBrickletFunction::SetBootloaderMode) as usize] =
217            ResponseExpectedFlag::AlwaysTrue;
218        result.device.response_expected[u8::from(MotorizedLinearPotiBrickletFunction::GetBootloaderMode) as usize] =
219            ResponseExpectedFlag::AlwaysTrue;
220        result.device.response_expected[u8::from(MotorizedLinearPotiBrickletFunction::SetWriteFirmwarePointer) as usize] =
221            ResponseExpectedFlag::False;
222        result.device.response_expected[u8::from(MotorizedLinearPotiBrickletFunction::WriteFirmware) as usize] =
223            ResponseExpectedFlag::AlwaysTrue;
224        result.device.response_expected[u8::from(MotorizedLinearPotiBrickletFunction::SetStatusLedConfig) as usize] =
225            ResponseExpectedFlag::False;
226        result.device.response_expected[u8::from(MotorizedLinearPotiBrickletFunction::GetStatusLedConfig) as usize] =
227            ResponseExpectedFlag::AlwaysTrue;
228        result.device.response_expected[u8::from(MotorizedLinearPotiBrickletFunction::GetChipTemperature) as usize] =
229            ResponseExpectedFlag::AlwaysTrue;
230        result.device.response_expected[u8::from(MotorizedLinearPotiBrickletFunction::Reset) as usize] = ResponseExpectedFlag::False;
231        result.device.response_expected[u8::from(MotorizedLinearPotiBrickletFunction::WriteUid) as usize] = ResponseExpectedFlag::False;
232        result.device.response_expected[u8::from(MotorizedLinearPotiBrickletFunction::ReadUid) as usize] = ResponseExpectedFlag::AlwaysTrue;
233        result.device.response_expected[u8::from(MotorizedLinearPotiBrickletFunction::GetIdentity) as usize] =
234            ResponseExpectedFlag::AlwaysTrue;
235        result
236    }
237
238    /// Returns the response expected flag for the function specified by the function ID parameter.
239    /// It is true if the function is expected to send a response, false otherwise.
240    ///
241    /// For getter functions this is enabled by default and cannot be disabled, because those
242    /// functions will always send a response. For callback configuration functions it is enabled
243    /// by default too, but can be disabled by [`set_response_expected`](crate::motorized_linear_poti_bricklet::MotorizedLinearPotiBricklet::set_response_expected).
244    /// For setter functions it is disabled by default and can be enabled.
245    ///
246    /// Enabling the response expected flag for a setter function allows to detect timeouts
247    /// and other error conditions calls of this setter as well. The device will then send a response
248    /// for this purpose. If this flag is disabled for a setter function then no response is sent
249    /// and errors are silently ignored, because they cannot be detected.
250    ///
251    /// See [`set_response_expected`](crate::motorized_linear_poti_bricklet::MotorizedLinearPotiBricklet::set_response_expected) for the list of function ID constants available for this function.
252    pub fn get_response_expected(&mut self, fun: MotorizedLinearPotiBrickletFunction) -> Result<bool, GetResponseExpectedError> {
253        self.device.get_response_expected(u8::from(fun))
254    }
255
256    /// Changes the response expected flag of the function specified by the function ID parameter.
257    /// This flag can only be changed for setter (default value: false) and callback configuration
258    /// functions (default value: true). For getter functions it is always enabled.
259    ///
260    /// Enabling the response expected flag for a setter function allows to detect timeouts and
261    /// other error conditions calls of this setter as well. The device will then send a response
262    /// for this purpose. If this flag is disabled for a setter function then no response is sent
263    /// and errors are silently ignored, because they cannot be detected.
264    pub fn set_response_expected(
265        &mut self,
266        fun: MotorizedLinearPotiBrickletFunction,
267        response_expected: bool,
268    ) -> Result<(), SetResponseExpectedError> {
269        self.device.set_response_expected(u8::from(fun), response_expected)
270    }
271
272    /// Changes the response expected flag for all setter and callback configuration functions of this device at once.
273    pub fn set_response_expected_all(&mut self, response_expected: bool) {
274        self.device.set_response_expected_all(response_expected)
275    }
276
277    /// Returns the version of the API definition (major, minor, revision) implemented by this API bindings.
278    /// This is neither the release version of this API bindings nor does it tell you anything about the represented Brick or Bricklet.
279    pub fn get_api_version(&self) -> [u8; 3] {
280        self.device.api_version
281    }
282
283    /// This receiver is triggered periodically according to the configuration set by
284    /// [`set_position_callback_configuration`].
285    ///
286    /// The parameter is the same as [`get_position`].
287    ///
288    /// [`get_position`]: #method.get_position
289    /// [`set_position_callback_configuration`]: #method.set_position_callback_configuration
290    pub async fn get_position_callback_receiver(&mut self) -> impl Stream<Item = u16> {
291        self.device
292            .get_callback_receiver(u8::from(MotorizedLinearPotiBrickletFunction::CallbackPosition))
293            .await
294            .map(|p| u16::from_le_byte_slice(p.body()))
295    }
296
297    /// This receiver is triggered if a new position as set by
298    /// [`set_motor_position`] is reached.
299    ///
300    /// The parameter is the current position.
301    pub async fn get_position_reached_callback_receiver(&mut self) -> impl Stream<Item = u16> {
302        self.device
303            .get_callback_receiver(u8::from(MotorizedLinearPotiBrickletFunction::CallbackPositionReached))
304            .await
305            .map(|p| u16::from_le_byte_slice(p.body()))
306    }
307
308    /// Returns the position of the linear potentiometer. The value is
309    /// between 0 (slider down) and 100 (slider up).
310    ///
311    ///
312    /// If you want to get the value periodically, it is recommended to use the
313    /// [`get_position_callback_receiver`] receiver. You can set the receiver configuration
314    /// with [`set_position_callback_configuration`].
315    pub async fn get_position(&mut self) -> Result<u16, TinkerforgeError> {
316        let payload = [0; 0];
317
318        #[allow(unused_variables)]
319        let result = self.device.get(u8::from(MotorizedLinearPotiBrickletFunction::GetPosition), &payload).await?;
320        Ok(u16::from_le_byte_slice(result.body()))
321    }
322
323    /// The period is the period with which the [`get_position_callback_receiver`] receiver is triggered
324    /// periodically. A value of 0 turns the receiver off.
325    ///
326    /// If the `value has to change`-parameter is set to true, the receiver is only
327    /// triggered after the value has changed. If the value didn't change
328    /// within the period, the receiver is triggered immediately on change.
329    ///
330    /// If it is set to false, the receiver is continuously triggered with the period,
331    /// independent of the value.
332    ///
333    /// It is furthermore possible to constrain the receiver with thresholds.
334    ///
335    /// The `option`-parameter together with min/max sets a threshold for the [`get_position_callback_receiver`] receiver.
336    ///
337    /// The following options are possible:
338    ///
339    ///  Option| Description
340    ///  --- | ---
341    ///  'x'|    Threshold is turned off
342    ///  'o'|    Threshold is triggered when the value is *outside* the min and max values
343    ///  'i'|    Threshold is triggered when the value is *inside* or equal to the min and max values
344    ///  '<'|    Threshold is triggered when the value is smaller than the min value (max is ignored)
345    ///  '>'|    Threshold is triggered when the value is greater than the min value (max is ignored)
346    ///
347    /// If the option is set to 'x' (threshold turned off) the receiver is triggered with the fixed period.
348    ///
349    /// Associated constants:
350    /// * MOTORIZED_LINEAR_POTI_BRICKLET_THRESHOLD_OPTION_OFF
351    ///	* MOTORIZED_LINEAR_POTI_BRICKLET_THRESHOLD_OPTION_OUTSIDE
352    ///	* MOTORIZED_LINEAR_POTI_BRICKLET_THRESHOLD_OPTION_INSIDE
353    ///	* MOTORIZED_LINEAR_POTI_BRICKLET_THRESHOLD_OPTION_SMALLER
354    ///	* MOTORIZED_LINEAR_POTI_BRICKLET_THRESHOLD_OPTION_GREATER
355    pub async fn set_position_callback_configuration(
356        &mut self,
357        period: u32,
358        value_has_to_change: bool,
359        option: char,
360        min: u16,
361        max: u16,
362    ) -> Result<(), TinkerforgeError> {
363        let mut payload = [0; 10];
364        period.write_to_slice(&mut payload[0..4]);
365        value_has_to_change.write_to_slice(&mut payload[4..5]);
366        option.write_to_slice(&mut payload[5..6]);
367        min.write_to_slice(&mut payload[6..8]);
368        max.write_to_slice(&mut payload[8..10]);
369
370        #[allow(unused_variables)]
371        let result = self.device.set(u8::from(MotorizedLinearPotiBrickletFunction::SetPositionCallbackConfiguration), &payload).await?;
372        Ok(())
373    }
374
375    /// Returns the receiver configuration as set by [`set_position_callback_configuration`].
376    ///
377    /// Associated constants:
378    /// * MOTORIZED_LINEAR_POTI_BRICKLET_THRESHOLD_OPTION_OFF
379    ///	* MOTORIZED_LINEAR_POTI_BRICKLET_THRESHOLD_OPTION_OUTSIDE
380    ///	* MOTORIZED_LINEAR_POTI_BRICKLET_THRESHOLD_OPTION_INSIDE
381    ///	* MOTORIZED_LINEAR_POTI_BRICKLET_THRESHOLD_OPTION_SMALLER
382    ///	* MOTORIZED_LINEAR_POTI_BRICKLET_THRESHOLD_OPTION_GREATER
383    pub async fn get_position_callback_configuration(&mut self) -> Result<PositionCallbackConfiguration, TinkerforgeError> {
384        let payload = [0; 0];
385
386        #[allow(unused_variables)]
387        let result = self.device.get(u8::from(MotorizedLinearPotiBrickletFunction::GetPositionCallbackConfiguration), &payload).await?;
388        Ok(PositionCallbackConfiguration::from_le_byte_slice(result.body()))
389    }
390
391    /// Sets the position of the potentiometer. The motorized potentiometer will
392    /// immediately start to approach the position. Depending on the chosen drive mode,
393    /// the position will either be reached as fast as possible or in a slow but smooth
394    /// motion.
395    ///
396    /// The position has to be between 0 (slider down) and 100 (slider up).
397    ///
398    /// If you set the hold position parameter to true, the position will automatically
399    /// be retained. If a user changes the position of the potentiometer, it will
400    /// automatically drive back to the original set point.
401    ///
402    /// If the hold position parameter is set to false, the potentiometer can be changed
403    /// again by the user as soon as the set point was reached once.
404    ///
405    /// Associated constants:
406    /// * MOTORIZED_LINEAR_POTI_BRICKLET_DRIVE_MODE_FAST
407    ///	* MOTORIZED_LINEAR_POTI_BRICKLET_DRIVE_MODE_SMOOTH
408    pub async fn set_motor_position(&mut self, position: u16, drive_mode: u8, hold_position: bool) -> Result<(), TinkerforgeError> {
409        let mut payload = [0; 4];
410        position.write_to_slice(&mut payload[0..2]);
411        drive_mode.write_to_slice(&mut payload[2..3]);
412        hold_position.write_to_slice(&mut payload[3..4]);
413
414        #[allow(unused_variables)]
415        let result = self.device.set(u8::from(MotorizedLinearPotiBrickletFunction::SetMotorPosition), &payload).await?;
416        Ok(())
417    }
418
419    /// Returns the last motor position as set by [`set_motor_position`]. This is not
420    /// the current position (use [`get_position`] to get the current position). This
421    /// is the last used set point and configuration.
422    ///
423    /// The position reached parameter is true if the position has been reached at one point.
424    /// The position may have been changed again in the meantime by the user.
425    ///
426    /// Associated constants:
427    /// * MOTORIZED_LINEAR_POTI_BRICKLET_DRIVE_MODE_FAST
428    ///	* MOTORIZED_LINEAR_POTI_BRICKLET_DRIVE_MODE_SMOOTH
429    pub async fn get_motor_position(&mut self) -> Result<MotorPosition, TinkerforgeError> {
430        let payload = [0; 0];
431
432        #[allow(unused_variables)]
433        let result = self.device.get(u8::from(MotorizedLinearPotiBrickletFunction::GetMotorPosition), &payload).await?;
434        Ok(MotorPosition::from_le_byte_slice(result.body()))
435    }
436
437    /// Starts a calibration procedure. The potentiometer will be driven to the extreme
438    /// points to calibrate the potentiometer.
439    ///
440    /// The calibration is saved in flash, it does not have to be called on every start up.
441    ///
442    /// The Motorized Linear Poti Bricklet is already factory-calibrated during
443    /// testing at Tinkerforge.
444    pub async fn calibrate(&mut self) -> Result<(), TinkerforgeError> {
445        let payload = [0; 0];
446
447        #[allow(unused_variables)]
448        let result = self.device.set(u8::from(MotorizedLinearPotiBrickletFunction::Calibrate), &payload).await?;
449        Ok(())
450    }
451
452    /// Enables/Disables [`get_position_reached_callback_receiver`] receiver.
453    pub async fn set_position_reached_callback_configuration(&mut self, enabled: bool) -> Result<(), TinkerforgeError> {
454        let mut payload = [0; 1];
455        enabled.write_to_slice(&mut payload[0..1]);
456
457        #[allow(unused_variables)]
458        let result =
459            self.device.set(u8::from(MotorizedLinearPotiBrickletFunction::SetPositionReachedCallbackConfiguration), &payload).await?;
460        Ok(())
461    }
462
463    /// Returns the [`get_position_reached_callback_receiver`] receiver configuration
464    /// as set by [`set_position_reached_callback_configuration`].
465    pub async fn get_position_reached_callback_configuration(&mut self) -> Result<bool, TinkerforgeError> {
466        let payload = [0; 0];
467
468        #[allow(unused_variables)]
469        let result =
470            self.device.get(u8::from(MotorizedLinearPotiBrickletFunction::GetPositionReachedCallbackConfiguration), &payload).await?;
471        Ok(bool::from_le_byte_slice(result.body()))
472    }
473
474    /// Returns the error count for the communication between Brick and Bricklet.
475    ///
476    /// The errors are divided into
477    ///
478    /// * ACK checksum errors,
479    /// * message checksum errors,
480    /// * framing errors and
481    /// * overflow errors.
482    ///
483    /// The errors counts are for errors that occur on the Bricklet side. All
484    /// Bricks have a similar function that returns the errors on the Brick side.
485    pub async fn get_spitfp_error_count(&mut self) -> Result<SpitfpErrorCount, TinkerforgeError> {
486        let payload = [0; 0];
487
488        #[allow(unused_variables)]
489        let result = self.device.get(u8::from(MotorizedLinearPotiBrickletFunction::GetSpitfpErrorCount), &payload).await?;
490        Ok(SpitfpErrorCount::from_le_byte_slice(result.body()))
491    }
492
493    /// Sets the bootloader mode and returns the status after the requested
494    /// mode change was instigated.
495    ///
496    /// You can change from bootloader mode to firmware mode and vice versa. A change
497    /// from bootloader mode to firmware mode will only take place if the entry function,
498    /// device identifier and CRC are present and correct.
499    ///
500    /// This function is used by Brick Viewer during flashing. It should not be
501    /// necessary to call it in a normal user program.
502    ///
503    /// Associated constants:
504    /// * MOTORIZED_LINEAR_POTI_BRICKLET_BOOTLOADER_MODE_BOOTLOADER
505    ///	* MOTORIZED_LINEAR_POTI_BRICKLET_BOOTLOADER_MODE_FIRMWARE
506    ///	* MOTORIZED_LINEAR_POTI_BRICKLET_BOOTLOADER_MODE_BOOTLOADER_WAIT_FOR_REBOOT
507    ///	* MOTORIZED_LINEAR_POTI_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_REBOOT
508    ///	* MOTORIZED_LINEAR_POTI_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_ERASE_AND_REBOOT
509    ///	* MOTORIZED_LINEAR_POTI_BRICKLET_BOOTLOADER_STATUS_OK
510    ///	* MOTORIZED_LINEAR_POTI_BRICKLET_BOOTLOADER_STATUS_INVALID_MODE
511    ///	* MOTORIZED_LINEAR_POTI_BRICKLET_BOOTLOADER_STATUS_NO_CHANGE
512    ///	* MOTORIZED_LINEAR_POTI_BRICKLET_BOOTLOADER_STATUS_ENTRY_FUNCTION_NOT_PRESENT
513    ///	* MOTORIZED_LINEAR_POTI_BRICKLET_BOOTLOADER_STATUS_DEVICE_IDENTIFIER_INCORRECT
514    ///	* MOTORIZED_LINEAR_POTI_BRICKLET_BOOTLOADER_STATUS_CRC_MISMATCH
515    pub async fn set_bootloader_mode(&mut self, mode: u8) -> Result<u8, TinkerforgeError> {
516        let mut payload = [0; 1];
517        mode.write_to_slice(&mut payload[0..1]);
518
519        #[allow(unused_variables)]
520        let result = self.device.get(u8::from(MotorizedLinearPotiBrickletFunction::SetBootloaderMode), &payload).await?;
521        Ok(u8::from_le_byte_slice(result.body()))
522    }
523
524    /// Returns the current bootloader mode, see [`set_bootloader_mode`].
525    ///
526    /// Associated constants:
527    /// * MOTORIZED_LINEAR_POTI_BRICKLET_BOOTLOADER_MODE_BOOTLOADER
528    ///	* MOTORIZED_LINEAR_POTI_BRICKLET_BOOTLOADER_MODE_FIRMWARE
529    ///	* MOTORIZED_LINEAR_POTI_BRICKLET_BOOTLOADER_MODE_BOOTLOADER_WAIT_FOR_REBOOT
530    ///	* MOTORIZED_LINEAR_POTI_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_REBOOT
531    ///	* MOTORIZED_LINEAR_POTI_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_ERASE_AND_REBOOT
532    pub async fn get_bootloader_mode(&mut self) -> Result<u8, TinkerforgeError> {
533        let payload = [0; 0];
534
535        #[allow(unused_variables)]
536        let result = self.device.get(u8::from(MotorizedLinearPotiBrickletFunction::GetBootloaderMode), &payload).await?;
537        Ok(u8::from_le_byte_slice(result.body()))
538    }
539
540    /// Sets the firmware pointer for [`write_firmware`]. The pointer has
541    /// to be increased by chunks of size 64. The data is written to flash
542    /// every 4 chunks (which equals to one page of size 256).
543    ///
544    /// This function is used by Brick Viewer during flashing. It should not be
545    /// necessary to call it in a normal user program.
546    pub async fn set_write_firmware_pointer(&mut self, pointer: u32) -> Result<(), TinkerforgeError> {
547        let mut payload = [0; 4];
548        pointer.write_to_slice(&mut payload[0..4]);
549
550        #[allow(unused_variables)]
551        let result = self.device.set(u8::from(MotorizedLinearPotiBrickletFunction::SetWriteFirmwarePointer), &payload).await?;
552        Ok(())
553    }
554
555    /// Writes 64 Bytes of firmware at the position as written by
556    /// [`set_write_firmware_pointer`] before. The firmware is written
557    /// to flash every 4 chunks.
558    ///
559    /// You can only write firmware in bootloader mode.
560    ///
561    /// This function is used by Brick Viewer during flashing. It should not be
562    /// necessary to call it in a normal user program.
563    pub async fn write_firmware(&mut self, data: &[u8; 64]) -> Result<u8, TinkerforgeError> {
564        let mut payload = [0; 64];
565        data.write_to_slice(&mut payload[0..64]);
566
567        #[allow(unused_variables)]
568        let result = self.device.get(u8::from(MotorizedLinearPotiBrickletFunction::WriteFirmware), &payload).await?;
569        Ok(u8::from_le_byte_slice(result.body()))
570    }
571
572    /// Sets the status LED configuration. By default the LED shows
573    /// communication traffic between Brick and Bricklet, it flickers once
574    /// for every 10 received data packets.
575    ///
576    /// You can also turn the LED permanently on/off or show a heartbeat.
577    ///
578    /// If the Bricklet is in bootloader mode, the LED is will show heartbeat by default.
579    ///
580    /// Associated constants:
581    /// * MOTORIZED_LINEAR_POTI_BRICKLET_STATUS_LED_CONFIG_OFF
582    ///	* MOTORIZED_LINEAR_POTI_BRICKLET_STATUS_LED_CONFIG_ON
583    ///	* MOTORIZED_LINEAR_POTI_BRICKLET_STATUS_LED_CONFIG_SHOW_HEARTBEAT
584    ///	* MOTORIZED_LINEAR_POTI_BRICKLET_STATUS_LED_CONFIG_SHOW_STATUS
585    pub async fn set_status_led_config(&mut self, config: u8) -> Result<(), TinkerforgeError> {
586        let mut payload = [0; 1];
587        config.write_to_slice(&mut payload[0..1]);
588
589        #[allow(unused_variables)]
590        let result = self.device.set(u8::from(MotorizedLinearPotiBrickletFunction::SetStatusLedConfig), &payload).await?;
591        Ok(())
592    }
593
594    /// Returns the configuration as set by [`set_status_led_config`]
595    ///
596    /// Associated constants:
597    /// * MOTORIZED_LINEAR_POTI_BRICKLET_STATUS_LED_CONFIG_OFF
598    ///	* MOTORIZED_LINEAR_POTI_BRICKLET_STATUS_LED_CONFIG_ON
599    ///	* MOTORIZED_LINEAR_POTI_BRICKLET_STATUS_LED_CONFIG_SHOW_HEARTBEAT
600    ///	* MOTORIZED_LINEAR_POTI_BRICKLET_STATUS_LED_CONFIG_SHOW_STATUS
601    pub async fn get_status_led_config(&mut self) -> Result<u8, TinkerforgeError> {
602        let payload = [0; 0];
603
604        #[allow(unused_variables)]
605        let result = self.device.get(u8::from(MotorizedLinearPotiBrickletFunction::GetStatusLedConfig), &payload).await?;
606        Ok(u8::from_le_byte_slice(result.body()))
607    }
608
609    /// Returns the temperature as measured inside the microcontroller. The
610    /// value returned is not the ambient temperature!
611    ///
612    /// The temperature is only proportional to the real temperature and it has bad
613    /// accuracy. Practically it is only useful as an indicator for
614    /// temperature changes.
615    pub async fn get_chip_temperature(&mut self) -> Result<i16, TinkerforgeError> {
616        let payload = [0; 0];
617
618        #[allow(unused_variables)]
619        let result = self.device.get(u8::from(MotorizedLinearPotiBrickletFunction::GetChipTemperature), &payload).await?;
620        Ok(i16::from_le_byte_slice(result.body()))
621    }
622
623    /// Calling this function will reset the Bricklet. All configurations
624    /// will be lost.
625    ///
626    /// After a reset you have to create new device objects,
627    /// calling functions on the existing ones will result in
628    /// undefined behavior!
629    pub async fn reset(&mut self) -> Result<(), TinkerforgeError> {
630        let payload = [0; 0];
631
632        #[allow(unused_variables)]
633        let result = self.device.set(u8::from(MotorizedLinearPotiBrickletFunction::Reset), &payload).await?;
634        Ok(())
635    }
636
637    /// Writes a new UID into flash. If you want to set a new UID
638    /// you have to decode the Base58 encoded UID string into an
639    /// integer first.
640    ///
641    /// We recommend that you use Brick Viewer to change the UID.
642    pub async fn write_uid(&mut self, uid: u32) -> Result<(), TinkerforgeError> {
643        let mut payload = [0; 4];
644        uid.write_to_slice(&mut payload[0..4]);
645
646        #[allow(unused_variables)]
647        let result = self.device.set(u8::from(MotorizedLinearPotiBrickletFunction::WriteUid), &payload).await?;
648        Ok(())
649    }
650
651    /// Returns the current UID as an integer. Encode as
652    /// Base58 to get the usual string version.
653    pub async fn read_uid(&mut self) -> Result<u32, TinkerforgeError> {
654        let payload = [0; 0];
655
656        #[allow(unused_variables)]
657        let result = self.device.get(u8::from(MotorizedLinearPotiBrickletFunction::ReadUid), &payload).await?;
658        Ok(u32::from_le_byte_slice(result.body()))
659    }
660
661    /// Returns the UID, the UID where the Bricklet is connected to,
662    /// the position, the hardware and firmware version as well as the
663    /// device identifier.
664    ///
665    /// The position can be 'a', 'b', 'c', 'd', 'e', 'f', 'g' or 'h' (Bricklet Port).
666    /// A Bricklet connected to an [Isolator Bricklet](isolator_bricklet) is always at
667    /// position 'z'.
668    ///
669    /// The device identifier numbers can be found [here](device_identifier).
670    /// |device_identifier_constant|
671    pub async fn get_identity(&mut self) -> Result<Identity, TinkerforgeError> {
672        let payload = [0; 0];
673
674        #[allow(unused_variables)]
675        let result = self.device.get(u8::from(MotorizedLinearPotiBrickletFunction::GetIdentity), &payload).await?;
676        Ok(Identity::from_le_byte_slice(result.body()))
677    }
678}