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