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