tinkerforge_async/bindings/
linear_poti_v2_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//! 59mm linear potentiometer.
12//!
13//! See also the documentation [here](https://www.tinkerforge.com/en/doc/Software/Bricklets/LinearPotiV2_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 LinearPotiV2BrickletFunction {
24    GetPosition,
25    SetPositionCallbackConfiguration,
26    GetPositionCallbackConfiguration,
27    GetSpitfpErrorCount,
28    SetBootloaderMode,
29    GetBootloaderMode,
30    SetWriteFirmwarePointer,
31    WriteFirmware,
32    SetStatusLedConfig,
33    GetStatusLedConfig,
34    GetChipTemperature,
35    Reset,
36    WriteUid,
37    ReadUid,
38    GetIdentity,
39    CallbackPosition,
40}
41impl From<LinearPotiV2BrickletFunction> for u8 {
42    fn from(fun: LinearPotiV2BrickletFunction) -> Self {
43        match fun {
44            LinearPotiV2BrickletFunction::GetPosition => 1,
45            LinearPotiV2BrickletFunction::SetPositionCallbackConfiguration => 2,
46            LinearPotiV2BrickletFunction::GetPositionCallbackConfiguration => 3,
47            LinearPotiV2BrickletFunction::GetSpitfpErrorCount => 234,
48            LinearPotiV2BrickletFunction::SetBootloaderMode => 235,
49            LinearPotiV2BrickletFunction::GetBootloaderMode => 236,
50            LinearPotiV2BrickletFunction::SetWriteFirmwarePointer => 237,
51            LinearPotiV2BrickletFunction::WriteFirmware => 238,
52            LinearPotiV2BrickletFunction::SetStatusLedConfig => 239,
53            LinearPotiV2BrickletFunction::GetStatusLedConfig => 240,
54            LinearPotiV2BrickletFunction::GetChipTemperature => 242,
55            LinearPotiV2BrickletFunction::Reset => 243,
56            LinearPotiV2BrickletFunction::WriteUid => 248,
57            LinearPotiV2BrickletFunction::ReadUid => 249,
58            LinearPotiV2BrickletFunction::GetIdentity => 255,
59            LinearPotiV2BrickletFunction::CallbackPosition => 4,
60        }
61    }
62}
63pub const LINEAR_POTI_V2_BRICKLET_THRESHOLD_OPTION_OFF: char = 'x';
64pub const LINEAR_POTI_V2_BRICKLET_THRESHOLD_OPTION_OUTSIDE: char = 'o';
65pub const LINEAR_POTI_V2_BRICKLET_THRESHOLD_OPTION_INSIDE: char = 'i';
66pub const LINEAR_POTI_V2_BRICKLET_THRESHOLD_OPTION_SMALLER: char = '<';
67pub const LINEAR_POTI_V2_BRICKLET_THRESHOLD_OPTION_GREATER: char = '>';
68pub const LINEAR_POTI_V2_BRICKLET_BOOTLOADER_MODE_BOOTLOADER: u8 = 0;
69pub const LINEAR_POTI_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE: u8 = 1;
70pub const LINEAR_POTI_V2_BRICKLET_BOOTLOADER_MODE_BOOTLOADER_WAIT_FOR_REBOOT: u8 = 2;
71pub const LINEAR_POTI_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_REBOOT: u8 = 3;
72pub const LINEAR_POTI_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_ERASE_AND_REBOOT: u8 = 4;
73pub const LINEAR_POTI_V2_BRICKLET_BOOTLOADER_STATUS_OK: u8 = 0;
74pub const LINEAR_POTI_V2_BRICKLET_BOOTLOADER_STATUS_INVALID_MODE: u8 = 1;
75pub const LINEAR_POTI_V2_BRICKLET_BOOTLOADER_STATUS_NO_CHANGE: u8 = 2;
76pub const LINEAR_POTI_V2_BRICKLET_BOOTLOADER_STATUS_ENTRY_FUNCTION_NOT_PRESENT: u8 = 3;
77pub const LINEAR_POTI_V2_BRICKLET_BOOTLOADER_STATUS_DEVICE_IDENTIFIER_INCORRECT: u8 = 4;
78pub const LINEAR_POTI_V2_BRICKLET_BOOTLOADER_STATUS_CRC_MISMATCH: u8 = 5;
79pub const LINEAR_POTI_V2_BRICKLET_STATUS_LED_CONFIG_OFF: u8 = 0;
80pub const LINEAR_POTI_V2_BRICKLET_STATUS_LED_CONFIG_ON: u8 = 1;
81pub const LINEAR_POTI_V2_BRICKLET_STATUS_LED_CONFIG_SHOW_HEARTBEAT: u8 = 2;
82pub const LINEAR_POTI_V2_BRICKLET_STATUS_LED_CONFIG_SHOW_STATUS: u8 = 3;
83
84#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
85pub struct PositionCallbackConfiguration {
86    pub period: u32,
87    pub value_has_to_change: bool,
88    pub option: char,
89    pub min: u8,
90    pub max: u8,
91}
92impl FromByteSlice for PositionCallbackConfiguration {
93    fn bytes_expected() -> usize {
94        8
95    }
96    fn from_le_byte_slice(bytes: &[u8]) -> PositionCallbackConfiguration {
97        PositionCallbackConfiguration {
98            period: <u32>::from_le_byte_slice(&bytes[0..4]),
99            value_has_to_change: <bool>::from_le_byte_slice(&bytes[4..5]),
100            option: <char>::from_le_byte_slice(&bytes[5..6]),
101            min: <u8>::from_le_byte_slice(&bytes[6..7]),
102            max: <u8>::from_le_byte_slice(&bytes[7..8]),
103        }
104    }
105}
106
107#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
108pub struct SpitfpErrorCount {
109    pub error_count_ack_checksum: u32,
110    pub error_count_message_checksum: u32,
111    pub error_count_frame: u32,
112    pub error_count_overflow: u32,
113}
114impl FromByteSlice for SpitfpErrorCount {
115    fn bytes_expected() -> usize {
116        16
117    }
118    fn from_le_byte_slice(bytes: &[u8]) -> SpitfpErrorCount {
119        SpitfpErrorCount {
120            error_count_ack_checksum: <u32>::from_le_byte_slice(&bytes[0..4]),
121            error_count_message_checksum: <u32>::from_le_byte_slice(&bytes[4..8]),
122            error_count_frame: <u32>::from_le_byte_slice(&bytes[8..12]),
123            error_count_overflow: <u32>::from_le_byte_slice(&bytes[12..16]),
124        }
125    }
126}
127
128#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
129pub struct Identity {
130    pub uid: String,
131    pub connected_uid: String,
132    pub position: char,
133    pub hardware_version: [u8; 3],
134    pub firmware_version: [u8; 3],
135    pub device_identifier: u16,
136}
137impl FromByteSlice for Identity {
138    fn bytes_expected() -> usize {
139        25
140    }
141    fn from_le_byte_slice(bytes: &[u8]) -> Identity {
142        Identity {
143            uid: <String>::from_le_byte_slice(&bytes[0..8]),
144            connected_uid: <String>::from_le_byte_slice(&bytes[8..16]),
145            position: <char>::from_le_byte_slice(&bytes[16..17]),
146            hardware_version: <[u8; 3]>::from_le_byte_slice(&bytes[17..20]),
147            firmware_version: <[u8; 3]>::from_le_byte_slice(&bytes[20..23]),
148            device_identifier: <u16>::from_le_byte_slice(&bytes[23..25]),
149        }
150    }
151}
152
153/// 59mm linear potentiometer
154#[derive(Clone)]
155pub struct LinearPotiV2Bricklet {
156    device: Device,
157}
158impl LinearPotiV2Bricklet {
159    pub const DEVICE_IDENTIFIER: u16 = 2139;
160    pub const DEVICE_DISPLAY_NAME: &'static str = "Linear Poti Bricklet 2.0";
161    /// Creates an object with the unique device ID `uid`. This object can then be used after the IP Connection `ip_connection` is connected.
162    pub fn new(uid: Uid, connection: AsyncIpConnection) -> LinearPotiV2Bricklet {
163        let mut result = LinearPotiV2Bricklet { device: Device::new([2, 0, 10], uid, connection, Self::DEVICE_DISPLAY_NAME) };
164        result.device.response_expected[u8::from(LinearPotiV2BrickletFunction::GetPosition) as usize] = ResponseExpectedFlag::AlwaysTrue;
165        result.device.response_expected[u8::from(LinearPotiV2BrickletFunction::SetPositionCallbackConfiguration) as usize] =
166            ResponseExpectedFlag::True;
167        result.device.response_expected[u8::from(LinearPotiV2BrickletFunction::GetPositionCallbackConfiguration) as usize] =
168            ResponseExpectedFlag::AlwaysTrue;
169        result.device.response_expected[u8::from(LinearPotiV2BrickletFunction::GetSpitfpErrorCount) as usize] =
170            ResponseExpectedFlag::AlwaysTrue;
171        result.device.response_expected[u8::from(LinearPotiV2BrickletFunction::SetBootloaderMode) as usize] =
172            ResponseExpectedFlag::AlwaysTrue;
173        result.device.response_expected[u8::from(LinearPotiV2BrickletFunction::GetBootloaderMode) as usize] =
174            ResponseExpectedFlag::AlwaysTrue;
175        result.device.response_expected[u8::from(LinearPotiV2BrickletFunction::SetWriteFirmwarePointer) as usize] =
176            ResponseExpectedFlag::False;
177        result.device.response_expected[u8::from(LinearPotiV2BrickletFunction::WriteFirmware) as usize] = ResponseExpectedFlag::AlwaysTrue;
178        result.device.response_expected[u8::from(LinearPotiV2BrickletFunction::SetStatusLedConfig) as usize] = ResponseExpectedFlag::False;
179        result.device.response_expected[u8::from(LinearPotiV2BrickletFunction::GetStatusLedConfig) as usize] =
180            ResponseExpectedFlag::AlwaysTrue;
181        result.device.response_expected[u8::from(LinearPotiV2BrickletFunction::GetChipTemperature) as usize] =
182            ResponseExpectedFlag::AlwaysTrue;
183        result.device.response_expected[u8::from(LinearPotiV2BrickletFunction::Reset) as usize] = ResponseExpectedFlag::False;
184        result.device.response_expected[u8::from(LinearPotiV2BrickletFunction::WriteUid) as usize] = ResponseExpectedFlag::False;
185        result.device.response_expected[u8::from(LinearPotiV2BrickletFunction::ReadUid) as usize] = ResponseExpectedFlag::AlwaysTrue;
186        result.device.response_expected[u8::from(LinearPotiV2BrickletFunction::GetIdentity) as usize] = ResponseExpectedFlag::AlwaysTrue;
187        result
188    }
189
190    /// Returns the response expected flag for the function specified by the function ID parameter.
191    /// It is true if the function is expected to send a response, false otherwise.
192    ///
193    /// For getter functions this is enabled by default and cannot be disabled, because those
194    /// functions will always send a response. For callback configuration functions it is enabled
195    /// by default too, but can be disabled by [`set_response_expected`](crate::linear_poti_v2_bricklet::LinearPotiV2Bricklet::set_response_expected).
196    /// For setter functions it is disabled by default and can be enabled.
197    ///
198    /// Enabling the response expected flag for a setter function allows to detect timeouts
199    /// and other error conditions calls of this setter as well. The device will then send a response
200    /// for this purpose. If this flag is disabled for a setter function then no response is sent
201    /// and errors are silently ignored, because they cannot be detected.
202    ///
203    /// See [`set_response_expected`](crate::linear_poti_v2_bricklet::LinearPotiV2Bricklet::set_response_expected) for the list of function ID constants available for this function.
204    pub fn get_response_expected(&mut self, fun: LinearPotiV2BrickletFunction) -> Result<bool, GetResponseExpectedError> {
205        self.device.get_response_expected(u8::from(fun))
206    }
207
208    /// Changes the response expected flag of the function specified by the function ID parameter.
209    /// This flag can only be changed for setter (default value: false) and callback configuration
210    /// functions (default value: true). For getter functions it is always enabled.
211    ///
212    /// Enabling the response expected flag for a setter function allows to detect timeouts and
213    /// other error conditions calls of this setter as well. The device will then send a response
214    /// for this purpose. If this flag is disabled for a setter function then no response is sent
215    /// and errors are silently ignored, because they cannot be detected.
216    pub fn set_response_expected(
217        &mut self,
218        fun: LinearPotiV2BrickletFunction,
219        response_expected: bool,
220    ) -> Result<(), SetResponseExpectedError> {
221        self.device.set_response_expected(u8::from(fun), response_expected)
222    }
223
224    /// Changes the response expected flag for all setter and callback configuration functions of this device at once.
225    pub fn set_response_expected_all(&mut self, response_expected: bool) {
226        self.device.set_response_expected_all(response_expected)
227    }
228
229    /// Returns the version of the API definition (major, minor, revision) implemented by this API bindings.
230    /// This is neither the release version of this API bindings nor does it tell you anything about the represented Brick or Bricklet.
231    pub fn get_api_version(&self) -> [u8; 3] {
232        self.device.api_version
233    }
234
235    /// This receiver is triggered periodically according to the configuration set by
236    /// [`set_position_callback_configuration`].
237    ///
238    /// The parameter is the same as [`get_position`].
239    ///
240    /// [`get_position`]: #method.get_position
241    /// [`set_position_callback_configuration`]: #method.set_position_callback_configuration
242    pub async fn get_position_callback_receiver(&mut self) -> impl Stream<Item = u8> {
243        self.device
244            .get_callback_receiver(u8::from(LinearPotiV2BrickletFunction::CallbackPosition))
245            .await
246            .map(|p| u8::from_le_byte_slice(p.body()))
247    }
248
249    /// Returns the position of the linear potentiometer. The value is
250    /// between 0% (slider down) and 100% (slider up).
251    ///
252    ///
253    /// If you want to get the value periodically, it is recommended to use the
254    /// [`get_position_callback_receiver`] receiver. You can set the receiver configuration
255    /// with [`set_position_callback_configuration`].
256    pub async fn get_position(&mut self) -> Result<u8, TinkerforgeError> {
257        let payload = [0; 0];
258
259        #[allow(unused_variables)]
260        let result = self.device.get(u8::from(LinearPotiV2BrickletFunction::GetPosition), &payload).await?;
261        Ok(u8::from_le_byte_slice(result.body()))
262    }
263
264    /// The period is the period with which the [`get_position_callback_receiver`] receiver is triggered
265    /// periodically. A value of 0 turns the receiver off.
266    ///
267    /// If the `value has to change`-parameter is set to true, the receiver is only
268    /// triggered after the value has changed. If the value didn't change
269    /// within the period, the receiver is triggered immediately on change.
270    ///
271    /// If it is set to false, the receiver is continuously triggered with the period,
272    /// independent of the value.
273    ///
274    /// It is furthermore possible to constrain the receiver with thresholds.
275    ///
276    /// The `option`-parameter together with min/max sets a threshold for the [`get_position_callback_receiver`] receiver.
277    ///
278    /// The following options are possible:
279    ///
280    ///  Option| Description
281    ///  --- | ---
282    ///  'x'|    Threshold is turned off
283    ///  'o'|    Threshold is triggered when the value is *outside* the min and max values
284    ///  'i'|    Threshold is triggered when the value is *inside* or equal to the min and max values
285    ///  '<'|    Threshold is triggered when the value is smaller than the min value (max is ignored)
286    ///  '>'|    Threshold is triggered when the value is greater than the min value (max is ignored)
287    ///
288    /// If the option is set to 'x' (threshold turned off) the receiver is triggered with the fixed period.
289    ///
290    /// Associated constants:
291    /// * LINEAR_POTI_V2_BRICKLET_THRESHOLD_OPTION_OFF
292    ///	* LINEAR_POTI_V2_BRICKLET_THRESHOLD_OPTION_OUTSIDE
293    ///	* LINEAR_POTI_V2_BRICKLET_THRESHOLD_OPTION_INSIDE
294    ///	* LINEAR_POTI_V2_BRICKLET_THRESHOLD_OPTION_SMALLER
295    ///	* LINEAR_POTI_V2_BRICKLET_THRESHOLD_OPTION_GREATER
296    pub async fn set_position_callback_configuration(
297        &mut self,
298        period: u32,
299        value_has_to_change: bool,
300        option: char,
301        min: u8,
302        max: u8,
303    ) -> Result<(), TinkerforgeError> {
304        let mut payload = [0; 8];
305        period.write_to_slice(&mut payload[0..4]);
306        value_has_to_change.write_to_slice(&mut payload[4..5]);
307        option.write_to_slice(&mut payload[5..6]);
308        min.write_to_slice(&mut payload[6..7]);
309        max.write_to_slice(&mut payload[7..8]);
310
311        #[allow(unused_variables)]
312        let result = self.device.set(u8::from(LinearPotiV2BrickletFunction::SetPositionCallbackConfiguration), &payload).await?;
313        Ok(())
314    }
315
316    /// Returns the receiver configuration as set by [`set_position_callback_configuration`].
317    ///
318    /// Associated constants:
319    /// * LINEAR_POTI_V2_BRICKLET_THRESHOLD_OPTION_OFF
320    ///	* LINEAR_POTI_V2_BRICKLET_THRESHOLD_OPTION_OUTSIDE
321    ///	* LINEAR_POTI_V2_BRICKLET_THRESHOLD_OPTION_INSIDE
322    ///	* LINEAR_POTI_V2_BRICKLET_THRESHOLD_OPTION_SMALLER
323    ///	* LINEAR_POTI_V2_BRICKLET_THRESHOLD_OPTION_GREATER
324    pub async fn get_position_callback_configuration(&mut self) -> Result<PositionCallbackConfiguration, TinkerforgeError> {
325        let payload = [0; 0];
326
327        #[allow(unused_variables)]
328        let result = self.device.get(u8::from(LinearPotiV2BrickletFunction::GetPositionCallbackConfiguration), &payload).await?;
329        Ok(PositionCallbackConfiguration::from_le_byte_slice(result.body()))
330    }
331
332    /// Returns the error count for the communication between Brick and Bricklet.
333    ///
334    /// The errors are divided into
335    ///
336    /// * ACK checksum errors,
337    /// * message checksum errors,
338    /// * framing errors and
339    /// * overflow errors.
340    ///
341    /// The errors counts are for errors that occur on the Bricklet side. All
342    /// Bricks have a similar function that returns the errors on the Brick side.
343    pub async fn get_spitfp_error_count(&mut self) -> Result<SpitfpErrorCount, TinkerforgeError> {
344        let payload = [0; 0];
345
346        #[allow(unused_variables)]
347        let result = self.device.get(u8::from(LinearPotiV2BrickletFunction::GetSpitfpErrorCount), &payload).await?;
348        Ok(SpitfpErrorCount::from_le_byte_slice(result.body()))
349    }
350
351    /// Sets the bootloader mode and returns the status after the requested
352    /// mode change was instigated.
353    ///
354    /// You can change from bootloader mode to firmware mode and vice versa. A change
355    /// from bootloader mode to firmware mode will only take place if the entry function,
356    /// device identifier and CRC are present and correct.
357    ///
358    /// This function is used by Brick Viewer during flashing. It should not be
359    /// necessary to call it in a normal user program.
360    ///
361    /// Associated constants:
362    /// * LINEAR_POTI_V2_BRICKLET_BOOTLOADER_MODE_BOOTLOADER
363    ///	* LINEAR_POTI_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE
364    ///	* LINEAR_POTI_V2_BRICKLET_BOOTLOADER_MODE_BOOTLOADER_WAIT_FOR_REBOOT
365    ///	* LINEAR_POTI_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_REBOOT
366    ///	* LINEAR_POTI_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_ERASE_AND_REBOOT
367    ///	* LINEAR_POTI_V2_BRICKLET_BOOTLOADER_STATUS_OK
368    ///	* LINEAR_POTI_V2_BRICKLET_BOOTLOADER_STATUS_INVALID_MODE
369    ///	* LINEAR_POTI_V2_BRICKLET_BOOTLOADER_STATUS_NO_CHANGE
370    ///	* LINEAR_POTI_V2_BRICKLET_BOOTLOADER_STATUS_ENTRY_FUNCTION_NOT_PRESENT
371    ///	* LINEAR_POTI_V2_BRICKLET_BOOTLOADER_STATUS_DEVICE_IDENTIFIER_INCORRECT
372    ///	* LINEAR_POTI_V2_BRICKLET_BOOTLOADER_STATUS_CRC_MISMATCH
373    pub async fn set_bootloader_mode(&mut self, mode: u8) -> Result<u8, TinkerforgeError> {
374        let mut payload = [0; 1];
375        mode.write_to_slice(&mut payload[0..1]);
376
377        #[allow(unused_variables)]
378        let result = self.device.get(u8::from(LinearPotiV2BrickletFunction::SetBootloaderMode), &payload).await?;
379        Ok(u8::from_le_byte_slice(result.body()))
380    }
381
382    /// Returns the current bootloader mode, see [`set_bootloader_mode`].
383    ///
384    /// Associated constants:
385    /// * LINEAR_POTI_V2_BRICKLET_BOOTLOADER_MODE_BOOTLOADER
386    ///	* LINEAR_POTI_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE
387    ///	* LINEAR_POTI_V2_BRICKLET_BOOTLOADER_MODE_BOOTLOADER_WAIT_FOR_REBOOT
388    ///	* LINEAR_POTI_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_REBOOT
389    ///	* LINEAR_POTI_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_ERASE_AND_REBOOT
390    pub async fn get_bootloader_mode(&mut self) -> Result<u8, TinkerforgeError> {
391        let payload = [0; 0];
392
393        #[allow(unused_variables)]
394        let result = self.device.get(u8::from(LinearPotiV2BrickletFunction::GetBootloaderMode), &payload).await?;
395        Ok(u8::from_le_byte_slice(result.body()))
396    }
397
398    /// Sets the firmware pointer for [`write_firmware`]. The pointer has
399    /// to be increased by chunks of size 64. The data is written to flash
400    /// every 4 chunks (which equals to one page of size 256).
401    ///
402    /// This function is used by Brick Viewer during flashing. It should not be
403    /// necessary to call it in a normal user program.
404    pub async fn set_write_firmware_pointer(&mut self, pointer: u32) -> Result<(), TinkerforgeError> {
405        let mut payload = [0; 4];
406        pointer.write_to_slice(&mut payload[0..4]);
407
408        #[allow(unused_variables)]
409        let result = self.device.set(u8::from(LinearPotiV2BrickletFunction::SetWriteFirmwarePointer), &payload).await?;
410        Ok(())
411    }
412
413    /// Writes 64 Bytes of firmware at the position as written by
414    /// [`set_write_firmware_pointer`] before. The firmware is written
415    /// to flash every 4 chunks.
416    ///
417    /// You can only write firmware in bootloader mode.
418    ///
419    /// This function is used by Brick Viewer during flashing. It should not be
420    /// necessary to call it in a normal user program.
421    pub async fn write_firmware(&mut self, data: &[u8; 64]) -> Result<u8, TinkerforgeError> {
422        let mut payload = [0; 64];
423        data.write_to_slice(&mut payload[0..64]);
424
425        #[allow(unused_variables)]
426        let result = self.device.get(u8::from(LinearPotiV2BrickletFunction::WriteFirmware), &payload).await?;
427        Ok(u8::from_le_byte_slice(result.body()))
428    }
429
430    /// Sets the status LED configuration. By default the LED shows
431    /// communication traffic between Brick and Bricklet, it flickers once
432    /// for every 10 received data packets.
433    ///
434    /// You can also turn the LED permanently on/off or show a heartbeat.
435    ///
436    /// If the Bricklet is in bootloader mode, the LED is will show heartbeat by default.
437    ///
438    /// Associated constants:
439    /// * LINEAR_POTI_V2_BRICKLET_STATUS_LED_CONFIG_OFF
440    ///	* LINEAR_POTI_V2_BRICKLET_STATUS_LED_CONFIG_ON
441    ///	* LINEAR_POTI_V2_BRICKLET_STATUS_LED_CONFIG_SHOW_HEARTBEAT
442    ///	* LINEAR_POTI_V2_BRICKLET_STATUS_LED_CONFIG_SHOW_STATUS
443    pub async fn set_status_led_config(&mut self, config: u8) -> Result<(), TinkerforgeError> {
444        let mut payload = [0; 1];
445        config.write_to_slice(&mut payload[0..1]);
446
447        #[allow(unused_variables)]
448        let result = self.device.set(u8::from(LinearPotiV2BrickletFunction::SetStatusLedConfig), &payload).await?;
449        Ok(())
450    }
451
452    /// Returns the configuration as set by [`set_status_led_config`]
453    ///
454    /// Associated constants:
455    /// * LINEAR_POTI_V2_BRICKLET_STATUS_LED_CONFIG_OFF
456    ///	* LINEAR_POTI_V2_BRICKLET_STATUS_LED_CONFIG_ON
457    ///	* LINEAR_POTI_V2_BRICKLET_STATUS_LED_CONFIG_SHOW_HEARTBEAT
458    ///	* LINEAR_POTI_V2_BRICKLET_STATUS_LED_CONFIG_SHOW_STATUS
459    pub async fn get_status_led_config(&mut self) -> Result<u8, TinkerforgeError> {
460        let payload = [0; 0];
461
462        #[allow(unused_variables)]
463        let result = self.device.get(u8::from(LinearPotiV2BrickletFunction::GetStatusLedConfig), &payload).await?;
464        Ok(u8::from_le_byte_slice(result.body()))
465    }
466
467    /// Returns the temperature as measured inside the microcontroller. The
468    /// value returned is not the ambient temperature!
469    ///
470    /// The temperature is only proportional to the real temperature and it has bad
471    /// accuracy. Practically it is only useful as an indicator for
472    /// temperature changes.
473    pub async fn get_chip_temperature(&mut self) -> Result<i16, TinkerforgeError> {
474        let payload = [0; 0];
475
476        #[allow(unused_variables)]
477        let result = self.device.get(u8::from(LinearPotiV2BrickletFunction::GetChipTemperature), &payload).await?;
478        Ok(i16::from_le_byte_slice(result.body()))
479    }
480
481    /// Calling this function will reset the Bricklet. All configurations
482    /// will be lost.
483    ///
484    /// After a reset you have to create new device objects,
485    /// calling functions on the existing ones will result in
486    /// undefined behavior!
487    pub async fn reset(&mut self) -> Result<(), TinkerforgeError> {
488        let payload = [0; 0];
489
490        #[allow(unused_variables)]
491        let result = self.device.set(u8::from(LinearPotiV2BrickletFunction::Reset), &payload).await?;
492        Ok(())
493    }
494
495    /// Writes a new UID into flash. If you want to set a new UID
496    /// you have to decode the Base58 encoded UID string into an
497    /// integer first.
498    ///
499    /// We recommend that you use Brick Viewer to change the UID.
500    pub async fn write_uid(&mut self, uid: u32) -> Result<(), TinkerforgeError> {
501        let mut payload = [0; 4];
502        uid.write_to_slice(&mut payload[0..4]);
503
504        #[allow(unused_variables)]
505        let result = self.device.set(u8::from(LinearPotiV2BrickletFunction::WriteUid), &payload).await?;
506        Ok(())
507    }
508
509    /// Returns the current UID as an integer. Encode as
510    /// Base58 to get the usual string version.
511    pub async fn read_uid(&mut self) -> Result<u32, TinkerforgeError> {
512        let payload = [0; 0];
513
514        #[allow(unused_variables)]
515        let result = self.device.get(u8::from(LinearPotiV2BrickletFunction::ReadUid), &payload).await?;
516        Ok(u32::from_le_byte_slice(result.body()))
517    }
518
519    /// Returns the UID, the UID where the Bricklet is connected to,
520    /// the position, the hardware and firmware version as well as the
521    /// device identifier.
522    ///
523    /// The position can be 'a', 'b', 'c', 'd', 'e', 'f', 'g' or 'h' (Bricklet Port).
524    /// A Bricklet connected to an [Isolator Bricklet](isolator_bricklet) is always at
525    /// position 'z'.
526    ///
527    /// The device identifier numbers can be found [here](device_identifier).
528    /// |device_identifier_constant|
529    pub async fn get_identity(&mut self) -> Result<Identity, TinkerforgeError> {
530        let payload = [0; 0];
531
532        #[allow(unused_variables)]
533        let result = self.device.get(u8::from(LinearPotiV2BrickletFunction::GetIdentity), &payload).await?;
534        Ok(Identity::from_le_byte_slice(result.body()))
535    }
536}